@fancyapps/ui
Version:
Robust JavaScript UI Component Library
1 lines • 2.01 kB
JavaScript
!/*! License details at fancyapps.com/license */function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).window=e.window||{})}(this,function(e){"use strict";let t=e=>"object"==typeof e&&null!==e&&e.constructor===Object&&"[object Object]"===Object.prototype.toString.call(e),n={autoStart:!0,speed:3},o=1/60*1e3;e.Autoscroll=()=>{let e,i,s=null,u=!1,r=!1,c=!1,f=!1;function l(){let o=e?.getOptions().Autoscroll;return t(o)?{...n,...o}:n}function a(){s||(i=performance.now(),s=requestAnimationFrame(g))}function d(){s&&(cancelAnimationFrame(s),s=null)}function p(){if(e&&e.isInfinite()){if(!u){u=!0;let t=e?.getContainer();e?.getTween()?.on("start",h),t&&matchMedia("(hover: hover)").matches&&(t.addEventListener("mouseenter",v,!1),t.addEventListener("mouseleave",b,!1)),e.emit("autoscroll:start")}a()}}function m(){if(d(),u){u=!1,c=!1,e?.getTween()?.off("start",h);let t=e?.getContainer();t?.addEventListener("mouseenter",v,!1),t?.addEventListener("mouseleave",b,!1),e?.emit("autoscroll:end")}}function g(t){if(!e||!u||c||!i)return;let n=t-i;n>o&&(n=o);let f=1/60*n,d=l().speed,p=l().speedOnHover,m=f*(r&&void 0!==p?p:d),g=e.getPosition()+m;e.setPosition(g),s=null,a()}function v(){r=!0,0===l().speedOnHover&&(f=!0,e?.getTween()?.pause(),d())}function b(){r=!1,f=!1,u&&!c&&a()}function y(){e&&!1!==e.getOptions().Autoscroll&&l().autoStart&&p()}function h(){d()}function w(){!u||c||f||a()}function E(){u&&(document.hidden?(e?.getTween()?.pause(),d()):c||f||a())}return{init:function(t){(e=t).on("ready",y),e.on("settle",w),document.addEventListener("visibilitychange",E)},destroy:function(){f=!1,m(),e&&(e.off("ready",y),e.off("settle",w)),e=void 0,document.removeEventListener("visibilitychange",E)},isEnabled:()=>u,pause:function(){c||(c=!0,e?.getTween()?.pause(),d())},resume:function(){c=!1,u&&!f&&a()},start:function(){p()},stop:function(){m()},toggle(){u?m():p()}}}});