-
Notifications
You must be signed in to change notification settings - Fork 0
/
WrapChars.min.js
1 lines (1 loc) · 2.55 KB
/
WrapChars.min.js
1
"use strict";function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,r){if(e){if("string"==typeof e)return _arrayLikeToArray(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Map"===(t="Object"===t&&e.constructor?e.constructor.name:t)||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(e,r):void 0}}function _iterableToArray(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _arrayLikeToArray(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,a=new Array(r);t<r;t++)a[t]=e[t];return a}function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var a=r[t];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}var WrapChars=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"wrap",value:function(e){var r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},l=r.split||r.type||"letter",s=r.tagName||"span",c=r.className,p=function(e){var r;if(e)return(r=document.createElement("span")).innerHTML=e,r.textContent}(r.spaceChar),o=!r.hasOwnProperty("deep")||r.deep,i=r.skipClass,u=!!r.hasOwnProperty("wrapSpaces")&&r.wrapSpaces;function y(e){var r=e.split("word"===l?" ":""),t="";if("word"===l)for(var a=r.length;1<a;a--)r.splice(a-1,0," ");for(var n=0;n<r.length;n++){var o=" "===r[n]&&p?p:r[n],i="";u||" "!==o&&o!==p?o.length&&(i+="<".concat(s),c&&"string"==typeof c&&c.length&&(i+=' class="'.concat(c,'"')),i+=">"+o+"</".concat(s,">")):i+=p||" ",t+=i}return t}!function e(r){var t,a;switch(r.nodeType){case 1:if(i&&r.classList.contains(i))break;for(var n=(t=r.childNodes).length;0<n;n--)!o&&3!==t[n-1].nodeType||e(t[n-1]);break;case 3:if(!(a=r.textContent).replace(/\s\s+/g,"").length)break;a=a.replace(/\s\s+/g," "),(t=document.createElement("span")).innerHTML=y(a),r.replaceWith.apply(r,_toConsumableArray(t.childNodes))}}(e)}}]),e}();