iwmlib/lib/3rdparty/greensock/src/minified/utils/SplitText.min.js

13 lines
9.0 KiB
JavaScript

/*!
* VERSION: 0.7.0
* DATE: 2019-02-07
* UPDATES AND DOCS AT: http://greensock.com
*
* @license Copyright (c) 2008-2019, GreenSock. All rights reserved.
* SplitText is a Club GreenSock membership benefit; You must have a valid membership to use
* this code without violating the terms of use. Visit http://greensock.com/club/ to sign up or get more details.
* This work is subject to the software agreement that was issued with your membership.
*
* @author: Jack Doyle, jack@greensock.com
*/
var _gsScope="undefined"!=typeof module&&module.exports&&"undefined"!=typeof global?global:this||window;!function(a){"use strict";var b=a.GreenSockGlobals||a,c=function(a){var c,d=a.split("."),e=b;for(c=0;c<d.length;c++)e[d[c]]=e=e[d[c]]||{};return e},d=c("com.greensock.utils"),e=function(a){var b=a.nodeType,c="";if(1===b||9===b||11===b){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===b||4===b)return a.nodeValue;return c},f=_gsScope.document||{},g="undefined"!=typeof a?a:f.defaultView||{getComputedStyle:function(){}},h=function(a){return g.getComputedStyle(a)},i=/([A-Z])/g,j=function(a,b,c,d){var e;return(c=c||h(a,null))?(a=c.getPropertyValue(b.replace(i,"-$1").toLowerCase()),e=a||c.length?a:c[b]):a.currentStyle&&(c=a.currentStyle,e=c[b]),d?e:parseInt(e,10)||0},k=function(a){return a.length&&a[0]&&(a[0].nodeType&&a[0].style&&!a.nodeType||a[0].length&&a[0][0])?!0:!1},l=function(a){var b,c,d,e=[],f=a.length;for(b=0;f>b;b++)if(c=a[b],k(c))for(d=c.length,d=0;d<c.length;d++)e.push(c[d]);else e.push(c);return e},m=function(a,b){for(var c,d=b.length;--d>-1;)if(c=b[d],a.substr(0,c.length)===c)return c.length},n=/(?:\r|\n|\t\t)/g,o=/(?:\s\s+)/g,p=55296,q=56319,r=56320,s=127462,t=127487,u=127995,v=127999,w=function(a){return(a.charCodeAt(0)-p<<10)+(a.charCodeAt(1)-r)+65536},x=f.all&&!f.addEventListener,y=" style='position:relative;display:inline-block;"+(x?"*display:inline;*zoom:1;'":"'"),z=function(a,b){a=a||"";var c=-1!==a.indexOf("++"),d=1;return c&&(a=a.split("++").join("")),function(){return"<"+b+y+(a?" class='"+a+(c?d++:"")+"'>":">")}},A=d.SplitText=b.SplitText=function(a,b){if("string"==typeof a&&(a=A.selector(a)),!a)throw"cannot split a null element.";this.elements=k(a)?l(a):[a],this.chars=[],this.words=[],this.lines=[],this._originals=[],this.vars=b||{},this.split(b)},B=function(a,b,c){var d=a.nodeType;if(1===d||9===d||11===d)for(a=a.firstChild;a;a=a.nextSibling)B(a,b,c);else(3===d||4===d)&&(a.nodeValue=a.nodeValue.split(b).join(c))},C=function(a,b){for(var c=b.length;--c>-1;)a.push(b[c])},D=function(a){var b,c=[],d=a.length;for(b=0;b!==d;c.push(a[b++]));return c},E=function(a,b,c){for(var d;a&&a!==b;){if(d=a._next||a.nextSibling)return d.textContent.charAt(0)===c;a=a.parentNode||a._parent}return!1},F=function(a){var b,c,d=D(a.childNodes),e=d.length;for(b=0;e>b;b++)c=d[b],c._isSplit?F(c):(b&&3===c.previousSibling.nodeType?c.previousSibling.nodeValue+=3===c.nodeType?c.nodeValue:c.firstChild.nodeValue:3!==c.nodeType&&a.insertBefore(c.firstChild,c),a.removeChild(c))},G=function(a,b,c,d,e,g,i){var k,l,m,n,o,p,q,r,s,t,u,v,w=h(a),x=j(a,"paddingLeft",w),y=-999,z=j(a,"borderBottomWidth",w)+j(a,"borderTopWidth",w),A=j(a,"borderLeftWidth",w)+j(a,"borderRightWidth",w),D=j(a,"paddingTop",w)+j(a,"paddingBottom",w),G=j(a,"paddingLeft",w)+j(a,"paddingRight",w),H=.2*j(a,"fontSize"),I=j(a,"textAlign",w,!0),J=[],K=[],L=[],M=b.wordDelimiter||" ",N=b.tag?b.tag:b.span?"span":"div",O=b.type||b.split||"chars,words,lines",P=e&&-1!==O.indexOf("lines")?[]:null,Q=-1!==O.indexOf("words"),R=-1!==O.indexOf("chars"),S="absolute"===b.position||b.absolute===!0,T=b.linesClass,U=-1!==(T||"").indexOf("++"),V=[];for(U&&(T=T.split("++").join("")),l=a.getElementsByTagName("*"),m=l.length,o=[],k=0;m>k;k++)o[k]=l[k];if(P||S)for(k=0;m>k;k++)n=o[k],p=n.parentNode===a,(p||S||R&&!Q)&&(v=n.offsetTop,P&&p&&Math.abs(v-y)>H&&("BR"!==n.nodeName||0===k)&&(q=[],P.push(q),y=v),S&&(n._x=n.offsetLeft,n._y=v,n._w=n.offsetWidth,n._h=n.offsetHeight),P&&((n._isSplit&&p||!R&&p||Q&&p||!Q&&n.parentNode.parentNode===a&&!n.parentNode._isSplit)&&(q.push(n),n._x-=x,E(n,a,M)&&(n._wordEnd=!0)),"BR"===n.nodeName&&(n.nextSibling&&"BR"===n.nextSibling.nodeName||0===k)&&P.push([])));for(k=0;m>k;k++)n=o[k],p=n.parentNode===a,"BR"!==n.nodeName?(S&&(s=n.style,Q||p||(n._x+=n.parentNode._x,n._y+=n.parentNode._y),s.left=n._x+"px",s.top=n._y+"px",s.position="absolute",s.display="block",s.width=n._w+1+"px",s.height=n._h+"px"),!Q&&R?n._isSplit?(n._next=n.nextSibling,n.parentNode.appendChild(n)):n.parentNode._isSplit?(n._parent=n.parentNode,!n.previousSibling&&n.firstChild&&(n.firstChild._isFirst=!0),n.nextSibling&&" "===n.nextSibling.textContent&&!n.nextSibling.nextSibling&&V.push(n.nextSibling),n._next=n.nextSibling&&n.nextSibling._isFirst?null:n.nextSibling,n.parentNode.removeChild(n),o.splice(k--,1),m--):p||(v=!n.nextSibling&&E(n.parentNode,a,M),n.parentNode._parent&&n.parentNode._parent.appendChild(n),v&&n.parentNode.appendChild(f.createTextNode(" ")),"span"===N&&(n.style.display="inline"),J.push(n)):n.parentNode._isSplit&&!n._isSplit&&""!==n.innerHTML?K.push(n):R&&!n._isSplit&&("span"===N&&(n.style.display="inline"),J.push(n))):P||S?(n.parentNode&&n.parentNode.removeChild(n),o.splice(k--,1),m--):Q||a.appendChild(n);for(k=V.length;--k>-1;)V[k].parentNode.removeChild(V[k]);if(P){for(S&&(t=f.createElement(N),a.appendChild(t),u=t.offsetWidth+"px",v=t.offsetParent===a?0:a.offsetLeft,a.removeChild(t)),s=a.style.cssText,a.style.cssText="display:none;";a.firstChild;)a.removeChild(a.firstChild);for(r=" "===M&&(!S||!Q&&!R),k=0;k<P.length;k++){for(q=P[k],t=f.createElement(N),t.style.cssText="display:block;text-align:"+I+";position:"+(S?"absolute;":"relative;"),T&&(t.className=T+(U?k+1:"")),L.push(t),m=q.length,l=0;m>l;l++)"BR"!==q[l].nodeName&&(n=q[l],t.appendChild(n),r&&n._wordEnd&&t.appendChild(f.createTextNode(" ")),S&&(0===l&&(t.style.top=n._y+"px",t.style.left=x+v+"px"),n.style.top="0px",v&&(n.style.left=n._x-v+"px")));0===m?t.innerHTML="&nbsp;":Q||R||(F(t),B(t,String.fromCharCode(160)," ")),S&&(t.style.width=u,t.style.height=n._h+"px"),a.appendChild(t)}a.style.cssText=s}S&&(i>a.clientHeight&&(a.style.height=i-D+"px",a.clientHeight<i&&(a.style.height=i+z+"px")),g>a.clientWidth&&(a.style.width=g-G+"px",a.clientWidth<g&&(a.style.width=g+A+"px"))),C(c,J),Q&&C(d,K),C(e,L)},H=function(a,b,c,d){var g,h,i,j,k,l,r,x,y,z,A=b.tag?b.tag:b.span?"span":"div",C=b.type||b.split||"chars,words,lines",D=-1!==C.indexOf("chars"),E="absolute"===b.position||b.absolute===!0,F=b.wordDelimiter||" ",G=" "!==F?"":E?"&#173; ":" ",H="</"+A+">",I=!0,J=b.specialChars?"function"==typeof b.specialChars?b.specialChars:m:null,K=f.createElement("div"),L=a.parentNode;for(L.insertBefore(K,a),K.textContent=a.nodeValue,L.removeChild(a),a=K,g=e(a),r=-1!==g.indexOf("<"),b.reduceWhiteSpace!==!1&&(g=g.replace(o," ").replace(n,"")),r&&(g=g.split("<").join("{{LT}}")),k=g.length,h=(" "===g.charAt(0)?G:"")+c(),i=0;k>i;i++)if(l=g.charAt(i),J&&(z=J(g.substr(i),b.specialChars)))l=g.substr(i,z||1),h+=D&&" "!==l?d()+l+"</"+A+">":l,i+=z-1;else if(l===F&&g.charAt(i-1)!==F&&i){for(h+=I?H:"",I=!1;g.charAt(i+1)===F;)h+=G,i++;i===k-1?h+=G:")"!==g.charAt(i+1)&&(h+=G+c(),I=!0)}else"{"===l&&"{{LT}}"===g.substr(i,6)?(h+=D?d()+"{{LT}}</"+A+">":"{{LT}}",i+=5):l.charCodeAt(0)>=p&&l.charCodeAt(0)<=q||g.charCodeAt(i+1)>=65024&&g.charCodeAt(i+1)<=65039?(x=w(g.substr(i,2)),y=w(g.substr(i+2,2)),j=x>=s&&t>=x&&y>=s&&t>=y||y>=u&&v>=y?4:2,h+=D&&" "!==l?d()+g.substr(i,j)+"</"+A+">":g.substr(i,j),i+=j-1):h+=D&&" "!==l?d()+l+"</"+A+">":l;a.outerHTML=h+(I?H:""),r&&B(L,"{{LT}}","<")},I=function(a,b,c,d){var e,f,g=D(a.childNodes),h=g.length,i="absolute"===b.position||b.absolute===!0;if(3!==a.nodeType||h>1){for(b.absolute=!1,e=0;h>e;e++)f=g[e],(3!==f.nodeType||/\S+/.test(f.nodeValue))&&(i&&3!==f.nodeType&&"inline"===j(f,"display",null,!0)&&(f.style.display="inline-block",f.style.position="relative"),f._isSplit=!0,I(f,b,c,d));return b.absolute=i,void(a._isSplit=!0)}H(a,b,c,d)},J=A.prototype;J.split=function(a){this.isSplit&&this.revert(),this.vars=a=a||this.vars,this._originals.length=this.chars.length=this.words.length=this.lines.length=0;for(var b,c,d,e=this.elements.length,f=a.tag?a.tag:a.span?"span":"div",g=z(a.wordsClass,f),h=z(a.charsClass,f);--e>-1;)d=this.elements[e],this._originals[e]=d.innerHTML,b=d.clientHeight,c=d.clientWidth,I(d,a,g,h),G(d,a,this.chars,this.words,this.lines,c,b);return this.chars.reverse(),this.words.reverse(),this.lines.reverse(),this.isSplit=!0,this},J.revert=function(){if(!this._originals)throw"revert() call wasn't scoped properly.";for(var a=this._originals.length;--a>-1;)this.elements[a].innerHTML=this._originals[a];return this.chars=[],this.words=[],this.lines=[],this.isSplit=!1,this},A.selector=a.$||a.jQuery||function(b){var c=a.$||a.jQuery;return c?(A.selector=c,c(b)):"undefined"==typeof document?b:document.querySelectorAll?document.querySelectorAll(b):document.getElementById("#"===b.charAt(0)?b.substr(1):b)},A.version="0.7.0"}(_gsScope),function(a){"use strict";var b=function(){return(_gsScope.GreenSockGlobals||_gsScope)[a]};"undefined"!=typeof module&&module.exports?module.exports=b():"function"==typeof define&&define.amd&&define([],b)}("SplitText");