UNPKG

exit-intent-quattro

Version:

Exit intent detection library - detects all 4 edges.

2 lines (1 loc) 5.96 kB
"use strict";function isObject(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function getRawTag(t){var e=hasOwnProperty.call(t,symToStringTag$1),n=t[symToStringTag$1];try{t[symToStringTag$1]=void 0;var o=!0}catch(t){}var r=nativeObjectToString.call(t);return o&&(e?t[symToStringTag$1]=n:delete t[symToStringTag$1]),r}function objectToString(t){return nativeObjectToString$1.call(t)}function baseGetTag(t){return null==t?void 0===t?undefinedTag:nullTag:symToStringTag&&symToStringTag in Object(t)?_getRawTag(t):_objectToString(t)}function isObjectLike(t){return null!=t&&"object"==typeof t}function isSymbol(t){return"symbol"==typeof t||isObjectLike_1(t)&&_baseGetTag(t)==symbolTag}function toNumber(t){if("number"==typeof t)return t;if(isSymbol_1(t))return NAN;if(isObject_1(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=isObject_1(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(reTrim,"");var n=reIsBinary.test(t);return n||reIsOctal.test(t)?freeParseInt(t.slice(2),n?2:8):reIsBadHex.test(t)?NAN:+t}function debounce(t,e,n){function o(e){var n=s,o=f;return s=f=void 0,y=e,m=t.apply(o,n)}function r(t){return y=t,g=setTimeout(c,e),v?o(t):m}function i(t){var n=t-y,o=e-(t-d);return T?nativeMin(o,b-n):o}function a(t){var n=t-d,o=t-y;return void 0===d||n>=e||n<0||T&&o>=b}function c(){var t=now_1();if(a(t))return u(t);g=setTimeout(c,i(t))}function u(t){return g=void 0,h&&s?o(t):(s=f=void 0,m)}function l(){var t=now_1(),n=a(t);if(s=arguments,f=this,d=t,n){if(void 0===g)return r(d);if(T)return clearTimeout(g),g=setTimeout(c,e),o(d)}return void 0===g&&(g=setTimeout(c,e)),m}var s,f,b,m,g,d,y=0,v=!1,T=!1,h=!0;if("function"!=typeof t)throw new TypeError(FUNC_ERROR_TEXT$1);return e=toNumber_1(e)||0,isObject_1(n)&&(v=!!n.leading,b=(T="maxWait"in n)?nativeMax(toNumber_1(n.maxWait)||0,e):b,h="trailing"in n?!!n.trailing:h),l.cancel=function(){void 0!==g&&clearTimeout(g),y=0,s=d=f=g=void 0},l.flush=function(){return void 0===g?m:u(now_1())},l}function throttle(t,e,n){var o=!0,r=!0;if("function"!=typeof t)throw new TypeError(FUNC_ERROR_TEXT);return isObject_1(n)&&(o="leading"in n?!!n.leading:o,r="trailing"in n?!!n.trailing:r),debounce_1(t,e,{leading:o,maxWait:e,trailing:r})}function ExitIntent(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e={edges:{top:!0,right:!1,bottom:!1,left:!1},threshold:20,maxDisplays:1,eventThrottle:200,onExitIntent:function(){}};return function(){var n=_extends({},e,t,{edges:_extends({},e.edges,t.edges)}),o=new Map,r=0,i=function(t){var e=o.get(t),n=e.eventName,r=e.callback;document.removeEventListener(n,r),o.delete(t)},a=function(t,e){return n.edges.top&&e<=n.threshold&&r<n.maxDisplays?(r++,"top"):n.edges.right&&t>=u()-n.threshold&&r<n.maxDisplays?(r++,"right"):n.edges.bottom&&e>=l()-n.threshold&&r<n.maxDisplays?(r++,"bottom"):!!(n.edges.left&&t<=n.threshold&&r<n.maxDisplays)&&(r++,"left")},c=function(){o.forEach(function(t,e,n){return i(e)})},u=function(){return Math.max(document.documentElement.clientWidth||0,window.innerWidth||0)},l=function(){return Math.max(document.documentElement.clientHeight||0,window.innerHeight||0)};return function(t,e){document.addEventListener(t,e,!1),o.set("document:"+t,{eventName:t,callback:e})}("mousemove",throttle_1(function(t){var e=a(t.clientX,t.clientY);e&&(n.onExitIntent({side:e,position:{x:t.clientX,y:t.clientY}}),r>=n.maxDisplays&&c())},n.eventThrottle)),c}()}var isObject_1=isObject,commonjsGlobal="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},freeGlobal="object"==typeof commonjsGlobal&&commonjsGlobal&&commonjsGlobal.Object===Object&&commonjsGlobal,_freeGlobal=freeGlobal,freeSelf="object"==typeof self&&self&&self.Object===Object&&self,root=_freeGlobal||freeSelf||Function("return this")(),_root=root,now=function(){return _root.Date.now()},now_1=now,Symbol$1=_root.Symbol,_Symbol=Symbol$1,objectProto=Object.prototype,hasOwnProperty=objectProto.hasOwnProperty,nativeObjectToString=objectProto.toString,symToStringTag$1=_Symbol?_Symbol.toStringTag:void 0,_getRawTag=getRawTag,objectProto$1=Object.prototype,nativeObjectToString$1=objectProto$1.toString,_objectToString=objectToString,nullTag="[object Null]",undefinedTag="[object Undefined]",symToStringTag=_Symbol?_Symbol.toStringTag:void 0,_baseGetTag=baseGetTag,isObjectLike_1=isObjectLike,symbolTag="[object Symbol]",isSymbol_1=isSymbol,NAN=NaN,reTrim=/^\s+|\s+$/g,reIsBadHex=/^[-+]0x[0-9a-f]+$/i,reIsBinary=/^0b[01]+$/i,reIsOctal=/^0o[0-7]+$/i,freeParseInt=parseInt,toNumber_1=toNumber,FUNC_ERROR_TEXT$1="Expected a function",nativeMax=Math.max,nativeMin=Math.min,debounce_1=debounce,FUNC_ERROR_TEXT="Expected a function",throttle_1=throttle,asyncGenerator=function(){function t(t){this.value=t}function e(e){function n(r,i){try{var a=e[r](i),c=a.value;c instanceof t?Promise.resolve(c.value).then(function(t){n("next",t)},function(t){n("throw",t)}):o(a.done?"return":"normal",a.value)}catch(t){o("throw",t)}}function o(t,e){switch(t){case"return":r.resolve({value:e,done:!0});break;case"throw":r.reject(e);break;default:r.resolve({value:e,done:!1})}(r=r.next)?n(r.key,r.arg):i=null}var r,i;this._invoke=function(t,e){return new Promise(function(o,a){var c={key:t,arg:e,resolve:o,reject:a,next:null};i?i=i.next=c:(r=i=c,n(t,e))})},"function"!=typeof e.return&&(this.return=void 0)}return"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)},{wrap:function(t){return function(){return new e(t.apply(this,arguments))}},await:function(e){return new t(e)}}}(),_extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t};module.exports=ExitIntent;