(config)
| 198 | this.split(config); |
| 199 | } |
| 200 | split(config) { |
| 201 | (this._ctx || _defaultContext).add(() => { |
| 202 | this.isSplit && this.revert(); |
| 203 | this.vars = config = config || this.vars || {}; |
| 204 | let { type = "chars,words,lines", aria = "auto", deepSlice = true, smartWrap, onSplit, autoSplit = false, specialChars, mask } = this.vars, splitLines = type.indexOf("lines") > -1, splitCharacters = type.indexOf("chars") > -1, splitWords = type.indexOf("words") > -1, onlySplitCharacters = splitCharacters && !splitWords && !splitLines, specialCharsRegEx = specialChars && ("push" in specialChars ? new RegExp("(?:" + specialChars.join("|") + ")", "gu") : specialChars), finalCharSplitRegEx = specialCharsRegEx ? new RegExp(specialCharsRegEx.source + "|" + _emojiSafeRegEx.source, "gu") : _emojiSafeRegEx, ignore = !!config.ignore && _elements(config.ignore), { orig, animTime, obs } = this._data, onSplitResult; |
| 205 | if (splitCharacters || splitWords || splitLines) { |
| 206 | this.elements.forEach((element, index) => { |
| 207 | orig[index] = { |
| 208 | element, |
| 209 | html: element.innerHTML, |
| 210 | ariaL: element.getAttribute("aria-label"), |
| 211 | ariaH: element.getAttribute("aria-hidden") |
| 212 | }; |
| 213 | aria === "auto" ? element.setAttribute("aria-label", (element.textContent || "").trim()) : aria === "hidden" && element.setAttribute("aria-hidden", "true"); |
| 214 | let chars = [], words = [], lines = [], charWrapper = splitCharacters ? _getWrapper("char", config, chars) : null, wordWrapper = _getWrapper("word", config, words), i, curWord, smartWrapSpan, nextSibling; |
| 215 | _splitWordsAndCharsRecursively(element, config, wordWrapper, charWrapper, onlySplitCharacters, deepSlice && (splitLines || onlySplitCharacters), ignore, finalCharSplitRegEx, specialCharsRegEx, false); |
| 216 | if (splitLines) { |
| 217 | let nodes = _toArray(element.childNodes), wrapLine = _getLineWrapper(element, nodes, config, lines), curNode, toRemove = [], lineStartIndex = 0, allBounds = nodes.map((n) => n.nodeType === 1 ? n.getBoundingClientRect() : _emptyBounds), lastBounds = _emptyBounds, curBounds; |
| 218 | for (i = 0; i < nodes.length; i++) { |
| 219 | curNode = nodes[i]; |
| 220 | if (curNode.nodeType === 1) { |
| 221 | if (curNode.nodeName === "BR") { |
| 222 | if (!i || nodes[i - 1].nodeName !== "BR") { |
| 223 | toRemove.push(curNode); |
| 224 | wrapLine(lineStartIndex, i + 1); |
| 225 | } |
| 226 | lineStartIndex = i + 1; |
| 227 | lastBounds = _findNextValidBounds(allBounds, i); |
| 228 | } else { |
| 229 | curBounds = allBounds[i]; |
| 230 | if (i && curBounds.top > lastBounds.top && curBounds.left < lastBounds.left + lastBounds.width - 1) { |
| 231 | wrapLine(lineStartIndex, i); |
| 232 | lineStartIndex = i; |
| 233 | } |
| 234 | lastBounds = curBounds; |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | lineStartIndex < i && wrapLine(lineStartIndex, i); |
| 239 | toRemove.forEach((el) => { |
| 240 | var _a; |
| 241 | return (_a = el.parentNode) == null ? void 0 : _a.removeChild(el); |
| 242 | }); |
| 243 | } |
| 244 | if (!splitWords) { |
| 245 | for (i = 0; i < words.length; i++) { |
| 246 | curWord = words[i]; |
| 247 | if (splitCharacters || !curWord.nextSibling || curWord.nextSibling.nodeType !== 3) { |
| 248 | if (smartWrap && !splitLines) { |
| 249 | smartWrapSpan = document.createElement("span"); |
| 250 | smartWrapSpan.style.whiteSpace = "nowrap"; |
| 251 | while (curWord.firstChild) { |
| 252 | smartWrapSpan.appendChild(curWord.firstChild); |
| 253 | } |
| 254 | curWord.replaceWith(smartWrapSpan); |
| 255 | } else { |
| 256 | curWord.replaceWith(...curWord.childNodes); |
| 257 | } |
no test coverage detected