shake-monitor
Advanced tools
Comparing version 0.2.3 to 0.2.4
'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,b){function e(){f&&(k?window.removeEventListener("devicemotion",a,!1):b?b.addEventListener("click",c):console.warn("Cannot get The permission to listen to DeviceOrientationEvent"))}function c(){DeviceMotionEvent.requestPermission().then(a=>{(k="granted"===a)?(b.removeEventListener("click",c),e()):console.warn("The permission to listen to DeviceMotionEvent was not granted")})}let f=isDeviceMotionSupported(),k=!isListenerRequirePermission();return{start:e,stop:function(){f&& | ||
window.removeEventListener("devicemotion",a,!1)}}}let defaultOptions={permissionTriggerNode:document.documentElement,autoStart:!0,threshold:15,frequency:1E3}; | ||
function createShakeMonitor(a){function b(){if(!g)return g=!0,h=performance.now(),d={},n.start(),this}function e(){if(g)return g=!1,n.stop(),h=performance.now(),d={},this}function c(){let a=performance.now();a-h>p&&(l.forEach(a=>a()),h=a)}let {autoStart:f,threshold:k,frequency:p,permissionTriggerNode:q}=Object.assign({},defaultOptions,a),n=createMotionMonitor(function(a){let {x:b,y:m,z:f}=a.accelerationIncludingGravity;if(null===b||null===m||null===f)e();else{if(!isEmptyObject(d)){a=getDelta(d.x, | ||
b);var g=getDelta(d.y,m),h=getDelta(d.z,f);isShake(a,g,h,k)&&c()}d.x=b;d.y=m;d.z=f}},q),l=[],g=!1,h,d;f&&b();return{subscribe:function(a){isFunc(a)&&l.push(a);return this},unsubscribe:function(a){isFunc(a)&&(l=l.filter(b=>b!==a));return this},start:b,stop:e}}function isShake(a,b,e,c){return a>c&&b>c||a>c&&e>c||b>c&&e>c}module.exports=createShakeMonitor | ||
function createMotionMonitor(a,b,g=()=>{}){function c(){if(!k)return!1;d?window.removeEventListener("devicemotion",a,!1):b?b.addEventListener("click",h):console.warn("Cannot get The permission to listen to DeviceOrientationEvent");return d}function h(){DeviceMotionEvent.requestPermission().then(a=>{(d="granted"===a)?(b.removeEventListener("click",h),g(),c()):console.warn("The permission to listen to DeviceMotionEvent was not granted")})}let k=isDeviceMotionSupported(),d=!isListenerRequirePermission(); | ||
return{start:c,stop:function(){k&&window.removeEventListener("devicemotion",a,!1)}}}let defaultOptions={permissionTriggerNode:document.documentElement,autoStart:!0,threshold:15,frequency:1E3}; | ||
function createShakeMonitor(a){function b(){if(!e)return e=!0,n=p.start(),l=performance.now(),f={},this}function g(){if(e)return e=!1,p.stop(),l=performance.now(),f={},this}function c(){let a=performance.now();a-l>d&&(m.forEach(a=>a()),l=a)}let {autoStart:h,threshold:k,frequency:d,permissionTriggerNode:q}=Object.assign({},defaultOptions,a),p=createMotionMonitor(function(a){let {x:b,y:d,z:e}=a.accelerationIncludingGravity;if(null===b||null===d||null===e)g();else{if(!isEmptyObject(f)){a=getDelta(f.x, | ||
b);var r=getDelta(f.y,d),h=getDelta(f.z,e);isShake(a,r,h,k)&&c()}f.x=b;f.y=d;f.z=e}},q,function(){n=!0}),m=[],e=!1,n=!1,l,f;h&&b();return{subscribe:function(a){isFunc(a)&&m.push(a);return this},unsubscribe:function(a){isFunc(a)&&(m=m.filter(b=>b!==a));return this},start:b,stop:g,isMonitoring:function(){return e&&n}}}function isShake(a,b,g,c){return a>c&&b>c||a>c&&g>c||b>c&&g>c}module.exports=createShakeMonitor |
@@ -1,5 +0,5 @@ | ||
function n(b){return"function"===typeof b} | ||
function q(b,c){function k(){f&&(d?window.removeEventListener("devicemotion",b,!1):c?c.addEventListener("click",l):console.warn("Cannot get The permission to listen to DeviceOrientationEvent"))}function l(){DeviceMotionEvent.requestPermission().then(b=>{(d="granted"===b)?(c.removeEventListener("click",l),k()):console.warn("The permission to listen to DeviceMotionEvent was not granted")})}let f="DeviceMotionEvent"in window,d=!n(DeviceMotionEvent.requestPermission);return{start:k,stop:function(){f&& | ||
window.removeEventListener("devicemotion",b,!1)}}}let t={permissionTriggerNode:document.documentElement,autoStart:!0,threshold:15,frequency:1E3}; | ||
export default function(b){function c(){if(!g)return g=!0,h=performance.now(),e={},p.start(),this}function k(){if(g)return g=!1,p.stop(),h=performance.now(),e={},this}function l(){let a=performance.now();a-h>r&&(m.forEach(a=>a()),h=a)}let {autoStart:f,threshold:d,frequency:r,permissionTriggerNode:u}=Object.assign({},t,b),p=q(function(a){let {x:b,y:c,z:f}=a.accelerationIncludingGravity;if(null===b||null===c||null===f)k();else{if(0!==Object.keys(e).length){a=Math.abs(e.x-b);var g=Math.abs(e.y- | ||
c),h=Math.abs(e.z-f);(a>d&&g>d||a>d&&h>d||g>d&&h>d)&&l()}e.x=b;e.y=c;e.z=f}},u),m=[],g=!1,h,e;f&&c();return{subscribe:function(a){n(a)&&m.push(a);return this},unsubscribe:function(a){n(a)&&(m=m.filter(b=>b!==a));return this},start:c,stop:k}} | ||
function p(c){return"function"===typeof c} | ||
function t(c,d,k=()=>{}){function l(){if(!b)return!1;e?window.removeEventListener("devicemotion",c,!1):d?d.addEventListener("click",h):console.warn("Cannot get The permission to listen to DeviceOrientationEvent");return e}function h(){DeviceMotionEvent.requestPermission().then(b=>{(e="granted"===b)?(d.removeEventListener("click",h),k(),l()):console.warn("The permission to listen to DeviceMotionEvent was not granted")})}let b="DeviceMotionEvent"in window,e=!p(DeviceMotionEvent.requestPermission);return{start:l, | ||
stop:function(){b&&window.removeEventListener("devicemotion",c,!1)}}}let v={permissionTriggerNode:document.documentElement,autoStart:!0,threshold:15,frequency:1E3}; | ||
export default function(c){function d(){if(!g)return g=!0,q=r.start(),m=performance.now(),f={},this}function k(){if(g)return g=!1,r.stop(),m=performance.now(),f={},this}function l(){let a=performance.now();a-m>e&&(n.forEach(a=>a()),m=a)}let {autoStart:h,threshold:b,frequency:e,permissionTriggerNode:u}=Object.assign({},v,c),r=t(function(a){let {x:c,y:d,z:e}=a.accelerationIncludingGravity;if(null===c||null===d||null===e)k();else{if(0!==Object.keys(f).length){a=Math.abs(f.x-c);var g=Math.abs(f.y- | ||
d),h=Math.abs(f.z-e);(a>b&&g>b||a>b&&h>b||g>b&&h>b)&&l()}f.x=c;f.y=d;f.z=e}},u,function(){q=!0}),n=[],g=!1,q=!1,m,f;h&&d();return{subscribe:function(a){p(a)&&n.push(a);return this},unsubscribe:function(a){p(a)&&(n=n.filter(b=>b!==a));return this},start:d,stop:k,isMonitoring:function(){return g&&q}}} |
@@ -1,4 +0,4 @@ | ||
'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,d){function k(){g&&(e?window.removeEventListener("devicemotion",c,!1):d?d.addEventListener("click",l):console.warn("Cannot get The permission to listen to DeviceOrientationEvent"))}function l(){DeviceMotionEvent.requestPermission().then(a=> | ||
{(e="granted"===a)?(d.removeEventListener("click",l),k()):console.warn("The permission to listen to DeviceMotionEvent was not granted")})}let g="DeviceMotionEvent"in window,e=!a(DeviceMotionEvent.requestPermission);return{start:k,stop:function(){g&&window.removeEventListener("devicemotion",c,!1)}}}let t={permissionTriggerNode:document.documentElement,autoStart:!0,threshold:15,frequency:1E3};return function(q){function d(){if(!h)return h=!0,m=performance.now(),f={},p.start(),this}function k(){if(h)return h= | ||
!1,p.stop(),m=performance.now(),f={},this}function l(){let b=performance.now();b-m>r&&(n.forEach(b=>b()),m=b)}let {autoStart:g,threshold:e,frequency:r,permissionTriggerNode:u}=Object.assign({},t,q),p=c(function(b){let {x:a,y:c,z:d}=b.accelerationIncludingGravity;if(null===a||null===c||null===d)k();else{if(0!==Object.keys(f).length){b=Math.abs(f.x-a);var g=Math.abs(f.y-c),h=Math.abs(f.z-d);(b>e&&g>e||b>e&&h>e||g>e&&h>e)&&l()}f.x=a;f.y=c;f.z=d}},u),n=[],h=!1,m,f;g&&d();return{subscribe:function(b){a(b)&& | ||
n.push(b);return this},unsubscribe:function(b){a(b)&&(n=n.filter(a=>a!==b));return this},start:d,stop:k}}}) | ||
'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,d,k=()=>{}){function l(){if(!e)return!1;g?window.removeEventListener("devicemotion",c,!1):d?d.addEventListener("click",m):console.warn("Cannot get The permission to listen to DeviceOrientationEvent");return g} | ||
function m(){DeviceMotionEvent.requestPermission().then(a=>{(g="granted"===a)?(d.removeEventListener("click",m),k(),l()):console.warn("The permission to listen to DeviceMotionEvent was not granted")})}let e="DeviceMotionEvent"in window,g=!a(DeviceMotionEvent.requestPermission);return{start:l,stop:function(){e&&window.removeEventListener("devicemotion",c,!1)}}}let v={permissionTriggerNode:document.documentElement,autoStart:!0,threshold:15,frequency:1E3};return function(t){function d(){if(!h)return h= | ||
!0,q=r.start(),n=performance.now(),f={},this}function k(){if(h)return h=!1,r.stop(),n=performance.now(),f={},this}function l(){let b=performance.now();b-n>g&&(p.forEach(b=>b()),n=b)}let {autoStart:m,threshold:e,frequency:g,permissionTriggerNode:u}=Object.assign({},v,t),r=c(function(b){let {x:a,y:c,z:d}=b.accelerationIncludingGravity;if(null===a||null===c||null===d)k();else{if(0!==Object.keys(f).length){b=Math.abs(f.x-a);var g=Math.abs(f.y-c),h=Math.abs(f.z-d);(b>e&&g>e||b>e&&h>e||g>e&&h>e)&&l()}f.x= | ||
a;f.y=c;f.z=d}},u,function(){q=!0}),p=[],h=!1,q=!1,n,f;m&&d();return{subscribe:function(b){a(b)&&p.push(b);return this},unsubscribe:function(b){a(b)&&(p=p.filter(a=>a!==b));return this},start:d,stop:k,isMonitoring:function(){return h&&q}}}}) |
{ | ||
"name": "shake-monitor", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "shake-monitor", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7609