2801}28022803/**2804* Create letter span for letter animation2805* @param {string} text - text content for the span2806* @returns {HTMLSpanElement}2807*/2808function t_animate__createLetter(text) {2809const span = document.createElement('span');2810span.className = 't-animate__letter';2811span.textContent = text;2812
return span;}/** * Get shared grapheme segmenter, it is created once on first call * @returns {Intl.Segmenter|null} - segmenter or null if Intl.Segmenter is not supported */function t_animate__getGraphemeSegmenter() { if (t_animate__getGraphemeSegmenter.segmenter === undefined) { const isSegmenterSupported = typeof Intl !== 'undefined' && typeof Intl.Segmenter === 'function'; t_animate__getGraphemeSegmenter.segmenter = isSegmenterSupported ? new Intl.Segmenter(undefined, { granularity: 'grapheme' }) : null; } return t_animate__getGraphemeSegmenter.segmenter;}/** * Split text into letters (grapheme clusters). * Text of connected and complex shaped scripts (Arabic, Syriac, Mongolian, Indic, etc.) is not split, * because browser does not shape text across inline-block boundaries and letters lose their joining forms and ligatures. * Without Intl.Segmenter text with surrogate pairs, joiners, variation selectors or combining marks * is not split, because splitting by code points breaks emoji and accented letters. * @param {string} text - text to split * @returns {string[]} - array of letters */function t_animate__getTextLetters(text) { const connectedScriptRegex = /[\u0600-\u06FF\u0700-\u074F\u0750-\u077F\u07C0-\u07FF\u0840-\u085F\u08A0-\u08FF\u0900-\u0DFF\u1800-\u18AF\uFB50-\uFDFF\uFE70-\uFEFF]/; if (connectedScriptRegex.test(text)) { return [text]; } const segmenter = t_animate__getGraphemeSegmenter(); if (segmenter) { return Array.from(segmenter.segment(text), segment => segment.segment); } const complexCharRegex = /[\uD800-\uDFFF\u200C\u200D\uFE00-\uFE0F\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF]/; return complexCharRegex.test(text) ? [text] : text.split('');}/** * Split text into letters and wrap each one by span * @param {string} text - text to process * @returns {Node} - document fragment with wrapped letters */function t_animate__splitTextIntoLetters(text) { const fragment = document.createDocumentFragment(); t_animate__getTextLetters(text).forEach(letter => { fragment.appendChild(t_animate__createLetter(letter)); }); return fragment;}/** * Create line span for line animation * @returns {HTMLSpanElement} */function t_animate__createLine() { const line = document.createElement('span'); line.className = 't-animate__line'; return line;}/** * Split text into words and wrap each one by span, preserving whitespace and text decoration * @param {string} text - text to process * @param {TextDecoration|null} textDecoration - inherited text decoration from parent * @param {boolean} isMasked - whether the words should be wrapped in a mask wrapper * @returns {Node} - document fragment with wrapped words */function t_animate__splitTextIntoWords(text, textDecoration, isMasked = false) { const whitespaceRegex = /(\s+)/; const fragment = document.createDocumentFragment(); const parts = text.split(whitespaceRegex).filter(Boolean); // Filter out empty strings parts.forEach(function (part) { const isWord = part.trim().length > 0;