alrdy-animate
Version:
A library to handle animations on scroll with GSAP integration.
1 lines • 7.24 kB
JavaScript
;(this.webpackChunkAlrdyAnimate=this.webpackChunkAlrdyAnimate||[]).push([[297],{558:(e,t,r)=>{function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?a(Object(r),!0).forEach((function(t){i(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):a(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function i(e,t,r){return(t=function(e){var t=function(e){if("object"!=n(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=n(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==n(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e){return function(e){if(Array.isArray(e))return c(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||u(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(e,t){if(e){if("string"==typeof e)return c(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?c(e,t):void 0}}function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}r.r(t),r.d(t,{createModalAnimations:()=>y});var s={fade:{opacity:0},"fade-up":{opacity:0,yPercent:10},"fade-down":{opacity:0,yPercent:-10},"fade-left":{opacity:0,xPercent:10},"fade-right":{opacity:0,xPercent:-10},"slide-up":{yPercent:110},"slide-down":{yPercent:-110},"slide-left":{xPercent:110},"slide-right":{xPercent:-110},scale:{scale:.8,opacity:0}};function d(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,a=n.querySelector("[aa-modal-backdrop]"),i=n.querySelectorAll("[aa-modal-name]"),c=document.querySelectorAll("[aa-modal-target]"),d=new Map,f=null,y=null;function p(t){var r=d.get(t);r.eventCallback("onReverseComplete",(function(){t.style.visibility="hidden",t.style.display="none",t.setAttribute("aa-modal-status","not-active"),n.style.visibility="hidden",n.setAttribute("aa-modal-group-status","not-active"),e?e.start():document.body.style.overflow="",y&&y(),f=null,r.eventCallback("onReverseComplete",null)})),r.timeScale(2).reverse()}function m(i){n.style.visibility="visible",n.setAttribute("aa-modal-group-status","active"),i.style.visibility="visible",i.style.display="flex",i.setAttribute("aa-modal-status","active"),e?e.stop():document.body.style.overflow="hidden",f=i;var c=d.get(i);c||(c=function(e,t,r,n){var a=gsap.timeline({paused:!0,defaults:{ease:"power2.inOut"}});t&&a.fromTo(t,{autoAlpha:0},{autoAlpha:1,duration:.4,ease:"none"});var i=[].concat(l(e.hasAttribute("aa-modal-animate")?[e]:[]),l(e.querySelectorAll("[aa-modal-animate]"))),c=Array.from(i).map((function(e){var t,r,n=(t=(e.getAttribute("aa-modal-order")||"").split("-"),r=2,function(e){if(Array.isArray(e))return e}(t)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,a,o,i,l=[],u=!0,c=!1;try{if(o=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=o.call(r)).done)&&(l.push(n.value),l.length!==t);u=!0);}catch(e){c=!0,a=e}finally{try{if(!u&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(c)throw a}}return l}}(t,r)||u(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),a=n[0],o=n[1];return{element:e,order:parseInt(a)||0,percent:o||null,animationType:e.getAttribute("aa-modal-animate")}}));return c.sort((function(e,t){return e.order-t.order})),c.forEach((function(e){var t=e.element,i=e.percent,l=e.animationType,u=parseFloat(t.getAttribute("aa-duration"))||.5,c=t.getAttribute("aa-ease")||"power2.out",d=parseFloat(t.getAttribute("aa-delay"))||0,f=parseFloat(t.getAttribute("aa-distance"))||1,y=i?">-".concat(i,"%"):"<",p=l?l.includes("-")?l.split("-")[0]:l:null;if("text"===p&&r&&r.text&&n){var m=t.getAttribute("aa-split")||"lines",b=parseFloat(t.getAttribute("aa-stagger"))||.01,v=l.replace(/-clip|-lines|-words|-chars$/,""),h=r.text[v];if(!h)return void console.warn("[ModalTimeline][Text] No animation found for:",l,"Available:",Object.keys(r.text));var g=h(t,m,u,b,0,c),A="<";if(i){var w=a.recent()?a.recent().endTime():0,S=a.recent()?a.recent().startTime():0;A=S+(w-S)*(parseInt(i)/100)}n(t,m,!1,(function(e){var t=g.onSplit(e);return a.add(t,A),t}),l)}else if(r&&r[p]){var O;switch(p){case"appear":O=r.appear(t,u,c,d,f,l);break;case"reveal":O=r.reveal(t,u,c,d,l);break;case"counter":O=r.counter(t,u,c,d,l)}O&&a.add(O,y)}else{var x=s[l];l.includes("custom")?a.to(t,{x:0,y:0,xPercent:0,yPercent:0,opacity:1,scale:1,duration:u,ease:c},y):x&&a.from(t,o(o({},x),{},{duration:u,ease:c}),y)}})),a}(i,a,t,r),d.set(i,c)),c.eventCallback("onComplete",null),c.eventCallback("onComplete",(function(){var e=i.querySelector('input, select, textarea, [tabindex]:not([tabindex="-1"])');e&&e.focus()})),c.timeScale(1).play(),y=function(e){function t(t){var r=e.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(r.length){var n=r[0],a=r[r.length-1];"Tab"===t.key&&(t.shiftKey&&document.activeElement===n?(t.preventDefault(),a.focus()):t.shiftKey||document.activeElement!==a||(t.preventDefault(),n.focus()))}}return document.addEventListener("keydown",t),function(){return document.removeEventListener("keydown",t)}}(i)}return n.style.display="flex",n.style.visibility="hidden",n.setAttribute("aa-modal-group-status","not-active"),i.forEach((function(e){e.style.visibility="hidden",e.style.display="none",e.setAttribute("aa-modal-status","not-active"),d.set(e,null)})),c.forEach((function(e){e.addEventListener("click",(function(){var t=e.getAttribute("aa-modal-target"),r=n.querySelector('[aa-modal-name="'.concat(t,'"]'));f&&p(f),r&&m(r)}))})),document.querySelectorAll("[aa-modal-close]").forEach((function(e){e.addEventListener("click",(function(){f&&p(f)}))})),document.addEventListener("keydown",(function(e){"Escape"===e.key&&f&&p(f)})),{open:m,close:p,timelines:d}}var f=null;function y(e,t,r,n){return f={gsap:e,lenis:t,animations:r,splitText:n},{modal:function(e){return d(f.lenis,f.animations,f.splitText,e)}}}}}]);