{"version":3,"sources":["webpack:///./src/js/modules/solutionFeatured.js"],"names":["Module","this","dom","counters","el","querySelectorAll","featuredSection","hiddenCounters","countContainer","animated","window","addEventListener","handleCounters","bind","e","isInViewport","startCounters","resetCounter","element","rect","getBoundingClientRect","viewportHeight","innerHeight","document","documentElement","clientHeight","viewportWidth","innerWidth","clientWidth","elementArea","width","height","Math","max","min","right","left","bottom","top","forEach","counter","index","iterations","getAttribute","updateCount","target","parseFloat","decimalPlaces","getDecimalPlaces","count","increment","updatedCount","toFixed","updatedHiddenCount","classList","remove","offsetWidth","innerText","setAttribute","add","setTimeout","style","transform","initialCount","value","stringValue","toString","indexOfDecimal","indexOf","length","Component"],"mappings":"i/CAEMA,E,iXAEFC,KAAKC,IAAI,CACPC,SAAUF,KAAKG,GAAGC,iBAAiB,2BACnCC,gBAAiBL,KAAKG,GACtBG,eAAgBN,KAAKG,GAAGC,iBAAiB,kCACzCG,eAAgBP,KAAKG,GAAGC,iBAAiB,wCAE3CJ,KAAKQ,UAAW,I,qCAIhBC,OAAOC,iBAAiB,OAAQV,KAAKW,eAAeC,KAAKZ,OACzDS,OAAOC,iBAAiB,SAAUV,KAAKW,eAAeC,KAAKZ,S,qCAG9Ca,GACTb,KAAKc,aAAad,KAAKC,IAAII,mBAAqBL,KAAKQ,UACvDR,KAAKe,gBACLf,KAAKQ,UAAW,GACNR,KAAKc,aAAad,KAAKC,IAAII,mBACrCL,KAAKgB,eACLhB,KAAKQ,UAAW,K,mCAIPS,GACX,IAAMC,EAAOD,EAAQE,wBACfC,EAAiBX,OAAOY,aAAeC,SAASC,gBAAgBC,aAChEC,EAAgBhB,OAAOiB,YAAcJ,SAASC,gBAAgBI,YAC9DC,EAAcV,EAAKW,MAAQX,EAAKY,OAItC,OAHyBC,KAAKC,IAAI,EAAGD,KAAKE,IAAIf,EAAKgB,MAAOT,GAAiBM,KAAKC,IAAId,EAAKiB,KAAM,IACxEJ,KAAKC,IAAI,EAAGD,KAAKE,IAAIf,EAAKkB,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B,EAAQkB,aAAa,oBAAqBK,Q,uCAI7BC,GACf,IAAMC,EAAcD,EAAME,WACpBC,EAAiBF,EAAYG,QAAQ,KAC3C,OAAwB,IAApBD,EACK,EAEFF,EAAYI,OAASF,EAAiB,O,8BA/F5BG,aAmGNtE","file":"58.b2c0748c0522c48a3abc.js","sourcesContent":["import { Component } from '@verndale/core';\r\n\r\nclass Module extends Component {\r\n  setupDefaults() {\r\n    this.dom={\r\n      counters: this.el.querySelectorAll('.statistics-card__count'),\r\n      featuredSection: this.el,\r\n      hiddenCounters: this.el.querySelectorAll('.statistics-card__hidden-count'),\r\n      countContainer: this.el.querySelectorAll('.statistics-card__absolute-position')\r\n    }\r\n    this.animated = false;\r\n  }\r\n\r\n  addListeners() {\r\n    window.addEventListener('load', this.handleCounters.bind(this));\r\n    window.addEventListener('scroll', this.handleCounters.bind(this));\r\n  }\r\n\r\n  handleCounters(e) {\r\n    if (this.isInViewport(this.dom.featuredSection) && !this.animated) {\r\n      this.startCounters();\r\n      this.animated = true;\r\n    } else if (!this.isInViewport(this.dom.featuredSection)) {\r\n      this.resetCounter();\r\n      this.animated = false;\r\n    }\r\n  }\r\n\r\n  isInViewport(element) {\r\n    const rect = element.getBoundingClientRect();\r\n    const viewportHeight = window.innerHeight || document.documentElement.clientHeight;\r\n    const viewportWidth = window.innerWidth || document.documentElement.clientWidth;\r\n    const elementArea = rect.width * rect.height;\r\n    const intersectionArea = Math.max(0, Math.min(rect.right, viewportWidth) - Math.max(rect.left, 0)) *\r\n                           Math.max(0, Math.min(rect.bottom, viewportHeight) - Math.max(rect.top, 0));\r\n    const visibilityPercentage = intersectionArea / elementArea * 100;\r\n    return visibilityPercentage > 50;\r\n  }\r\n\r\n  startCounters() {\r\n    this.resetCounter();\r\n    this.dom.counters.forEach((counter, index) => {\r\n      const iterations = (counter.getAttribute('data-iterations') ? counter.getAttribute('data-iterations'): 8);\r\n      const updateCount = () => {\r\n        const target = parseFloat(counter.getAttribute('data-count'));\r\n        const decimalPlaces = this.getDecimalPlaces(target);\r\n        const count = parseFloat(counter.getAttribute('data-hidden-count'));\r\n        const increment = parseFloat(target / iterations);\r\n        const updatedCount = parseFloat((count + increment)).toFixed(decimalPlaces);\r\n        const updatedHiddenCount = parseFloat(count + increment);\r\n        if (updatedCount < target && count === 0) {\r\n          counter.classList.remove('start-animation');\r\n          counter.offsetWidth; // Trigger reflow\r\n          counter.innerText = updatedCount;\r\n          counter.setAttribute('data-hidden-count', updatedHiddenCount);\r\n          count\r\n          counter.classList.add('start-animation');\r\n          setTimeout(updateCount, 250);\r\n        }\r\n\r\n        if (updatedCount < target && count !== 0) {\r\n          counter.classList.remove('start-animation');\r\n          counter.classList.remove('counter-animation');\r\n          counter.offsetWidth; // Trigger reflow\r\n          counter.style.transform = 'translateY(-100%)';\r\n          counter.innerText = updatedCount;\r\n          counter.setAttribute('data-hidden-count', updatedHiddenCount);\r\n          counter.classList.add('counter-animation');\r\n          setTimeout(updateCount, 250);\r\n        } else if (updatedCount >= target) {\r\n          counter.classList.remove('start-animation');\r\n          counter.classList.remove('counter-animation');\r\n          counter.classList.remove('end-animation');\r\n          counter.innerText = target;\r\n          counter.setAttribute('data-hidden-count', target);\r\n          counter.classList.add('end-animation');\r\n        }\r\n      };\r\n      updateCount();\r\n    });\r\n  }\r\n\r\n  resetCounter() {\r\n    this.dom.counters.forEach(counter => {\r\n      const initialCount = (counter.getAttribute('data-reset') ? counter.getAttribute('data-reset'): 0);\r\n      counter.classList.remove('end-animation');\r\n      counter.style.transform = 'translateY(0)';\r\n      counter.setAttribute('data-hidden-count', initialCount);\r\n    });\r\n  }\r\n\r\n  getDecimalPlaces(value) {\r\n    const stringValue = value.toString();\r\n    const indexOfDecimal = stringValue.indexOf('.');\r\n    if (indexOfDecimal === -1) {\r\n      return 0;\r\n    }\r\n    return stringValue.length - indexOfDecimal - 1;\r\n  }\r\n}\r\n\r\nexport default Module;\r\n"],"sourceRoot":""}