2501const baseDelay = t_animate__getElementBaseDelay(animatedTextElement);2502let letterIndex = 0;2503let lastLetter = null;25042505particles.forEach(particle => {2506t_animate__setTextParticleDelay(particle, baseDelay + letterIndex * letterDelayIncrement);25072508if (!t_animate__isWhitespaceParticle(particle)) {2509letterIndex++;2510lastLetter = particle;2511}2512
}); if (!lastLetter) { return; } // letters aren't animated with zero duration, so they can be joined right away if (letterDuration === 0) { t_animate__unwrapAnimatedTextLetters(animatedTextElement); return; } // the last letter has the biggest delay, so the whole text is animated when its animation ends const onLastLetterAnimationEnd = event => { // setting delay returns paused animation to the before phase, it fires animationend with zero elapsed time if (event.elapsedTime === 0) { return; } lastLetter.removeEventListener('animationend', onLastLetterAnimationEnd); t_animate__unwrapAnimatedTextLetters(animatedTextElement); }; lastLetter.addEventListener('animationend', onLastLetterAnimationEnd); });}/** * Wrap each word of animated text with a span for specific animation styles * @param {string|null} scopeSelector - optional selector of container, if set, only elements inside it are wrapped */function t_animate__wrapAnimatedTextWords(scopeSelector = null) { const animatedTextElements = t_animate__getAnimatedTextElements([ 'word-fade-in-right', 'word-fade-in-left', 'word-fade-in-down', 'word-fade-in-up', 'line-fade-in-right-gradient', 'line-fade-in-left-gradient', ]).filter(animatedTextElement => !scopeSelector || animatedTextElement.closest(scopeSelector)); animatedTextElements.forEach(animatedTextElement => { t_animate__wrapAnimatedTextElementContentWords(animatedTextElement, false); });}/** * Wrap each word of animated text with a mask wrapper for specific animation styles * @param {string|null} scopeSelector - optional selector of container, if set, only elements inside it are wrapped */function t_animate__wrapAnimatedTextWordsWithMasks(scopeSelector = null) { const animatedTextElements = t_animate__getAnimatedTextElements([ 'word-fade-in-up-masked', 'line-fade-in-up-masked', ]).filter(animatedTextElement => !scopeSelector || animatedTextElement.closest(scopeSelector)); animatedTextElements.forEach(animatedTextElement => { t_animate__wrapAnimatedTextElementContentWords(animatedTextElement, true); });}/** * Wrap each word and then each letter of animated text with a span for letter animation styles. * Letter animations are available only for ZeroBlock elements. */function t_animate__wrapAnimatedTextLetters() { const animatedTextElements = t_animate__getAnimatedTextElements(['letter-bounce-in-up']).filter( animatedTextElement => animatedTextElement.closest('.t396') ); animatedTextElements.forEach(animatedTextElement => { t_animate__wrapAnimatedTextElementContentWords(animatedTextElement, false); const wordElements = animatedTextElement.querySelectorAll( '.t-animate__word:not(.t-animate__word_whitespace):not(.t-animate__word_strict)' ); wordElements.forEach(wordElement => { const letters = t_animate__splitTextIntoLetters(wordElement.textContent); wordElement.textContent = ''; wordElement.appendChild(letters); }); });}/** * Join letters of animated text back into words after animation end. * Browser doesn't shape text across inline-block boundaries, so split letters lose kerning, ligatures