const body=document.body,MathUtils={lerp:(e,t,s)=>(1-s)*e+s*t,distance:(e,t,s,i)=>Math.hypot(s-e,i-t)},getMousePos=e=>{let t=0,s=0;return e||(e=window.event),e.pageX||e.pageY?(t=e.pageX,s=e.pageY):(e.clientX||e.clientY)&&(t=e.clientX+body.scrollLeft,s=e.clientY+body.scrollTop),{x:t,y:s}};let mousePos=lastMousePos=cacheMousePos={x:0,y:0};window.addEventListener("mousemove",e=>mousePos=getMousePos(e));const getMouseDistance=()=>MathUtils.distance(mousePos.x,mousePos.y,lastMousePos.x,lastMousePos.y);class Image{constructor(e){this.DOM={el:e},this.defaultStyle={scale:1,x:0,y:0,opacity:0},this.getRect(),this.initEvents()}initEvents(){window.addEventListener("resize",()=>this.resize())}resize(){anime.set(this.DOM.el,this.defaultStyle),this.getRect()}getRect(){this.rect=this.DOM.el.getBoundingClientRect()}isActive(){return parseFloat(this.DOM.el.style.opacity)>0}}class ImageTrail{constructor(){this.DOM={content:document.querySelector(".content")},this.images=[],[...this.DOM.content.querySelectorAll("img")].forEach(e=>this.images.push(new Image(e))),this.imagesTotal=this.images.length,this.imgPosition=0,this.zIndexVal=1,this.threshold=100,requestAnimationFrame(()=>this.render())}render(){let e=getMouseDistance();cacheMousePos.x=MathUtils.lerp(cacheMousePos.x||mousePos.x,mousePos.x,.1),cacheMousePos.y=MathUtils.lerp(cacheMousePos.y||mousePos.y,mousePos.y,.1),e>this.threshold&&(this.showNextImage(),++this.zIndexVal,this.imgPosition=this.imgPosition<this.imagesTotal-1?this.imgPosition+1:0,lastMousePos=mousePos),this.images.every(e=>!e.isActive())&&1!==this.zIndexVal&&(this.zIndexVal=1),requestAnimationFrame(()=>this.render())}showNextImage(){const e=this.images[this.imgPosition];anime.remove(e.DOM.el),anime.set(e.DOM.el,{opacity:0,scale:1,zIndex:this.zIndexVal,translateX:cacheMousePos.x-e.rect.width/2,translateY:cacheMousePos.y-e.rect.height/2}),anime.timeline().add({targets:e.DOM.el,opacity:1,translateX:mousePos.x-e.rect.width/2,translateY:mousePos.y-e.rect.height/2,easing:"easeOutExpo",duration:900}).add({targets:e.DOM.el,opacity:0,easing:"easeOutQuad",duration:1e3},400).add({targets:e.DOM.el,scale:.2,easing:"easeOutQuint",duration:1e3},400)}}const preloadImages=()=>new Promise(e=>{imagesLoaded(document.querySelectorAll(".content__img"),e)});preloadImages().then(()=>{document.body.classList.remove("loading"),new ImageTrail});