2301return Array.from(elements);2302}23032304const elementAnimationStyle = element.getAttribute('data-animate-style');2305const isStyleAppropriate = animationStyles.includes(elementAnimationStyle);23062307return isStyleAppropriate ? [element] : [];2308}23092310/**2311* Prepare word by word animation to the right.2312* Add animation delay for each word by increment
* @param {HTMLElement|null} element - optional specific element to prepare, if null, prepares all elements with the specified animation styles */function t_animate__prepareWordByWordAnimationToRight(element = null) { const wordDelayIncrement = 0.06; const animatedTextElements = t_animate__getAnimatedTextElements( ['word-fade-in-right', 'word-fade-in-up', 'word-fade-in-up-masked', 'word-fade-in-down'], element ); animatedTextElements.forEach(animatedTextElement => { const wordElements = animatedTextElement.querySelectorAll('.t-animate__word'); const baseDelay = t_animate__getElementBaseDelay(animatedTextElement); let wordIndex = 0; wordElements.forEach(wordElement => { t_animate__setTextParticleDelay(wordElement, baseDelay + wordIndex * wordDelayIncrement); if (!t_animate__isWhitespaceParticle(wordElement)) { wordIndex++; } }); });}/** * Get the root element and tree path of inline parents for a given text node. * @param {Node} node - text node to process * @param {Node[]} path - array of inline parent nodes leading to the root * @returns {{ root: Node, path: Node[] }} - root element and path of inline parents */function t_animate__getTreePath(node, path = []) { const parent = node.parentElement; if (!parent || parent === node) { return { root: node, path, }; } const parentStyles = window.getComputedStyle(parent); const isParentInline = parentStyles.display.includes('inline'); return isParentInline ? t_animate__getTreePath(parent, [parent, ...path]) : { root: parent, path, };}/** * Get lines of words from element. * @param {HTMLElement} element - element to get lines from * @returns {HTMLElement[][]} - array of lines, each line is an array of word elements */function t_animate__getElementLines(element) { const wordElements = element.querySelectorAll('.t-animate__word'); const lines = Array.from(wordElements) .reduce((acc, wordElement) => { const { root } = t_animate__getTreePath(wordElement); const wordTop = Math.round(wordElement.offsetTop + (wordElement.offsetParent?.offsetTop ?? 0)); const currentLine = acc.at(-1); const isWhitespace = wordElement.classList.contains('t-animate__word_whitespace'); if (currentLine && currentLine.root === root && Math.abs(wordTop - currentLine.top) < currentLine.height) { currentLine.words.push(wordElement); if (currentLine.isTopUpdateNeeded && !isWhitespace) { currentLine.isTopUpdateNeeded = false; currentLine.top = wordTop; } } else { const lineHeight = window.getComputedStyle(wordElement).lineHeight; const lineHeightParsedValue = parseFloat(lineHeight); const lineHeightNumberValue = isNaN(lineHeightParsedValue) ? wordElement.getBoundingClientRect().height : lineHeightParsedValue; acc.push({ root, top: wordTop, height: lineHeightNumberValue, words: [wordElement], isTopUpdateNeeded: isWhitespace, }); }