ruạṛ
!function(t){"use strict";class e{constructor(e){this.element=e,this.$element=t(e),this.isAnimated=!1,this.isAnimating=!1,this.isInViewport=!1,this.observer=null,this.paths=[],this.loopTimeout=null,this.currentLoop=0,this.init()}init(){this.settings={animationType:this.$element.data("animation-type")||"sync",animationTrigger:this.$element.data("animation-trigger")||"viewport",animationDuration:this.$element.data("animation-duration")||3,animationDelay:this.$element.data("animation-delay")||0,pathTimingFunction:this.$element.data("path-timing-function")||"ease-out",autoStart:this.$element.data("auto-start")||"yes",replayOnClick:this.$element.data("replay-on-click")||"no",looping:this.$element.data("looping")||"none",loopCount:this.$element.data("loop-count")||1,direction:this.$element.data("direction")||"forward",fillMode:this.$element.data("fill-mode")||"none",fillDuration:this.$element.data("fill-duration")||1,staggerDelay:this.$element.data("stagger-delay")||100,lazyLoad:this.$element.data("lazy-load")||"no"},this.findSVGElements(),this.setupAnimationTrigger(),this.setupReplayClick()}findSVGElements(){const t=this.$element.find("svg");if(0===t.length)return;this.paths=[],["path","circle","rect","line","polyline","polygon","ellipse"].forEach(e=>{t.find(e).each((t,e)=>{this.preparePath(e)})})}preparePath(e){const i=t(e);let s=0;try{if((s=e.getTotalLength?e.getTotalLength():this.estimatePathLength(e))>0){const t={element:e,$element:i,length:s};this.paths.push(t),i.css({"stroke-dasharray":s+" "+s,"stroke-dashoffset":s}),this.setupPathFillMode(i),i.addClass("uael-svg-animate")}}catch(t){console.warn("UAEL SVG Animator: Could not measure path length",t)}}setupPathFillMode(t){switch(this.settings.fillMode){case"before":t.css("fill-opacity","1");break;case"after":t.css("fill-opacity","0");break;case"always":t.css("fill-opacity","1");break;case"none":default:t.css("fill-opacity","0")}}estimatePathLength(t){let e=0;switch(t.tagName.toLowerCase()){case"circle":const i=parseFloat(t.getAttribute("r"))||0;e=2*Math.PI*i;break;case"ellipse":const s=parseFloat(t.getAttribute("rx"))||0,a=parseFloat(t.getAttribute("ry"))||0;e=Math.PI*(3*(s+a)-Math.sqrt((3*s+a)*(s+3*a)));break;case"rect":e=2*((parseFloat(t.getAttribute("width"))||0)+(parseFloat(t.getAttribute("height"))||0));break;case"line":const n=parseFloat(t.getAttribute("x1"))||0,o=parseFloat(t.getAttribute("y1"))||0,l=parseFloat(t.getAttribute("x2"))||0,h=parseFloat(t.getAttribute("y2"))||0;e=Math.sqrt(Math.pow(l-n,2)+Math.pow(h-o,2));break;case"polyline":case"polygon":const r=t.getAttribute("points");r&&(e=this.calculatePolylineLength(r))}return e}calculatePolylineLength(t){const e=t.trim().split(/[\s,]+/);let i=0;for(let t=0;t<e.length-2;t+=2){const s=parseFloat(e[t]),a=parseFloat(e[t+1]),n=parseFloat(e[t+2]),o=parseFloat(e[t+3]);isNaN(s)||isNaN(a)||isNaN(n)||isNaN(o)||(i+=Math.sqrt(Math.pow(n-s,2)+Math.pow(o-a,2)))}return i}setupAnimationTrigger(){if(this.setupViewportObserver(),"no"!==this.settings.autoStart)switch(this.settings.animationTrigger){case"auto":this.settings.animationDelay>0?setTimeout(()=>{this.startAnimation()},1e3*this.settings.animationDelay):this.startAnimation();break;case"viewport":break;case"hover":this.setupHoverTrigger();break;case"click":this.setupClickTrigger();break;case"delay":setTimeout(()=>{this.startAnimation()},1e3*this.settings.animationDelay)}}setupViewportObserver(){if(!window.IntersectionObserver)return void this.startAnimation();this.observer=new IntersectionObserver(t=>{t.forEach(t=>{t.isIntersecting?(this.$element.addClass("uael-svg-in-view"),this.isInViewport=!0,this.isAnimated||this.isAnimating||"viewport"!==this.settings.animationTrigger||setTimeout(()=>{this.startAnimation()},100)):(this.$element.removeClass("uael-svg-in-view"),this.isInViewport=!1,this.loopTimeout&&(clearTimeout(this.loopTimeout),this.loopTimeout=null))})},{root:null,rootMargin:"0px",threshold:.1}),this.observer.observe(this.element)}setupHoverTrigger(){this.$element.find(".uael-svg-container").on("mouseenter",()=>{this.isAnimated||this.isAnimating||this.startAnimation()})}setupClickTrigger(){this.$element.find(".uael-svg-container").on("click",t=>{this.$element.closest("a").length||t.preventDefault(),this.isAnimated||this.isAnimating?"yes"===this.settings.replayOnClick&&this.replayAnimation():this.startAnimation()})}setupReplayClick(){("yes"===this.settings.replayOnClick||!0===this.settings.replayOnClick)&&"click"!==this.settings.animationTrigger&&this.$element.find(".uael-svg-container").on("click",t=>{this.$element.closest("a").length||t.preventDefault(),this.replayAnimation()})}startAnimation(){if(!this.isAnimating&&0!==this.paths.length)switch(this.isAnimating=!0,this.$element.addClass("uael-svg-animating"),"backward"===this.settings.direction&&(this.paths=this.paths.reverse()),this.settings.animationType){case"sync":this.animateSync();break;case"delayed":this.animateDelayed();break;case"one-by-one":this.animateOneByOne();break;default:this.animateSync()}}animateSync(){const t=1e3*this.settings.animationDuration;let e=0;this.paths.forEach(i=>{this.animatePath(i,0,t,()=>{++e===this.paths.length&&this.onAnimationComplete()})})}animateDelayed(){const t=1e3*this.settings.animationDuration,e=this.settings.staggerDelay;let i=0;this.paths.forEach((s,a)=>{const n=a*e;this.animatePath(s,n,t,()=>{++i===this.paths.length&&this.onAnimationComplete()})})}animateOneByOne(){const t=1e3*this.settings.animationDuration/this.paths.length;let e=0;const i=()=>{if(e>=this.paths.length)return void this.onAnimationComplete();const s=this.paths[e];this.animatePath(s,0,t,()=>{e++,i()})};i()}animatePath(t,e,i,s){setTimeout(()=>{const e=t.$element,a=this.settings.pathTimingFunction;e.css({transition:`stroke-dashoffset ${i}ms ${a}`,"stroke-dashoffset":"0"});const n=()=>{e.off("transitionend",n),s&&s()};e.on("transitionend",n),setTimeout(n,i+50)},e)}onAnimationComplete(){this.isAnimating=!1,this.isAnimated=!0,this.$element.removeClass("uael-svg-animating").addClass("uael-svg-animated"),this.paths.forEach(t=>{t.$element.css("transition","")}),this.handleFillAnimation(),this.handleLooping()}handleFillAnimation(){if("after"===this.settings.fillMode||"always"===this.settings.fillMode){const t=1e3*this.settings.fillDuration;this.paths.forEach(e=>{e.$element.css({transition:`fill ${t}ms ease`,"fill-opacity":"1"})})}}handleLooping(){this.isInViewport&&("infinite"===this.settings.looping?this.scheduleNextLoop():"count"===this.settings.looping&&(this.currentLoop=(this.currentLoop||1)+1,this.currentLoop<this.settings.loopCount?this.scheduleNextLoop():this.currentLoop=0))}scheduleNextLoop(){this.loopTimeout=setTimeout(()=>{this.isInViewport&&!this.isAnimating&&this.replayAnimation()},500)}replayAnimation(){this.isAnimating||(this.isAnimated=!1,this.$element.removeClass("uael-svg-animated"),this.paths.forEach(t=>{t.$element.css({"stroke-dashoffset":t.length,transition:""})}),setTimeout(()=>{this.startAnimation()},100))}destroy(){this.observer&&(this.observer.disconnect(),this.observer=null),this.loopTimeout&&(clearTimeout(this.loopTimeout),this.loopTimeout=null),this.$element.find(".uael-svg-container").off("click"),this.$element.removeClass("uael-svg-animating uael-svg-animated uael-svg-in-view"),this.paths.forEach(t=>{t.$element.removeClass("uael-svg-animate").css({"stroke-dasharray":"","stroke-dashoffset":"",transition:""})}),this.paths=[]}}function i(){t(".uael-svg-animator").each(function(){if(!t(this).data("uael-svg-animator")){const i=new e(this);t(this).data("uael-svg-animator",i)}})}let s;t.fn.uaelSVGAnimator=function(){return this.each(function(){if(!t(this).data("uael-svg-animator")){const i=new e(this);t(this).data("uael-svg-animator",i)}})},t(function(){i()}),t(window).on("elementor/frontend/init",function(){"undefined"!=typeof elementorFrontend&&elementorFrontend.hooks.addAction("frontend/element_ready/uael-svg-animator.default",function(t){t.find(".uael-svg-animator").uaelSVGAnimator()})}),t(document).on("DOMNodeInserted",".uael-svg-animator",function(){clearTimeout(s),s=setTimeout(i,150)}),window.UAELSVGAnimator=e}(jQuery);
cải xoăn