{"version":3,"file":"scripts.min.js","mappings":"oBAAIA,EAASC,OAYb,SAASC,IACPF,EAAOG,YAAYC,OAChBC,SAAQ,SAACC,GACRC,MAAMC,KAAKC,SAASC,uBAAuBJ,IAC1CD,SAAQ,SAACM,IACDA,EAAQC,UAAUC,SAAS,yBAQ1C,SAAsBF,GACpB,IAAIG,EAAaH,EAAQI,wBAAwBC,IAC7CC,EAAgBH,EAAaH,EAAQI,wBAAwBG,OAC7DC,EAAclB,OAAOmB,QACrBC,EAAiBF,EAAclB,OAAOqB,YAC1C,OAAOL,EAAgBE,GAAeL,EAAaO,EAbgBE,CAAaZ,MAgBlF,SAAsBA,EAAca,EAAcC,GAChD,IAAIC,EAAiBC,KAAKC,MACpBC,EAAO,WAET,IAAMC,EAAWC,KAAKC,KAAKL,KAAKC,MAAQF,GAAaD,EAAU,GAE/Dd,EAAQsB,UAAYF,KAAKG,MAAMJ,EAAWN,GAEtCM,EAAW,EAAG7B,OAAOkC,sBAAsBN,GAC1C5B,OAAOmC,qBAAqBnC,OAAOkC,sBAAsBN,KAGlE5B,OAAOkC,sBAAsBN,GA3BnBQ,CAAa1B,EAASA,EAAQ2B,aAAa,cAAe,KAC1D3B,EAAQC,UAAU2B,IAAI,+BAlBhB,QAAlB,EAAAvC,EAAOG,mBAAW,QAAlBH,EAAOG,YAAgB,IACA,QAAvB,KAAAH,EAAOG,aAAYqC,YAAI,UAAJA,KAGnB,SAAyB,G,IAAElC,EAAK,QAC9BN,EAAOG,YAAYC,OAAOqC,KAAKnC,GAC/BJ,MAJuB,QAAzB,KAAAF,EAAOG,aAAYC,cAAM,UAANA,OAAW,IAO9BH,OAAOyC,iBAAiB,UAAU,WAAM,OAAAxC,Q","sources":["webpack://app-counter2/./src/ts/index.ts"],"sourcesContent":["var winAny = window as any;\r\nwinAny.appCounter2 ??= {};\r\nwinAny.appCounter2.init ??= initAppCounter2;\r\nwinAny.appCounter2.domIds ??= [];\r\n\r\nfunction initAppCounter2({ domId } : { domId: string }) {\r\n winAny.appCounter2.domIds.push(domId);\r\n checkCounters();\r\n}\r\n\r\nwindow.addEventListener('scroll', () => checkCounters());\r\n\r\nfunction checkCounters() {\r\n winAny.appCounter2.domIds\r\n .forEach((domId: string) => {\r\n Array.from(document.getElementsByClassName(domId))\r\n .forEach((counter: HTMLElement) => {\r\n if (!counter.classList.contains('app-counter2-js-seen') && isInViewport(counter)) {\r\n startCounter(counter, counter.getAttribute('data-count'), 2000);\r\n counter.classList.add('app-counter2-js-seen')\r\n }\r\n });\r\n });\r\n}\r\n\r\nfunction isInViewport(counter: HTMLElement) {\r\n var elementTop = counter.getBoundingClientRect().top;\r\n var elementBottom = elementTop + counter.getBoundingClientRect().bottom;\r\n var viewportTop = window.scrollY;\r\n var viewportBottom = viewportTop + window.innerHeight;\r\n return elementBottom > viewportTop && elementTop < viewportBottom;\r\n}\r\n\r\nfunction startCounter(counter: any, lastVal: any, duration: any) {\r\n let startTime: any = Date.now();\r\n const step = () => {\r\n //calculate the value to be used in calculating the number to be displayed\r\n const progress = Math.min((Date.now() - startTime) / duration, 1);\r\n //calculate what to be displayed using the value gotten above\r\n counter.innerHTML = Math.floor(progress * lastVal);\r\n //checking to make sure the counter does not exceed the last value (lastVal)\r\n if (progress < 1) window.requestAnimationFrame(step);\r\n else window.cancelAnimationFrame(window.requestAnimationFrame(step));\r\n };\r\n\r\n window.requestAnimationFrame(step);\r\n}"],"names":["winAny","window","checkCounters","appCounter2","domIds","forEach","domId","Array","from","document","getElementsByClassName","counter","classList","contains","elementTop","getBoundingClientRect","top","elementBottom","bottom","viewportTop","scrollY","viewportBottom","innerHeight","isInViewport","lastVal","duration","startTime","Date","now","step","progress","Math","min","innerHTML","floor","requestAnimationFrame","cancelAnimationFrame","startCounter","getAttribute","add","init","push","addEventListener"],"sourceRoot":""}