UNPKG

ganic-pandora

Version:

A cool organic programming javascript library

2 lines (1 loc) 9.09 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)}Object.defineProperty(exports,"__esModule",{value:!0});function _interopDefault(a){return a&&"object"===_typeof(a)&&"default"in a?a["default"]:a}var ganicUsex=_interopDefault(require("ganic-usex")),ganic=_interopDefault(require("ganic")),broswerInfo={isMobile:/mobile/i.test(navigator.userAgent),isIE:/MSIE/i.test(navigator.userAgent)||/Trident/i.test(navigator.userAgent)},useBrowser=function(){return broswerInfo};function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_nonIterableRest()}function _arrayWithHoles(a){if(Array.isArray(a))return a}function _iterableToArrayLimit(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 _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}var useCallback=ganicUsex.useCallback,useState=ganicUsex.useState,useEffect=ganicUsex.useEffect,useClick=function(){var a=useState({clientX:0,clientY:0}),b=_slicedToArray(a,2),c=b[0],d=b[1],e=useCallback(function(a){var b=a.clientX,c=a.clientY;return d({clientX:b+1,clientY:c+1})});return useEffect(function(){return document.addEventListener("click",e),document.addEventListener("touchend",e,{passive:!0}),function(){document.removeEventListener("click",e),document.removeEventListener("touchend",e)}}),c},useClick_1=useClick,attach=ganic.attach,useRef=ganicUsex.useRef,runningIntervals={},intervalRefSets={},removeRefLastDelay=function(a){intervalRefSets[a.lastDelay]&&intervalRefSets[a.lastDelay].delete(a)},removeRefDelay=function(a){intervalRefSets[a.delay]&&intervalRefSets[a.delay].delete(a)},addRef=function(a){removeRefLastDelay(a);var b=a.delay;"number"==typeof b&&(intervalRefSets[b]?intervalRefSets[b].add(a):intervalRefSets[b]=new Set([a]),!runningIntervals[b]&&(runningIntervals[b]=setInterval(function(){return callRefs(b)},b)))},getRefSet=function(a){return intervalRefSets[a]},callRefs=function(a){var b=getRefSet(a);return b&&b.size?void b.forEach(function(a){a.callback()}):(clearInterval(runningIntervals[a]),runningIntervals[a]=null,void(intervalRefSets[a]=null))},useGlobalInterval=function(a,b){var c=useRef();c.callback=a,attach(function(a){return c.lastDelay=c.delay,c.delay=a,addRef(c),function(){removeRefDelay(c)}},b)},useGlobalInterval_1=useGlobalInterval,useState$1=ganicUsex.useState,getDocumentElementCount=function(){return document.querySelectorAll("*").length},getDocInfo=function(){return{count:getDocumentElementCount()}},initDocInfo=getDocInfo(),useDocument=function(){var a=useState$1(initDocInfo),b=_slicedToArray(a,2),c=b[0],d=b[1];return useGlobalInterval_1(function(){return d(getDocInfo())},100),c},useDocument_1=useDocument,useState$2=ganicUsex.useState,listeners=new Set,wakeListeners=function(a){listeners.forEach(function(b){return b(a)})},running=!1,runFPSChecker=function(){var a=Date.now(),b=0,c=function c(){if(!listeners.size)return void(running=!1);running=!0;var d=Date.now();b=Math.round(1e3/(d-a)),a=d,requestAnimationFrame(c),60>=b&&wakeListeners(b)};requestAnimationFrame(c)},requestFPS=function(a){listeners.add(a);running||runFPSChecker()},useFPS=function(){var a=useState$2(0),b=_slicedToArray(a,2),c=b[0],d=b[1];return requestFPS(d),c},useFPS_1=useFPS,useRef$1=ganicUsex.useRef,useState$3=ganicUsex.useState,useMotion=function(a,b){var c=useState$3(a),d=_slicedToArray(c,2),e=d[0],f=d[1],g=useRef$1();g.target!==a&&(g.startValue=e,g.target=a,g.startAt=Date.now());var h=e===g.target,i=h?null:50;return useGlobalInterval_1(function(){var a=Date.now()-g.startAt;return b-a<=i?void f(g.target):void f(function(a){var c=g.target-g.startValue;return a+c/(b/i)})},i),50>b&&!h&&f(g.target),e},useMotion_1=useMotion,useCallback$1=ganicUsex.useCallback,useState$4=ganicUsex.useState,useEffect$1=ganicUsex.useEffect,useMouse=function(){var a=useState$4({clientX:0,clientY:0}),b=_slicedToArray(a,2),c=b[0],d=b[1],e=useCallback$1(function(a){var b=a.clientX,c=a.clientY;return d({clientX:b+1,clientY:c+1})});return useEffect$1(function(){return document.addEventListener("mousemove",e),document.addEventListener("touchend",e,{passive:!0}),function(){document.removeEventListener("mousemove",e),document.removeEventListener("touchend",e)}}),c},useMouse_1=useMouse,useRef$2=ganicUsex.useRef,useEffect$2=ganicUsex.useEffect,mouseUpEffect=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}},useMouseUp=function(a){var b=useRef$2();b.current=a,useEffect$2(mouseUpEffect,b)},useMouseUp_1=useMouseUp,useState$5=ganicUsex.useState,useInterval=ganicUsex.useInterval,useCallback$2=ganicUsex.useCallback,usePress=function(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:1,c=useState$5(null),d=_slicedToArray(c,2),e=d[0],f=d[1];useInterval(a,e),useMouseUp_1(function(){f(null)});var g=useCallback$2(function(a){return function(c){f(b),"function"==typeof a&&a(c)}});return g},usePress_1=usePress,floor=function(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:1;return Math.floor(a-a%b)},math_floor=floor,useState$6=ganicUsex.useState,useRef$3=ganicUsex.useRef,getRefRect=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:math_floor(e,b),height:math_floor(g,b),top:math_floor(i,b),right:math_floor(k,b),bottom:math_floor(m,b),left:math_floor(o,b)}}},useRectRef=function(){var a=useRef$3(),b=useState$6(function(){return getRefRect(a)}),c=_slicedToArray(b,2),d=c[0],e=c[1];return useGlobalInterval_1(function(){return e(getRefRect(a))},100),[d,a]},useRectRef_1=useRectRef,useCallback$3=ganicUsex.useCallback,useState$7=ganicUsex.useState,useReducer=function(a,b){var c=useState$7(b),d=_slicedToArray(c,2),e=d[0],f=d[1],g=useCallback$3(function(b){return f(function(c){return a(c,b)})});return[e,g]},useReducer_1=useReducer,useState$8=ganicUsex.useState,getStoredValue=function(a,b){if(!a)return b;try{return JSON.parse(window.localStorage[a])}catch(a){return b}},setStoredValue=function(a,b){if(a)try{window.localStorage[a]=JSON.stringify(b)}catch(a){}},useStorage=function(a,b){var c=useState$8(function(){return getStoredValue(a,b)}),d=_slicedToArray(c,2),e=d[0],f=d[1];return setStoredValue(a,e),[e,f]},useStorage_1=useStorage,useState$9=ganicUsex.useState,getViewport=function(){var a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:1;return{width:math_floor(window.innerWidth,a),height:math_floor(window.innerHeight,a),scrollX:math_floor(document.documentElement.scrollLeft,a),scrollY:math_floor(document.documentElement.scrollTop,a)}},useViewport=function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:10,b=useState$9(getViewport),c=_slicedToArray(b,2),d=c[0],e=c[1];return useGlobalInterval_1(function(){return e(getViewport(a))},100),d},useViewport_1=useViewport,ganicPandora={useBrowser:useBrowser,useClick:useClick_1,useDocument:useDocument_1,useFPS:useFPS_1,useGlobalInterval:useGlobalInterval_1,useMotion:useMotion_1,useMouse:useMouse_1,useMouseUp:useMouseUp_1,usePress:usePress_1,useRectRef:useRectRef_1,useReducer:useReducer_1,useStorage:useStorage_1,useViewport:useViewport_1},ganicPandora_1=ganicPandora.useBrowser,ganicPandora_2=ganicPandora.useClick,ganicPandora_3=ganicPandora.useDocument,ganicPandora_4=ganicPandora.useFPS,ganicPandora_5=ganicPandora.useGlobalInterval,ganicPandora_6=ganicPandora.useMotion,ganicPandora_7=ganicPandora.useMouse,ganicPandora_8=ganicPandora.useMouseUp,ganicPandora_9=ganicPandora.usePress,ganicPandora_10=ganicPandora.useRectRef,ganicPandora_11=ganicPandora.useReducer,ganicPandora_12=ganicPandora.useStorage,ganicPandora_13=ganicPandora.useViewport;exports.default=ganicPandora,exports.useBrowser=ganicPandora_1,exports.useClick=ganicPandora_2,exports.useDocument=ganicPandora_3,exports.useFPS=ganicPandora_4,exports.useGlobalInterval=ganicPandora_5,exports.useMotion=ganicPandora_6,exports.useMouse=ganicPandora_7,exports.useMouseUp=ganicPandora_8,exports.usePress=ganicPandora_9,exports.useRectRef=ganicPandora_10,exports.useReducer=ganicPandora_11,exports.useStorage=ganicPandora_12,exports.useViewport=ganicPandora_13;