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

Class _SplitText

src/SplitText.js:165–329  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163 }
164};
165const _SplitText = class _SplitText {
166 constructor(elements, config) {
167 this.isSplit = false;
168 _initIfNecessary();
169 this.elements = _elements(elements);
170 this.chars = [];
171 this.words = [];
172 this.lines = [];
173 this.masks = [];
174 this.vars = config;
175 this.elements.forEach((el) => {
176 var _a;
177 config.overwrite !== false && ((_a = el[_splitProp]) == null ? void 0 : _a._data.orig.filter(({ element }) => element === el).forEach(_revertOriginal));
178 el[_splitProp] = this;
179 });
180 this._split = () => this.isSplit && this.split(this.vars);
181 let orig = [], timerId, checkWidths = () => {
182 let i = orig.length, o;
183 while (i--) {
184 o = orig[i];
185 let w = o.element.offsetWidth;
186 if (w !== o.width) {
187 o.width = w;
188 this._split();
189 return;
190 }
191 }
192 };
193 this._data = { orig, obs: typeof ResizeObserver !== "undefined" && new ResizeObserver(() => {
194 clearTimeout(timerId);
195 timerId = setTimeout(checkWidths, 200);
196 }) };
197 _context(this);
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") {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…