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AACC,OAAO,CAACC,KAAK,IAAI;QACvB,MAAMV,OAAO,GAAGU,KAAK,CAACC,MAAM,CAACC,aAAa,CAAE,4CAA2C,CAAC;QACxF,IAAGF,KAAK,CAACG,cAAc,KAAK,IAAI,EAAE;UAChC,IAAIb,OAAO,CAACI,SAAS,IAAI,CAAC,EAAG;YAC3B;YACAV,cAAc,CAACM,OAAO,CAAC;UACzB;QACF,CAAC,MAAM;UACLA,OAAO,CAACI,SAAS,GAAG,CAAC;QACvB;MACF,CAAE,CAAC;IACL,CAAC,EAAE;MAAEU,SAAS,EAAE,CAAC,CAAC;IAAE,CAAC,CAAC;IAEtB9B,aAAa,CAACyB,OAAO,CAAEM,YAAY,IAAI;MACrCT,QAAQ,CAACU,OAAO,CAAED,YAAa,CAAC;IAClC,CAAE,CAAC;EAEL;AACF,C","sources":["webpack://webdevia-blocks/./includes/block-editor/blocks/count-up/view.js"],"sourcesContent":["document.addEventListener( 'DOMContentLoaded', init )\r\n\r\nfunction init () {\r\n const countUpBlocks = document.querySelectorAll(`.wp-block-webdevia-count-up`)\r\n if( countUpBlocks.length ) {\r\n // How long you want the animation to take, in ms\r\n const animationDuration = 1500\r\n // Calculate how long each ‘frame’ should last if we want to update the animation 60 times per second\r\n const frameDuration = 1000 / 60\r\n // Use that to calculate how many frames we need to complete the animation\r\n const totalFrames = Math.round( animationDuration / frameDuration )\r\n // An ease-out function that slows the count as it progresses\r\n const easeOutQuad = t => t * ( 2 - t )\r\n\r\n // The animation function, which takes an Element\r\n const animateCountUp = el => {\r\n let frame = 0\r\n const countTo = parseInt( el.dataset.counter, 10 )\r\n // Start the animation running 60 times per second\r\n const counter = setInterval( () => {\r\n frame++\r\n // Calculate our progress as a value between 0 and 1\r\n // Pass that value to our easing function to get our\r\n // progress on a curve\r\n const progress = easeOutQuad( frame / totalFrames )\r\n // Use the progress value to calculate the current count\r\n const currentCount = Math.round( countTo * progress )\r\n \r\n // If the current count has changed, update the element\r\n if ( parseInt( el.innerHTML, 10 ) !== currentCount ) {\r\n el.innerHTML = currentCount\r\n }\r\n\r\n // If we’ve reached our last frame, stop the animation\r\n if ( frame === totalFrames ) {\r\n clearInterval( counter )\r\n }\r\n }, frameDuration )\r\n }\r\n const observer = new IntersectionObserver(function(entries) {\r\n entries.forEach(entry => {\r\n const counter = entry.target.querySelector(`.wp-block-webdevia-count-up__info__counter`)\r\n if(entry.isIntersecting === true) {\r\n if( counter.innerHTML == 0 ) {\r\n // countUp(counter, 0)\r\n animateCountUp(counter)\r\n }\r\n } else {\r\n counter.innerHTML = 0\r\n }\r\n } )\r\n }, { threshold: [0] })\r\n \r\n countUpBlocks.forEach( countUpBlock => {\r\n observer.observe( countUpBlock )\r\n } )\r\n \r\n }\r\n}\r\n"],"names":["document","addEventListener","init","countUpBlocks","querySelectorAll","length","animationDuration","frameDuration","totalFrames","Math","round","easeOutQuad","t","animateCountUp","el","frame","countTo","parseInt","dataset","counter","setInterval","progress","currentCount","innerHTML","clearInterval","observer","IntersectionObserver","entries","forEach","entry","target","querySelector","isIntersecting","threshold","countUpBlock","observe"],"sourceRoot":""}