tatuka-components
Version:
this is a readme text
48 lines • 2.18 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var math_1 = require("../utils/math");
var TextAnimationCore = /** @class */ (function () {
function TextAnimationCore(text, options) {
this.text = text;
this.options = options;
this.animationDelayTimes = [];
this.randomAnimationTimesMap = new Map();
this.colors = [];
this.init();
}
TextAnimationCore.prototype.init = function () {
this.generateAnimationDelayTimes();
};
TextAnimationCore.prototype.getColor = function () {
return this.options.colors[(0, math_1.getRandomNumber)(0, this.options.colors.length - 1)];
};
TextAnimationCore.prototype.getAnimationDelay = function (animationDelayIndex) {
var animationDelay = 0;
if (this.options.style === 'domino' || this.options.style === 'dance' || this.options.style === 'loading') {
animationDelay = this.animationDelayTimes[animationDelayIndex];
}
if (this.options.style === 'random') {
var randomNumber = (0, math_1.getRandomNumber)(0, this.animationDelayTimes.length - 1);
while (this.randomAnimationTimesMap.has(randomNumber)) {
randomNumber = (0, math_1.getRandomNumber)(0, this.animationDelayTimes.length - 1);
}
this.randomAnimationTimesMap.set(randomNumber, randomNumber);
animationDelay = this.animationDelayTimes[randomNumber];
}
return animationDelay;
};
TextAnimationCore.prototype.generateAnimationDelayTimes = function () {
var animationDelayTime = 0;
for (var i = 0; i < this.text.length; i++) {
if (this.text[i] !== ' ') {
this.options.reverse
? this.animationDelayTimes.unshift(animationDelayTime)
: this.animationDelayTimes.push(animationDelayTime);
animationDelayTime += (0, math_1.calculatePercentage)(100 - this.options.speed, this.options.symbolAnimationTime);
}
}
};
return TextAnimationCore;
}());
exports.default = TextAnimationCore;
//# sourceMappingURL=core.js.map