!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).SplitType=e()}(this,function(){"use strict";function t(t,e){for(var n=0;nt.length)&&(e=t.length);for(var n=0,r=Array(e);n0&&void 0!==arguments[0]?arguments[0]:{},n=c(e);return void 0!==n.types?t=n.types:void 0!==n.split&&(t=n.split),void 0!==t&&(n.types=(u(t)||f(t)?String(t):"").split(",").map(function(t){return String(t).trim()}).filter(function(t){return/((line)|(word)|(char))/i.test(t)})),(n.absolute||n.position)&&(n.absolute=n.absolute||/absolute/.test(e.position)),n}function h(t){var e=u(t)||f(t)?String(t):"";return{none:!e,lines:/line/i.test(e),words:/word/i.test(e),chars:/char/i.test(e)}}function d(t){return null!==t&&"object"==typeof t}function y(t){return d(t)&&/^(1|3|11)$/.test(t.nodeType)}function v(t){var e,n;return f(t)?t:null==t?[]:d(e=t)&&"number"==typeof(n=e.length)&&n>-1&&n%1==0?Array.prototype.slice.call(t):[t]}function g(t){var e=t;return u(t)&&(e=/^(#[a-z]\w+)$/.test(t.trim())?document.getElementById(t.trim().slice(1)):document.querySelectorAll(t)),v(e).reduce(function(t,e){return[].concat(s(t),s(v(e).filter(y)))},[])}!function(){function t(){for(var t=arguments.length,e=0;e1&&void 0!==arguments[1]?arguments[1]:" ";return(t?String(t):"").trim().replace(/\s+/g," ").split(e)})(f).reduce(function(t,e,n,r){var o,c;return a.chars&&(c=(function(t){var e,n,r,i,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return(t=null==(e=t)?"":String(e))&&u(t)&&!o&&z(t)?z(n=t)?(r=n).match(R)||[]:(i=n).split(""):t.split(o)})(e).map(function(t){var e=F(l,{class:"".concat(i.splitClass," ").concat(i.charClass),style:"display: inline;",children:t});return C(e,"isChar",!0),d=[].concat(s(d),[e]),e})),a.words||a.lines?(C(o=F(l,{class:"".concat(i.wordClass," ").concat(i.splitClass),style:"display: inline; ".concat(a.words&&i.absolute?"position: relative;":""),children:a.chars?c:e}),{isWord:!0,isWordStart:!0,isWordEnd:!0}),p.appendChild(o)):c.forEach(function(t){p.appendChild(t)}),n=k)&&(m=c,g.push($=[])),$.push(t)),a.absolute&&C(t,{top:c,left:u,width:r,height:s}))}),b&&b.removeChild(i),p.lines&&(w=g.map(function(t){var e=F(d,{class:"".concat(a.splitClass," ").concat(a.lineClass),style:"display: block; text-align: ".concat(P,"; width: 100%;")});C(e,"isLine",!0);var n={height:0,top:1e4};return x.appendChild(e),t.forEach(function(t,r,i){var o=_(t),s=o.isWordEnd,a=o.top,l=o.height,c=i[r+1];n.height=Math.max(n.height,l),n.top=Math.min(n.top,a),e.appendChild(t),s&&_(c).isWordStart&&e.append(" ")}),a.absolute&&C(e,{height:n.height,top:n.top}),e}),p.words||function t(e){_(e).isWord?(S(e),e.replaceWith.apply(e,s(e.childNodes))):v(e.children).forEach(function(e){return t(e)})}(x),i.replaceChildren(x)),a.absolute&&(i.style.width="".concat(i.style.width||u,"px"),i.style.height="".concat(c,"px"),v(y).forEach(function(t){var e=_(t),n=e.isLine,r=e.top,i=e.left,o=e.width,s=e.height,a=_(t.parentElement),l=!n&&a.isLine;t.style.top="".concat(l?r-a.top:r,"px"),t.style.left="".concat(n?f.left:i-(l?f.left:0),"px"),t.style.height="".concat(s,"px"),t.style.width="".concat(n?f.width:o,"px"),t.style.position="absolute"})),b&&(E?b.insertBefore(i,E):b.appendChild(i)),w);e.lines=[].concat(s(e.lines),s(N))}}),this.isSplit=!0,window.scrollTo(n[0],n[1]),$(w).forEach(function(t){var e=o(t,2),n=e[0],r=e[1],i=r.isRoot,s=r.isSplit;i&&s||(w[n]=null,delete w[n])}))}},{key:"revert",value:function(){this.isSplit&&(this.lines=null,this.words=null,this.chars=null,this.isSplit=!1),t.revert(this.elements)}},]),t}()});