anim8-core
Version:
Custom JavaScript animation library with modular effects
2 lines (1 loc) • 4.77 kB
JavaScript
(function(r,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(r=typeof globalThis<"u"?globalThis:r||self,c(r.anim8={}))})(this,function(r){"use strict";function c(e,t,n={}){const{duration:o=1e3,easing:a,delay:s=0}=n,i=typeof a=="function"?a:l=>l,m=performance.now(),M=["translateX","translateY","scale","rotate"];for(const l in t)t[l][0];function O(l){const d=[];for(const f in t){const[X,k]=t[f],C=i(l),y=X+(k-X)*C;M.includes(f)?f==="translateX"||f==="translateY"?d.push(`${f}(${y}px)`):f==="scale"?d.push(`scale(${y})`):f==="rotate"&&d.push(`rotate(${y}deg)`):e.style[f]=typeof y=="number"?`${y}`:y}d.length>0&&(e.style.transform=d.join(" "))}function g(l){const d=l-m;if(d<s){requestAnimationFrame(g);return}const f=Math.min((d-s)/o,1);O(f),f<1&&requestAnimationFrame(g)}requestAnimationFrame(g)}function u(e,{all:t=!1}={}){if(typeof e=="string"){const n=t?document.querySelectorAll(e):document.querySelector(e);return!n||t&&n.length===0?(console.warn(`resolveElement: No element(s) found for selector "${e}"`),t?[]:null):t?Array.from(n):n}return e instanceof HTMLElement?t?[e]:e:(console.warn("resolveElement: Invalid target provided",e),t?[]:null)}function p(e){return e===1?1:1-Math.pow(2,-10*e)}function v(e,t={}){const n=u(e);n&&c(n,{opacity:[0,1]},{duration:t.duration||800,easing:t.easing||p,delay:t.delay||0})}function h(e,t="left",n=200){const o=u(e);if(!o)return;let a,s;switch(t){case"right":a="translateX",s=n;break;case"top":a="translateY",s=-n;break;case"bottom":a="translateY",s=n;break;case"left":default:a="translateX",s=-n}c(o,{[a]:[s,0],opacity:[0,1]},{duration:800,easing:p})}function b(e){const t=u(e);t&&c(t,{rotate:[0,360]},{duration:1e3,easing:p})}function E(e){const t=u(e);t&&c(t,{rotate:[0,360],scale:[.5,1]},{duration:1e3,easing:p})}const w=(e,t={})=>{const n=u(e,{all:!0});if(!n.length)return;const o=new IntersectionObserver((a,s)=>{a.forEach(i=>{i.isIntersecting&&(i.target.classList.add("animate-scrollReveal"),t.once!==!1&&s.unobserve(i.target))})});n.forEach(a=>{o.observe(a)})};function S(e,t={}){const n=document.querySelectorAll(e),{delay:o=100,pulseScale:a=1.3,pulseDuration:s=150,letterDelay:i=60}=t;n.forEach(m=>{const M=m.textContent.trim();m.textContent="",m.style.display="inline-block",[...M].forEach((O,g)=>{const l=document.createElement("span");l.textContent=O,l.style.display="inline-block",l.style.opacity=0,l.style.transition=`transform ${s}ms ease, opacity 300ms ease`,m.appendChild(l),setTimeout(()=>{l.style.opacity=1,l.style.transform=`scale(${a})`,setTimeout(()=>{l.style.transform="scale(1)"},s)},o+g*i)})})}function $(e){const t=u(e);if(!t)return;t.querySelectorAll(".nav-item").forEach(o=>{o.addEventListener("mouseenter",()=>{o.classList.add("active-gooey")}),o.addEventListener("mouseleave",()=>{o.classList.remove("active-gooey")})})}function I(e,t={}){const{direction:n="left",duration:o=1e3,easing:a="ease"}=t,s=u(e);if(!s)return;s.style.transition=`transform ${o}ms ${a}, opacity ${o}ms ${a}`,s.style.opacity="0";const i={left:"translateX(-100%)",right:"translateX(100%)",top:"translateY(-100%)",bottom:"translateY(100%)"};s.style.transform=i[n]||i.left}function q(e,t={}){let n;if(typeof e=="string")n=document.querySelectorAll(e);else{const o=u(e);if(!o)return;n=[o]}n.forEach(o=>{c(o,{opacity:[0,1],transform:["scale(0.8) translateZ(-200px)","scale(1) translateZ(0)"]},{duration:t.duration||700,easing:t.easing||"ease-out",delay:t.delay||0})})}function A(e,t,n={}){const o=u(e,{all:!0});o.length&&o.forEach((a,s)=>{setTimeout(()=>{t(a,n)},(n.staggerDelay||100)*s)})}function T(e,t={}){let n;if(typeof e=="string")n=document.querySelectorAll(e);else{const o=u(e);if(!o)return;n=[o]}n.forEach(o=>{c(o,{opacity:[0,1],filter:["blur(10px)","blur(0)"]},{duration:t.duration||600,easing:t.easing||"ease-out",delay:t.delay||0})})}function L(e,t,n={}){const o=typeof e=="string"?document.querySelectorAll(e):[e],a=new IntersectionObserver(s=>{s.forEach(i=>{i.isIntersecting&&(t(i.target),a.unobserve(i.target))})},n);o.forEach(s=>{a.observe(s)})}const Y={fadeIn:v,slideIn:h,rotate:b,rotateScale:E,scrollReveal:w,typewriterPulse:S,gooeyNav:$,slideOut:I,depthZoom:q,stagger:A,blurIn:T,scrollTrigger:L,animate:c,resolveElement:u};typeof window<"u"&&(window.anim8={fadeIn:v,slideIn:h,rotate:b,rotateScale:E,scrollReveal:w,typewriterPulse:S,gooeyNav:$,slideOut:I,depthZoom:q,stagger:A,blurIn:T,scrollTrigger:L,animate:c,resolveElement:u}),r.animate=c,r.blurIn=T,r.default=Y,r.depthZoom=q,r.fadeIn=v,r.gooeyNav=$,r.resolveElement=u,r.rotate=b,r.rotateScale=E,r.scrollReveal=w,r.scrollTrigger=L,r.slideIn=h,r.slideOut=I,r.stagger=A,r.typewriterPulse=S,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});