UNPKG

ganic-pandora

Version:

A cool organic programming javascript library

2 lines (1 loc) 6.49 kB
"use strict";function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}(function(a,b){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?b(exports,require("ganic-usex"),require("ganic")):"function"==typeof define&&define.amd?define(["exports","ganic-usex","ganic"],b):(a=a||self,b(a.GanicPandora={},a.GanicUseX,a.Ganic))})(void 0,function(a,b,c){'use strict';function d(a,b){return e(a)||f(a,b)||g()}function e(a){if(Array.isArray(a))return a}function f(a,b){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a)){var c=[],d=!0,e=!1,f=void 0;try{for(var g,h=a[Symbol.iterator]();!(d=(g=h.next()).done)&&(c.push(g.value),!(b&&c.length===b));d=!0);}catch(a){e=!0,f=a}finally{try{d||null==h["return"]||h["return"]()}finally{if(e)throw f}}return c}}function g(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}b=b&&b.hasOwnProperty("default")?b["default"]:b,c=c&&c.hasOwnProperty("default")?c["default"]:c;var h={isMobile:/mobile/i.test(navigator.userAgent),isIE:/MSIE/i.test(navigator.userAgent)||/Trident/i.test(navigator.userAgent)},i=b.useCallback,j=b.useState,k=b.useEffect,l=c.attach,m=b.useRef,n={},o={},p=function(a){o[a.lastDelay]&&o[a.lastDelay].delete(a)},q=function(a){o[a.delay]&&o[a.delay].delete(a)},r=function(a){p(a);var b=a.delay;"number"==typeof b&&(o[b]?o[b].add(a):o[b]=new Set([a]),!n[b]&&(n[b]=setInterval(function(){return t(b)},b)))},s=function(a){return o[a]},t=function(a){var b=s(a);return b&&b.size?void b.forEach(function(a){a.callback()}):(clearInterval(n[a]),n[a]=null,void(o[a]=null))},u=function(a,b){var c=m();c.callback=a,l(function(a){return c.lastDelay=c.delay,c.delay=a,r(c),function(){q(c)}},b)},v=b.useState,w=function(){return document.querySelectorAll("*").length},x=function(){return{count:w()}},y=x(),z=b.useState,A=new Set,B=function(a){A.forEach(function(b){return b(a)})},C=!1,D=function(){var a=Date.now(),b=0,c=function c(){if(!A.size)return void(C=!1);C=!0;var d=Date.now();b=Math.round(1e3/(d-a)),a=d,requestAnimationFrame(c),60>=b&&B(b)};requestAnimationFrame(c)},E=function(a){A.add(a);C||D()},F=b.useRef,G=b.useState,H=b.useCallback,I=b.useState,J=b.useEffect,K=b.useRef,L=b.useEffect,M=function(a){var b=function(b){"function"==typeof a.current&&a.current(b)};return document.documentElement.addEventListener("mouseup",b),document.documentElement.addEventListener("touchend",b,{passive:!0}),function(){document.documentElement.removeEventListener("mouseup",b),document.documentElement.removeEventListener("touchend",b,{passive:!0}),a.current=null}},N=function(a){var b=K();b.current=a,L(M,b)},O=b.useState,P=b.useInterval,Q=b.useCallback,R=function(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:1;return Math.floor(a-a%b)},S=b.useState,T=b.useRef,U=function(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:1;if(a.current&&a.current.parentElement&&a.current.getBoundingClientRect){var c=a.current.getBoundingClientRect(),d=c.width,e=void 0===d?0:d,f=c.height,g=void 0===f?0:f,h=c.top,i=void 0===h?0:h,j=c.right,k=void 0===j?0:j,l=c.bottom,m=void 0===l?0:l,n=c.left,o=void 0===n?0:n;return{width:R(e,b),height:R(g,b),top:R(i,b),right:R(k,b),bottom:R(m,b),left:R(o,b)}}},V=b.useCallback,W=b.useState,X=b.useState,Y=function(a,b){if(!a)return b;try{return JSON.parse(window.localStorage[a])}catch(a){return b}},Z=function(a,b){if(a)try{window.localStorage[a]=JSON.stringify(b)}catch(a){}},$=b.useState,_=function(){var a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:1;return{width:R(window.innerWidth,a),height:R(window.innerHeight,a),scrollX:R(document.documentElement.scrollLeft,a),scrollY:R(document.documentElement.scrollTop,a)}},aa={useBrowser:function(){return h},useClick:function(){var a=j({clientX:0,clientY:0}),b=d(a,2),c=b[0],e=b[1],f=i(function(a){var b=a.clientX,c=a.clientY;return e({clientX:b+1,clientY:c+1})});return k(function(){return document.addEventListener("click",f),document.addEventListener("touchend",f,{passive:!0}),function(){document.removeEventListener("click",f),document.removeEventListener("touchend",f)}}),c},useDocument:function(){var a=v(y),b=d(a,2),c=b[0],e=b[1];return u(function(){return e(x())},100),c},useFPS:function(){var a=z(0),b=d(a,2),c=b[0],e=b[1];return E(e),c},useGlobalInterval:u,useMotion:function(a,b){var c=G(a),e=d(c,2),f=e[0],g=e[1],h=F();h.target!==a&&(h.startValue=f,h.target=a,h.startAt=Date.now());var i=f===h.target,j=i?null:50;return u(function(){var a=Date.now()-h.startAt;return b-a<=j?void g(h.target):void g(function(a){var c=h.target-h.startValue;return a+c/(b/j)})},j),50>b&&!i&&g(h.target),f},useMouse:function(){var a=I({clientX:0,clientY:0}),b=d(a,2),c=b[0],e=b[1],f=H(function(a){var b=a.clientX,c=a.clientY;return e({clientX:b+1,clientY:c+1})});return J(function(){return document.addEventListener("mousemove",f),document.addEventListener("touchend",f,{passive:!0}),function(){document.removeEventListener("mousemove",f),document.removeEventListener("touchend",f)}}),c},useMouseUp:N,usePress:function(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:1,c=O(null),e=d(c,2),f=e[0],g=e[1];P(a,f),N(function(){g(null)});var h=Q(function(a){return function(c){g(b),"function"==typeof a&&a(c)}});return h},useRectRef:function(){var a=T(),b=S(function(){return U(a)}),c=d(b,2),e=c[0],f=c[1];return u(function(){return f(U(a))},100),[e,a]},useReducer:function(a,b){var c=W(b),e=d(c,2),f=e[0],g=e[1],h=V(function(b){return g(function(c){return a(c,b)})});return[f,h]},useStorage:function(a,b){var c=X(function(){return Y(a,b)}),e=d(c,2),f=e[0],g=e[1];return Z(a,f),[f,g]},useViewport:function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:10,b=$(_),c=d(b,2),e=c[0],f=c[1];return u(function(){return f(_(a))},100),e}},ba=aa.useBrowser,ca=aa.useClick,da=aa.useDocument,ea=aa.useFPS,fa=aa.useGlobalInterval,ga=aa.useMotion,ha=aa.useMouse,ia=aa.useMouseUp,ja=aa.usePress,ka=aa.useRectRef,la=aa.useReducer,ma=aa.useStorage,na=aa.useViewport;a.default=aa,a.useBrowser=ba,a.useClick=ca,a.useDocument=da,a.useFPS=ea,a.useGlobalInterval=fa,a.useMotion=ga,a.useMouse=ha,a.useMouseUp=ia,a.usePress=ja,a.useRectRef=ka,a.useReducer=la,a.useStorage=ma,a.useViewport=na,Object.defineProperty(a,"__esModule",{value:!0})});