Release 1.0.0-beta18

This commit is contained in:
codecalm
2023-05-14 16:02:06 +02:00
parent 75619ddf72
commit 966d75903d
535 changed files with 50766 additions and 107436 deletions
+8 -3
View File
@@ -3,6 +3,7 @@ export interface CountUpOptions {
decimalPlaces?: number;
duration?: number;
useGrouping?: boolean;
useIndianSeparators?: boolean;
useEasing?: boolean;
smartEasingThreshold?: number;
smartEasingAmount?: number;
@@ -16,22 +17,26 @@ export interface CountUpOptions {
enableScrollSpy?: boolean;
scrollSpyDelay?: number;
scrollSpyOnce?: boolean;
onCompleteCallback?: () => any;
plugin?: CountUpPlugin;
}
export declare interface CountUpPlugin {
render(elem: HTMLElement, formatted: string): void;
}
export declare class CountUp {
private endVal;
options?: CountUpOptions;
version: string;
private defaults;
private el;
private rAF;
private startTime;
private remaining;
private finalEndVal;
private useEasing;
private countDown;
el: HTMLElement | HTMLInputElement;
formattingFn: (num: number) => string;
easingFn?: (t: number, b: number, c: number, d: number) => number;
callback: (args?: any) => any;
error: string;
startVal: number;
duration: number;
@@ -44,7 +49,7 @@ export declare class CountUp {
* Smart easing works by breaking the animation into 2 parts, the second part being the
* smartEasingAmount and first part being the total amount minus the smartEasingAmount. It works
* by disabling easing for the first part and enabling it on the second part. It is used if
* usingEasing is true and the total animation amount exceeds the smartEasingThreshold.
* useEasing is true and the total animation amount exceeds the smartEasingThreshold.
*/
private determineDirectionAndSmartEasing;
start(callback?: (args?: any) => any): void;
+26 -8
View File
@@ -15,13 +15,14 @@ var CountUp = /** @class */ (function () {
var _this = this;
this.endVal = endVal;
this.options = options;
this.version = '2.3.2';
this.version = '2.6.2';
this.defaults = {
startVal: 0,
decimalPlaces: 0,
duration: 2,
useEasing: true,
useGrouping: true,
useIndianSeparators: false,
smartEasingThreshold: 999,
smartEasingAmount: 333,
separator: ',',
@@ -73,8 +74,8 @@ var CountUp = /** @class */ (function () {
_this.update(_this.finalEndVal);
}
else {
if (_this.callback) {
_this.callback();
if (_this.options.onCompleteCallback) {
_this.options.onCompleteCallback();
}
}
};
@@ -89,10 +90,16 @@ var CountUp = /** @class */ (function () {
x2 = x.length > 1 ? _this.options.decimal + x[1] : '';
if (_this.options.useGrouping) {
x3 = '';
var factor = 3, j = 0;
for (var i = 0, len = x1.length; i < len; ++i) {
if (i !== 0 && (i % 3) === 0) {
if (_this.options.useIndianSeparators && i === 4) {
factor = 2;
j = 1;
}
if (i !== 0 && (j % factor) === 0) {
x3 = _this.options.separator + x3;
}
j++;
x3 = x1[len - i - 1] + x3;
}
x1 = x3;
@@ -151,6 +158,7 @@ var CountUp = /** @class */ (function () {
return;
var bottomOfScroll = window.innerHeight + window.scrollY;
var rect = self.el.getBoundingClientRect();
var topOfEl = rect.top + window.pageYOffset;
var bottomOfEl = rect.top + rect.height + window.pageYOffset;
if (bottomOfEl < bottomOfScroll && bottomOfEl > window.scrollY && self.paused) {
// in view
@@ -159,8 +167,9 @@ var CountUp = /** @class */ (function () {
if (self.options.scrollSpyOnce)
self.once = true;
}
else if (window.scrollY > bottomOfEl && !self.paused) {
// scrolled past
else if ((window.scrollY > bottomOfEl || topOfEl > bottomOfScroll) &&
!self.paused) {
// out of view
self.reset();
}
};
@@ -168,7 +177,7 @@ var CountUp = /** @class */ (function () {
* Smart easing works by breaking the animation into 2 parts, the second part being the
* smartEasingAmount and first part being the total amount minus the smartEasingAmount. It works
* by disabling easing for the first part and enabling it on the second part. It is used if
* usingEasing is true and the total animation amount exceeds the smartEasingThreshold.
* useEasing is true and the total animation amount exceeds the smartEasingThreshold.
*/
CountUp.prototype.determineDirectionAndSmartEasing = function () {
var end = (this.finalEndVal) ? this.finalEndVal : this.endVal;
@@ -197,7 +206,9 @@ var CountUp = /** @class */ (function () {
if (this.error) {
return;
}
this.callback = callback;
if (callback) {
this.options.onCompleteCallback = callback;
}
if (this.duration > 0) {
this.determineDirectionAndSmartEasing();
this.paused = false;
@@ -247,7 +258,14 @@ var CountUp = /** @class */ (function () {
this.rAF = requestAnimationFrame(this.count);
};
CountUp.prototype.printValue = function (val) {
var _a;
if (!this.el)
return;
var result = this.formattingFn(val);
if ((_a = this.options.plugin) === null || _a === void 0 ? void 0 : _a.render) {
this.options.plugin.render(this.el, result);
return;
}
if (this.el.tagName === 'INPUT') {
var input = this.el;
input.value = result;
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,26 @@
// make sure requestAnimationFrame and cancelAnimationFrame are defined
// polyfill for browsers without native support
// by Opera engineer Erik Möller
(function () {
var lastTime = 0;
var vendors = ['webkit', 'moz', 'ms', 'o'];
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] ||
window[vendors[x] + 'CancelRequestAnimationFrame'];
}
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = function (callback) {
var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
var id = window.setTimeout(function () { return callback(currTime + timeToCall); }, timeToCall);
lastTime = currTime + timeToCall;
return id;
};
}
if (!window.cancelAnimationFrame) {
window.cancelAnimationFrame = function (id) {
clearTimeout(id);
};
}
})();