countup__js.js 7.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import "./chunk-AC2VUBZ6.js";
  2. // node_modules/countup.js/dist/countUp.min.js
  3. var t = function() {
  4. return t = Object.assign || function(t2) {
  5. for (var i2, n = 1, s = arguments.length; n < s; n++)
  6. for (var a in i2 = arguments[n])
  7. Object.prototype.hasOwnProperty.call(i2, a) && (t2[a] = i2[a]);
  8. return t2;
  9. }, t.apply(this, arguments);
  10. };
  11. var i = function() {
  12. function i2(i3, n, s) {
  13. var a = this;
  14. this.endVal = n, this.options = s, this.version = "2.6.2", this.defaults = { startVal: 0, decimalPlaces: 0, duration: 2, useEasing: true, useGrouping: true, useIndianSeparators: false, smartEasingThreshold: 999, smartEasingAmount: 333, separator: ",", decimal: ".", prefix: "", suffix: "", enableScrollSpy: false, scrollSpyDelay: 200, scrollSpyOnce: false }, this.finalEndVal = null, this.useEasing = true, this.countDown = false, this.error = "", this.startVal = 0, this.paused = true, this.once = false, this.count = function(t2) {
  15. a.startTime || (a.startTime = t2);
  16. var i4 = t2 - a.startTime;
  17. a.remaining = a.duration - i4, a.useEasing ? a.countDown ? a.frameVal = a.startVal - a.easingFn(i4, 0, a.startVal - a.endVal, a.duration) : a.frameVal = a.easingFn(i4, a.startVal, a.endVal - a.startVal, a.duration) : a.frameVal = a.startVal + (a.endVal - a.startVal) * (i4 / a.duration);
  18. var n2 = a.countDown ? a.frameVal < a.endVal : a.frameVal > a.endVal;
  19. a.frameVal = n2 ? a.endVal : a.frameVal, a.frameVal = Number(a.frameVal.toFixed(a.options.decimalPlaces)), a.printValue(a.frameVal), i4 < a.duration ? a.rAF = requestAnimationFrame(a.count) : null !== a.finalEndVal ? a.update(a.finalEndVal) : a.options.onCompleteCallback && a.options.onCompleteCallback();
  20. }, this.formatNumber = function(t2) {
  21. var i4, n2, s2, e, o = t2 < 0 ? "-" : "";
  22. i4 = Math.abs(t2).toFixed(a.options.decimalPlaces);
  23. var r = (i4 += "").split(".");
  24. if (n2 = r[0], s2 = r.length > 1 ? a.options.decimal + r[1] : "", a.options.useGrouping) {
  25. e = "";
  26. for (var l = 3, h = 0, u = 0, p = n2.length; u < p; ++u)
  27. a.options.useIndianSeparators && 4 === u && (l = 2, h = 1), 0 !== u && h % l == 0 && (e = a.options.separator + e), h++, e = n2[p - u - 1] + e;
  28. n2 = e;
  29. }
  30. return a.options.numerals && a.options.numerals.length && (n2 = n2.replace(/[0-9]/g, function(t3) {
  31. return a.options.numerals[+t3];
  32. }), s2 = s2.replace(/[0-9]/g, function(t3) {
  33. return a.options.numerals[+t3];
  34. })), o + a.options.prefix + n2 + s2 + a.options.suffix;
  35. }, this.easeOutExpo = function(t2, i4, n2, s2) {
  36. return n2 * (1 - Math.pow(2, -10 * t2 / s2)) * 1024 / 1023 + i4;
  37. }, this.options = t(t({}, this.defaults), s), this.formattingFn = this.options.formattingFn ? this.options.formattingFn : this.formatNumber, this.easingFn = this.options.easingFn ? this.options.easingFn : this.easeOutExpo, this.startVal = this.validateValue(this.options.startVal), this.frameVal = this.startVal, this.endVal = this.validateValue(n), this.options.decimalPlaces = Math.max(this.options.decimalPlaces), this.resetDuration(), this.options.separator = String(this.options.separator), this.useEasing = this.options.useEasing, "" === this.options.separator && (this.options.useGrouping = false), this.el = "string" == typeof i3 ? document.getElementById(i3) : i3, this.el ? this.printValue(this.startVal) : this.error = "[CountUp] target is null or undefined", "undefined" != typeof window && this.options.enableScrollSpy && (this.error ? console.error(this.error, i3) : (window.onScrollFns = window.onScrollFns || [], window.onScrollFns.push(function() {
  38. return a.handleScroll(a);
  39. }), window.onscroll = function() {
  40. window.onScrollFns.forEach(function(t2) {
  41. return t2();
  42. });
  43. }, this.handleScroll(this)));
  44. }
  45. return i2.prototype.handleScroll = function(t2) {
  46. if (t2 && window && !t2.once) {
  47. var i3 = window.innerHeight + window.scrollY, n = t2.el.getBoundingClientRect(), s = n.top + window.pageYOffset, a = n.top + n.height + window.pageYOffset;
  48. a < i3 && a > window.scrollY && t2.paused ? (t2.paused = false, setTimeout(function() {
  49. return t2.start();
  50. }, t2.options.scrollSpyDelay), t2.options.scrollSpyOnce && (t2.once = true)) : (window.scrollY > a || s > i3) && !t2.paused && t2.reset();
  51. }
  52. }, i2.prototype.determineDirectionAndSmartEasing = function() {
  53. var t2 = this.finalEndVal ? this.finalEndVal : this.endVal;
  54. this.countDown = this.startVal > t2;
  55. var i3 = t2 - this.startVal;
  56. if (Math.abs(i3) > this.options.smartEasingThreshold && this.options.useEasing) {
  57. this.finalEndVal = t2;
  58. var n = this.countDown ? 1 : -1;
  59. this.endVal = t2 + n * this.options.smartEasingAmount, this.duration = this.duration / 2;
  60. } else
  61. this.endVal = t2, this.finalEndVal = null;
  62. null !== this.finalEndVal ? this.useEasing = false : this.useEasing = this.options.useEasing;
  63. }, i2.prototype.start = function(t2) {
  64. this.error || (t2 && (this.options.onCompleteCallback = t2), this.duration > 0 ? (this.determineDirectionAndSmartEasing(), this.paused = false, this.rAF = requestAnimationFrame(this.count)) : this.printValue(this.endVal));
  65. }, i2.prototype.pauseResume = function() {
  66. this.paused ? (this.startTime = null, this.duration = this.remaining, this.startVal = this.frameVal, this.determineDirectionAndSmartEasing(), this.rAF = requestAnimationFrame(this.count)) : cancelAnimationFrame(this.rAF), this.paused = !this.paused;
  67. }, i2.prototype.reset = function() {
  68. cancelAnimationFrame(this.rAF), this.paused = true, this.resetDuration(), this.startVal = this.validateValue(this.options.startVal), this.frameVal = this.startVal, this.printValue(this.startVal);
  69. }, i2.prototype.update = function(t2) {
  70. cancelAnimationFrame(this.rAF), this.startTime = null, this.endVal = this.validateValue(t2), this.endVal !== this.frameVal && (this.startVal = this.frameVal, null == this.finalEndVal && this.resetDuration(), this.finalEndVal = null, this.determineDirectionAndSmartEasing(), this.rAF = requestAnimationFrame(this.count));
  71. }, i2.prototype.printValue = function(t2) {
  72. var i3;
  73. if (this.el) {
  74. var n = this.formattingFn(t2);
  75. if (null === (i3 = this.options.plugin) || void 0 === i3 ? void 0 : i3.render)
  76. this.options.plugin.render(this.el, n);
  77. else if ("INPUT" === this.el.tagName)
  78. this.el.value = n;
  79. else
  80. "text" === this.el.tagName || "tspan" === this.el.tagName ? this.el.textContent = n : this.el.innerHTML = n;
  81. }
  82. }, i2.prototype.ensureNumber = function(t2) {
  83. return "number" == typeof t2 && !isNaN(t2);
  84. }, i2.prototype.validateValue = function(t2) {
  85. var i3 = Number(t2);
  86. return this.ensureNumber(i3) ? i3 : (this.error = "[CountUp] invalid start or end value: ".concat(t2), null);
  87. }, i2.prototype.resetDuration = function() {
  88. this.startTime = null, this.duration = 1e3 * Number(this.options.duration), this.remaining = this.duration;
  89. }, i2;
  90. }();
  91. export {
  92. i as CountUp
  93. };
  94. //# sourceMappingURL=countup__js.js.map