}/** * Split text into strict words with trailing whitespaces and wrap each one by span. * @param {string} text - text to process * @returns {Node} - document fragment with wrapped words */function t_animate__splitTextIntoStrictWords(text) { const whitespaceRegex = /(\s+)/; const fragment = document.createDocumentFragment(); const parts = text .split(whitespaceRegex) .reduce((acc, part) => { const isWhitespace = part.trim().length === 0; if (isWhitespace && acc.length > 0) { acc[acc.length - 1] += part; } else { acc.push(part); } return acc; }, []) // Combine trailing whitespace with the previous word .filter(Boolean); // Filter out empty strings parts.forEach(function (part) { const isWord = part.trim().length > 0; let wordSpan; if (isWord) { wordSpan = t_animate__createStrictWord(part); } else { wordSpan = t_animate__createWhitespaceWord(part); } fragment.appendChild(wordSpan); }); return fragment;}/** * Wrap inner words of an animated text element with a span, processing its child nodes recursively. * @param {Node} node - node to process * @param {boolean} isMasked - whether the words should be wrapped in a mask wrapper * @returns {Node} - document fragment with wrapped content */function t_animate__wrapAnimatedTextElementContentWords(node, isMasked = false) { /** * Wrap inner words of a text node * @param {Text} textNode - text node to process * @param {TextStyleOptions|null} textStyleOptions - inherited text style options from parent * @returns {Node} - document fragment with wrapped words */ function wrapTextNode(textNode, textStyleOptions) { const { verticalAlign = null, textDecoration = null } = textStyleOptions ?? {}; const hasStyleConflict = Boolean(verticalAlign && textDecoration); const text = textNode.textContent; const wrappedText = hasStyleConflict ? t_animate__splitTextIntoStrictWords(text) : t_animate__splitTextIntoWords(text, textDecoration, isMasked); return wrappedText; } /** * Wrap inner words of an element node * @param {Element} elementNode - element node to process * @param {TextStyleOptions|null} textStyleOptions - inherited text style options from parent * @returns {Node} - cloned element with wrapped children */ function wrapElementNode(elementNode, textStyleOptions) { // Clone element preserving all attributes (Quill formatting, classes, etc.) const clone = elementNode.cloneNode(false); // Process children if they exist if (elementNode.childNodes.length > 0) { const wrappedChildren = wrapNode(elementNode, textStyleOptions); clone.appendChild(wrappedChildren); } return clone; } /** * Wrap inner words of a node recursively, preserving text decoration and vertical alignment.