gsap
Version:
GSAP is a framework-agnostic JavaScript animation library that turns developers into animation superheroes. Build high-performance animations that work in **every** major browser. Animate CSS, SVG, canvas, React, Vue, WebGL, colors, strings, motion paths,
12 lines (10 loc) • 7.78 kB
JavaScript
/*!
* SplitText 3.14.2
* https://gsap.com
*
* @license Copyright 2025, GreenSock. All rights reserved. Subject to the terms at https://gsap.com/standard-license.
* @author: Jack Doyle
*/
(function(W,A){typeof exports=="object"&&typeof module!="undefined"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(W=typeof globalThis!="undefined"?globalThis:W||self,A(W.window=W.window||{}))})(this,function(W){"use strict";let A,I,Z=typeof Symbol=="function"?Symbol():"_split",K,he=()=>K||Y.register(window.gsap),$=typeof Intl!="undefined"&&"Segmenter"in Intl?new Intl.Segmenter:0,q=e=>typeof e=="string"?q(document.querySelectorAll(e)):"length"in e?Array.from(e).reduce((t,i)=>(typeof i=="string"?t.push(...q(i)):t.push(i),t),[]):[e],ee=e=>q(e).filter(t=>t instanceof HTMLElement),Q=[],U=function(){},de={add:e=>e()},pe=/\s+/g,te=new RegExp("\\p{RI}\\p{RI}|\\p{Emoji}(\\p{EMod}|\\u{FE0F}\\u{20E3}?|[\\u{E0020}-\\u{E007E}]+\\u{E007F})?(\\u{200D}\\p{Emoji}(\\p{EMod}|\\u{FE0F}\\u{20E3}?|[\\u{E0020}-\\u{E007E}]+\\u{E007F})?)*|.","gu"),J={left:0,top:0,width:0,height:0},ue=(e,t)=>{for(;++t<e.length&&e[t]===J;);return e[t]||J},ie=({element:e,html:t,ariaL:i,ariaH:n})=>{e.innerHTML=t,i?e.setAttribute("aria-label",i):e.removeAttribute("aria-label"),n?e.setAttribute("aria-hidden",n):e.removeAttribute("aria-hidden")},ne=(e,t)=>{if(t){let i=new Set(e.join("").match(t)||Q),n=e.length,a,c,l,o;if(i.size)for(;--n>-1;){c=e[n];for(l of i)if(l.startsWith(c)&&l.length>c.length){for(a=0,o=c;l.startsWith(o+=e[n+ ++a])&&o.length<l.length;);if(a&&o.length===l.length){e[n]=l,e.splice(n+1,a);break}}}}return e},le=e=>window.getComputedStyle(e).display==="inline"&&(e.style.display="inline-block"),M=(e,t,i)=>t.insertBefore(typeof e=="string"?document.createTextNode(e):e,i),X=(e,t,i)=>{let n=t[e+"sClass"]||"",{tag:a="div",aria:c="auto",propIndex:l=!1}=t,o=e==="line"?"block":"inline-block",d=n.indexOf("++")>-1,R=b=>{let m=document.createElement(a),E=i.length+1;return n&&(m.className=n+(d?" "+n+E:"")),l&&m.style.setProperty("--"+e,E+""),c!=="none"&&m.setAttribute("aria-hidden","true"),a!=="span"&&(m.style.position="relative",m.style.display=o),m.textContent=b,i.push(m),m};return d&&(n=n.replace("++","")),R.collection=i,R},fe=(e,t,i,n)=>{let a=X("line",i,n),c=window.getComputedStyle(e).textAlign||"left";return(l,o)=>{let d=a("");for(d.style.textAlign=c,e.insertBefore(d,t[l]);l<o;l++)d.appendChild(t[l]);d.normalize()}},se=(e,t,i,n,a,c,l,o,d,R)=>{var b;let m=Array.from(e.childNodes),E=0,{wordDelimiter:_,reduceWhiteSpace:B=!0,prepareText:V}=t,G=e.getBoundingClientRect(),O=G,D=!B&&window.getComputedStyle(e).whiteSpace.substring(0,3)==="pre",S=0,x=i.collection,r,f,H,s,g,y,z,h,p,k,C,T,N,L,w,u,F,v;for(typeof _=="object"?(H=_.delimiter||_,f=_.replaceWith||""):f=_===""?"":_||" ",r=f!==" ";E<m.length;E++)if(s=m[E],s.nodeType===3){for(w=s.textContent||"",B?w=w.replace(pe," "):D&&(w=w.replace(/\n/g,f+`
`)),V&&(w=V(w,e)),s.textContent=w,g=f||H?w.split(H||f):w.match(o)||Q,F=g[g.length-1],h=r?F.slice(-1)===" ":!F,F||g.pop(),O=G,z=r?g[0].charAt(0)===" ":!g[0],z&&M(" ",e,s),g[0]||g.shift(),ne(g,d),c&&R||(s.textContent=""),p=1;p<=g.length;p++)if(u=g[p-1],!B&&D&&u.charAt(0)===`
`&&((b=s.previousSibling)==null||b.remove(),M(document.createElement("br"),e,s),u=u.slice(1)),!B&&u==="")M(f,e,s);else if(u===" ")e.insertBefore(document.createTextNode(" "),s);else{if(r&&u.charAt(0)===" "&&M(" ",e,s),S&&p===1&&!z&&x.indexOf(S.parentNode)>-1?(y=x[x.length-1],y.appendChild(document.createTextNode(n?"":u))):(y=i(n?"":u),M(y,e,s),S&&p===1&&!z&&y.insertBefore(S,y.firstChild)),n)for(C=$?ne([...$.segment(u)].map(j=>j.segment),d):u.match(o)||Q,v=0;v<C.length;v++)y.appendChild(C[v]===" "?document.createTextNode(" "):n(C[v]));if(c&&R){if(w=s.textContent=w.substring(u.length+1,w.length),k=y.getBoundingClientRect(),k.top>O.top&&k.left<=O.left){for(T=e.cloneNode(),N=e.childNodes[0];N&&N!==y;)L=N,N=N.nextSibling,T.appendChild(L);e.parentNode.insertBefore(T,e),a&&le(T)}O=k}(p<g.length||h)&&M(p>=g.length?" ":r&&u.slice(-1)===" "?" "+f:f,e,s)}e.removeChild(s),S=0}else s.nodeType===1&&(l&&l.indexOf(s)>-1?(x.indexOf(s.previousSibling)>-1&&x[x.length-1].appendChild(s),S=s):(se(s,t,i,n,a,c,l,o,d,!0),S=0),a&&le(s))};const re=class ae{constructor(t,i){this.isSplit=!1,he(),this.elements=ee(t),this.chars=[],this.words=[],this.lines=[],this.masks=[],this.vars=i,this.elements.forEach(l=>{var o;i.overwrite!==!1&&((o=l[Z])==null||o._data.orig.filter(({element:d})=>d===l).forEach(ie)),l[Z]=this}),this._split=()=>this.isSplit&&this.split(this.vars);let n=[],a,c=()=>{let l=n.length,o;for(;l--;){o=n[l];let d=o.element.offsetWidth;if(d!==o.width){o.width=d,this._split();return}}};this._data={orig:n,obs:typeof ResizeObserver!="undefined"&&new ResizeObserver(()=>{clearTimeout(a),a=setTimeout(c,200)})},U(this),this.split(i)}split(t){return(this._ctx||de).add(()=>{this.isSplit&&this.revert(),this.vars=t=t||this.vars||{};let{type:i="chars,words,lines",aria:n="auto",deepSlice:a=!0,smartWrap:c,onSplit:l,autoSplit:o=!1,specialChars:d,mask:R}=this.vars,b=i.indexOf("lines")>-1,m=i.indexOf("chars")>-1,E=i.indexOf("words")>-1,_=m&&!E&&!b,B=d&&("push"in d?new RegExp("(?:"+d.join("|")+")","gu"):d),V=B?new RegExp(B.source+"|"+te.source,"gu"):te,G=!!t.ignore&&ee(t.ignore),{orig:O,animTime:D,obs:S}=this._data,x;(m||E||b)&&(this.elements.forEach((r,f)=>{O[f]={element:r,html:r.innerHTML,ariaL:r.getAttribute("aria-label"),ariaH:r.getAttribute("aria-hidden")},n==="auto"?r.setAttribute("aria-label",(r.textContent||"").trim()):n==="hidden"&&r.setAttribute("aria-hidden","true");let H=[],s=[],g=[],y=m?X("char",t,H):null,z=X("word",t,s),h,p,k,C;if(se(r,t,z,y,_,a&&(b||_),G,V,B,!1),b){let T=q(r.childNodes),N=fe(r,T,t,g),L,w=[],u=0,F=T.map(P=>P.nodeType===1?P.getBoundingClientRect():J),v=J,j;for(h=0;h<T.length;h++)L=T[h],L.nodeType===1&&(L.nodeName==="BR"?((!h||T[h-1].nodeName!=="BR")&&(w.push(L),N(u,h+1)),u=h+1,v=ue(F,h)):(j=F[h],h&&j.top>v.top&&j.left<v.left+v.width-1&&(N(u,h),u=h),v=j));u<h&&N(u,h),w.forEach(P=>{var oe;return(oe=P.parentNode)==null?void 0:oe.removeChild(P)})}if(!E){for(h=0;h<s.length;h++)if(p=s[h],m||!p.nextSibling||p.nextSibling.nodeType!==3)if(c&&!b){for(k=document.createElement("span"),k.style.whiteSpace="nowrap";p.firstChild;)k.appendChild(p.firstChild);p.replaceWith(k)}else p.replaceWith(...p.childNodes);else C=p.nextSibling,C&&C.nodeType===3&&(C.textContent=(p.textContent||"")+(C.textContent||""),p.remove());s.length=0,r.normalize()}this.lines.push(...g),this.words.push(...s),this.chars.push(...H)}),R&&this[R]&&this.masks.push(...this[R].map(r=>{let f=r.cloneNode();return r.replaceWith(f),f.appendChild(r),r.className&&(f.className=r.className.trim()+"-mask"),f.style.overflow="clip",f}))),this.isSplit=!0,I&&b&&(o?I.addEventListener("loadingdone",this._split):I.status==="loading"&&console.warn("SplitText called before fonts loaded")),(x=l&&l(this))&&x.totalTime&&(this._data.anim=D?x.totalTime(D):x),b&&o&&this.elements.forEach((r,f)=>{O[f].width=r.offsetWidth,S&&S.observe(r)})}),this}kill(){let{obs:t}=this._data;t&&t.disconnect(),I==null||I.removeEventListener("loadingdone",this._split)}revert(){var t,i;if(this.isSplit){let{orig:n,anim:a}=this._data;this.kill(),n.forEach(ie),this.chars.length=this.words.length=this.lines.length=n.length=this.masks.length=0,this.isSplit=!1,a&&(this._data.animTime=a.totalTime(),a.revert()),(i=(t=this.vars).onRevert)==null||i.call(t,this)}return this}static create(t,i){return new ae(t,i)}static register(t){A=A||t||window.gsap,A&&(q=A.utils.toArray,U=A.core.context||U),!K&&window.innerWidth>0&&(I=document.fonts,K=!0)}};re.version="3.14.2";let Y=re;W.SplitText=Y,W.default=Y;if (typeof(window)==="undefined"||window!==W){Object.defineProperty(W,"__esModule",{value:!0})} else {delete W.default}});