MCPcopy
hub / github.com/greensock/GSAP / _splitWordsAndCharsRecursively

Function _splitWordsAndCharsRecursively

esm/SplitText.js:72–164  ·  view source on GitHub ↗
(element, config, wordWrapper, charWrapper, prepForCharsOnly, deepSlice, ignore, charSplitRegEx, specialCharsRegEx, isNested)

Source from the content-addressed store, hash-verified

70 newLine.normalize();
71 };
72}, _splitWordsAndCharsRecursively = (element, config, wordWrapper, charWrapper, prepForCharsOnly, deepSlice, ignore, charSplitRegEx, specialCharsRegEx, isNested) => {
73 var _a;
74 let nodes = Array.from(element.childNodes), i = 0, { wordDelimiter, reduceWhiteSpace = true, prepareText } = config, elementBounds = element.getBoundingClientRect(), lastBounds = elementBounds, isPreformatted = !reduceWhiteSpace && window.getComputedStyle(element).whiteSpace.substring(0, 3) === "pre", ignoredPreviousSibling = 0, wordsCollection = wordWrapper.collection, wordDelimIsNotSpace, wordDelimString, wordDelimSplitter, curNode, words, curWordEl, startsWithSpace, endsWithSpace, j, bounds, curWordChars, clonedNode, curSubNode, tempSubNode, curTextContent, wordText, lastWordText, k;
75 if (typeof wordDelimiter === "object") {
76 wordDelimSplitter = wordDelimiter.delimiter || wordDelimiter;
77 wordDelimString = wordDelimiter.replaceWith || "";
78 } else {
79 wordDelimString = wordDelimiter === "" ? "" : wordDelimiter || " ";
80 }
81 wordDelimIsNotSpace = wordDelimString !== " ";
82 for (; i < nodes.length; i++) {
83 curNode = nodes[i];
84 if (curNode.nodeType === 3) {
85 curTextContent = curNode.textContent || "";
86 if (reduceWhiteSpace) {
87 curTextContent = curTextContent.replace(_spacesRegEx, " ");
88 } else if (isPreformatted) {
89 curTextContent = curTextContent.replace(/\n/g, wordDelimString + "\n");
90 }
91 prepareText && (curTextContent = prepareText(curTextContent, element));
92 curNode.textContent = curTextContent;
93 words = wordDelimString || wordDelimSplitter ? curTextContent.split(wordDelimSplitter || wordDelimString) : curTextContent.match(charSplitRegEx) || _emptyArray;
94 lastWordText = words[words.length - 1];
95 endsWithSpace = wordDelimIsNotSpace ? lastWordText.slice(-1) === " " : !lastWordText;
96 lastWordText || words.pop();
97 lastBounds = elementBounds;
98 startsWithSpace = wordDelimIsNotSpace ? words[0].charAt(0) === " " : !words[0];
99 startsWithSpace && _insertNodeBefore(" ", element, curNode);
100 words[0] || words.shift();
101 _stretchToFitSpecialChars(words, specialCharsRegEx);
102 deepSlice && isNested || (curNode.textContent = "");
103 for (j = 1; j <= words.length; j++) {
104 wordText = words[j - 1];
105 if (!reduceWhiteSpace && isPreformatted && wordText.charAt(0) === "\n") {
106 (_a = curNode.previousSibling) == null ? void 0 : _a.remove();
107 _insertNodeBefore(document.createElement("br"), element, curNode);
108 wordText = wordText.slice(1);
109 }
110 if (!reduceWhiteSpace && wordText === "") {
111 _insertNodeBefore(wordDelimString, element, curNode);
112 } else if (wordText === " ") {
113 element.insertBefore(document.createTextNode(" "), curNode);
114 } else {
115 wordDelimIsNotSpace && wordText.charAt(0) === " " && _insertNodeBefore(" ", element, curNode);
116 if (ignoredPreviousSibling && j === 1 && !startsWithSpace && wordsCollection.indexOf(ignoredPreviousSibling.parentNode) > -1) {
117 curWordEl = wordsCollection[wordsCollection.length - 1];
118 curWordEl.appendChild(document.createTextNode(charWrapper ? "" : wordText));
119 } else {
120 curWordEl = wordWrapper(charWrapper ? "" : wordText);
121 _insertNodeBefore(curWordEl, element, curNode);
122 ignoredPreviousSibling && j === 1 && !startsWithSpace && curWordEl.insertBefore(ignoredPreviousSibling, curWordEl.firstChild);
123 }
124 if (charWrapper) {
125 curWordChars = _charSegmenter ? _stretchToFitSpecialChars([..._charSegmenter.segment(wordText)].map((s) => s.segment), specialCharsRegEx) : wordText.match(charSplitRegEx) || _emptyArray;
126 for (k = 0; k < curWordChars.length; k++) {
127 curWordEl.appendChild(curWordChars[k] === " " ? document.createTextNode(" ") : charWrapper(curWordChars[k]));
128 }
129 }

Callers 1

splitMethod · 0.70

Calls 7

getBoundingClientRectMethod · 0.80
_insertNodeBeforeFunction · 0.70
_disallowInlineFunction · 0.70
removeMethod · 0.65
fromMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…