{ "version": 3, "sources": ["../../src/js/stat-counter.js"], "sourcesContent": ["export default class countUp {\n\tconstructor(el) {\n\t\tthis.el = el\n\t\tthis.triggered = false\n\t\tthis.setVars()\n\t\tthis.init()\n\t}\n\n\tsetVars() {\n\t\tthis.number = this.el.querySelectorAll('[data-countup-number]')\n\t\tthis.observerOptions = { root: null, rootMargin: '0px 0px', threshold: 0 }\n\t\tthis.observer = new IntersectionObserver(entries => {\n\t\t\tentries.forEach(entry => {\n\t\t\t\tconst end = parseFloat(\n\t\t\t\t\tentry.target.dataset.countupNumber.replace(/,/g, '')\n\t\t\t\t)\n\t\t\t\tconst decimals = this.countDecimals(end)\n\t\t\t\tif (entry.isIntersecting && !this.triggered) {\n\t\t\t\t\tthis.iterateValue(entry.target, end, decimals)\n\t\t\t\t\tthis.triggered = true\n\t\t\t\t}\n\t\t\t})\n\t\t}, this.observerOptions)\n\t}\n\n\tinit() {\n\t\tif (this.number.length > 0) {\n\t\t\tthis.number.forEach(el => {\n\t\t\t\tthis.observer.observe(el)\n\t\t\t})\n\t\t}\n\t}\n\n\titerateValue(el, end, decimals) {\n\t\tconst start = 0\n\t\tconst duration = 2500\n\t\tlet startTimestamp = null\n\n\t\tconst step = timestamp => {\n\t\t\tif (!startTimestamp) startTimestamp = timestamp\n\t\t\tconst elapsedPercent = (timestamp - startTimestamp) / duration\n\t\t\tconst easedProgress = Math.min(this.easeOutQuint(elapsedPercent), 1)\n\t\t\tlet interimNumber = Math.abs(easedProgress * (end - start) + start)\n\t\t\tel.innerHTML = this.formatNumber(interimNumber, decimals)\n\t\t\tif (easedProgress < 1) {\n\t\t\t\twindow.requestAnimationFrame(step)\n\t\t\t}\n\t\t}\n\n\t\t// requestAnimationFrame returns DOMHighResTimeStamp as a callback (used as timestamp)\n\t\twindow.requestAnimationFrame(step)\n\t}\n\n\teaseOutQuad(x) {\n\t\treturn 1 - Math.pow(1 - x, 3)\n\t}\n\n\teaseOutQuint(x) {\n\t\treturn 1 - Math.pow(1 - x, 5)\n\t}\n\n\tcountDecimals(val) {\n\t\tif (Math.floor(val) === val) return 0\n\t\treturn val.toString().split('.')[1].length || 0\n\t}\n\n\tformatNumber(val, decimals) {\n\t\treturn val.toLocaleString('en-US', {\n\t\t\tminimumFractionDigits: decimals,\n\t\t\tmaximumFractionDigits: decimals,\n\t\t})\n\t}\n}\n\n// Simplifed version of Viget dynamic modules to attach instances for this demo\n// https://www.viget.com/articles/how-does-viget-javascript/\n// You CAN use this pattern, but it's single purpose right now\nconst dataModules = [...document.querySelectorAll('[data-module=\"countup\"]')]\n\ndataModules.forEach(element => {\n\telement.dataset.module.split(' ').forEach(function () {\n\t\tnew countUp(element)\n\t})\n})\n"], "mappings": "mBAAA,IAAqBA,EAArB,KAA6B,CAC5B,YAAYC,EAAI,CACf,KAAK,GAAKA,EACV,KAAK,UAAY,GACjB,KAAK,QAAQ,EACb,KAAK,KAAK,CACX,CAEA,SAAU,CACT,KAAK,OAAS,KAAK,GAAG,iBAAiB,uBAAuB,EAC9D,KAAK,gBAAkB,CAAE,KAAM,KAAM,WAAY,UAAW,UAAW,CAAE,EACzE,KAAK,SAAW,IAAI,qBAAqBC,GAAW,CACnDA,EAAQ,QAAQC,GAAS,CACxB,IAAMC,EAAM,WACXD,EAAM,OAAO,QAAQ,cAAc,QAAQ,KAAM,EAAE,CACpD,EACME,EAAW,KAAK,cAAcD,CAAG,EACnCD,EAAM,gBAAkB,CAAC,KAAK,YACjC,KAAK,aAAaA,EAAM,OAAQC,EAAKC,CAAQ,EAC7C,KAAK,UAAY,GAEnB,CAAC,CACF,EAAG,KAAK,eAAe,CACxB,CAEA,MAAO,CACF,KAAK,OAAO,OAAS,GACxB,KAAK,OAAO,QAAQJ,GAAM,CACzB,KAAK,SAAS,QAAQA,CAAE,CACzB,CAAC,CAEH,CAEA,aAAaA,EAAIG,EAAKC,EAAU,CAG/B,IAAIC,EAAiB,KAEfC,EAAOC,GAAa,CACpBF,IAAgBA,EAAiBE,GACtC,IAAMC,GAAkBD,EAAYF,GAAkB,KAChDI,EAAgB,KAAK,IAAI,KAAK,aAAaD,CAAc,EAAG,CAAC,EAC/DE,EAAgB,KAAK,IAAID,GAAiBN,EAAM,GAAS,CAAK,EAClEH,EAAG,UAAY,KAAK,aAAaU,EAAeN,CAAQ,EACpDK,EAAgB,GACnB,OAAO,sBAAsBH,CAAI,CAEnC,EAGA,OAAO,sBAAsBA,CAAI,CAClC,CAEA,YAAYK,EAAG,CACd,MAAO,GAAI,KAAK,IAAI,EAAIA,EAAG,CAAC,CAC7B,CAEA,aAAaA,EAAG,CACf,MAAO,GAAI,KAAK,IAAI,EAAIA,EAAG,CAAC,CAC7B,CAEA,cAAcC,EAAK,CAClB,OAAI,KAAK,MAAMA,CAAG,IAAMA,EAAY,EAC7BA,EAAI,SAAS,EAAE,MAAM,GAAG,EAAE,CAAC,EAAE,QAAU,CAC/C,CAEA,aAAaA,EAAKR,EAAU,CAC3B,OAAOQ,EAAI,eAAe,QAAS,CAClC,sBAAuBR,EACvB,sBAAuBA,CACxB,CAAC,CACF,CACD,EAKMS,EAAc,CAAC,GAAG,SAAS,iBAAiB,yBAAyB,CAAC,EAE5EA,EAAY,QAAQC,GAAW,CAC9BA,EAAQ,QAAQ,OAAO,MAAM,GAAG,EAAE,QAAQ,UAAY,CACrD,IAAIf,EAAQe,CAAO,CACpB,CAAC,CACF,CAAC", "names": ["countUp", "el", "entries", "entry", "end", "decimals", "startTimestamp", "step", "timestamp", "elapsedPercent", "easedProgress", "interimNumber", "x", "val", "dataModules", "element"] }