UNPKG

tatuka-components

Version:
46 lines 2.09 kB
import { calculatePercentage, getRandomNumber } from '../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[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 = getRandomNumber(0, this.animationDelayTimes.length - 1); while (this.randomAnimationTimesMap.has(randomNumber)) { randomNumber = 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 += calculatePercentage(100 - this.options.speed, this.options.symbolAnimationTime); } } }; return TextAnimationCore; }()); export default TextAnimationCore; //# sourceMappingURL=core.js.map