Comparing version 5.10.1 to 5.10.2
@@ -5,3 +5,3 @@ /*! | ||
* Author: Alex MacArthur <alex@macarthur.me> (https://macarthur.me) | ||
* Version: v5.10.1 | ||
* Version: v5.10.2 | ||
* URL: https://typeitjs.com | ||
@@ -126,2 +126,26 @@ * License: GPL-2.0 | ||
var inherits = function (subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; | ||
}; | ||
var possibleConstructorReturn = function (self, call) { | ||
if (!self) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return call && (typeof call === "object" || typeof call === "function") ? call : self; | ||
}; | ||
var Instance = function () { | ||
@@ -131,6 +155,7 @@ function Instance(element, id, options, autoInit, typeit) { | ||
this.id = id; | ||
this.typeit = typeit; | ||
this.autoInit = autoInit; | ||
this.element = element; | ||
this.timeouts = []; | ||
this.id = id; | ||
this.autoInit = autoInit; | ||
this.hasStarted = false; | ||
@@ -144,3 +169,2 @@ this.isFrozen = false; | ||
this.style = "display:inline;position:relative;font:inherit;color:inherit;"; | ||
this.element = element; | ||
this.setOptions(options, window.TypeItDefaults, false); | ||
@@ -150,10 +174,6 @@ this.prepareTargetElement(); | ||
this.prepareDelay("loopDelay"); | ||
if (!this.prepareStrings()) { | ||
return; | ||
} | ||
this.prepareDOM(); | ||
this.prepareStrings(); | ||
if (this.options.startDelete) { | ||
if (this.options.startDelete && this.stringsToDelete) { | ||
this.insert(this.stringsToDelete); | ||
@@ -166,2 +186,5 @@ this.queue.push([this.delete]); | ||
//-- We have no strings! So, don't do anything. | ||
if (!this.options.strings.length || !this.options.strings[0]) return; | ||
if (this.autoInit) { | ||
@@ -180,11 +203,3 @@ this.init(); | ||
value: function prepareStrings() { | ||
this.options.strings = toArray(this.options.strings); | ||
this.options.strings = removeComments(this.options.strings); | ||
//-- We don't have anything. Get out of here. | ||
if (this.options.strings.length >= 1 && this.options.strings[0] === "") { | ||
return false; | ||
} | ||
return true; | ||
this.options.strings = removeComments(toArray(this.options.strings)); | ||
} | ||
@@ -312,7 +327,6 @@ | ||
if (rake) { | ||
string = this.rake(string); | ||
string = string[0]; | ||
string = this.rake(string)[0]; | ||
} | ||
//-- @todo Improve this check by using regex. | ||
//-- @todo Improve this check by using regex (rather than startsWith() checks). | ||
//-- If an opening HTML tag is found and we're not already printing inside a tag | ||
@@ -720,6 +734,6 @@ if (this.options.html && startsWith(string[0], "<") && !startsWith(string[0], "</")) { | ||
var TypeIt = function () { | ||
function TypeIt(element, args) { | ||
var Core = function () { | ||
function Core(element, args) { | ||
var autoInit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; | ||
classCallCheck(this, TypeIt); | ||
classCallCheck(this, Core); | ||
@@ -750,3 +764,3 @@ this.id = generateHash(); | ||
createClass(TypeIt, [{ | ||
createClass(Core, [{ | ||
key: "generateInstances", | ||
@@ -774,2 +788,4 @@ value: function generateInstances() { | ||
this.init(true); | ||
this.instances.forEach(function (instance) { | ||
@@ -781,5 +797,24 @@ instance.queue.push([instance[action], argument]); | ||
} | ||
//-- We KNOW we have items to process now, so make sure we set this to false. | ||
instance.isComplete = false; | ||
}); | ||
} | ||
}]); | ||
return Core; | ||
}(); | ||
var TypeIt = function (_Core) { | ||
inherits(TypeIt, _Core); | ||
function TypeIt(element, args) { | ||
var autoInit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; | ||
classCallCheck(this, TypeIt); | ||
return possibleConstructorReturn(this, (TypeIt.__proto__ || Object.getPrototypeOf(TypeIt)).call(this, element, args, autoInit)); | ||
} | ||
createClass(TypeIt, [{ | ||
key: "type", | ||
/** | ||
@@ -791,8 +826,7 @@ * If used after typing has started, will append strings to the end of the existing queue. If used when typing is paused, will restart it. | ||
*/ | ||
}, { | ||
key: "type", | ||
value: function type() { | ||
var string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; | ||
this.init(true); | ||
this.instances.forEach(function (instance) { | ||
@@ -805,2 +839,5 @@ //-- Queue up a string right off the bat. | ||
} | ||
//-- We KNOW we have items to process now, so make sure we set this to false. | ||
instance.isComplete = false; | ||
}); | ||
@@ -903,4 +940,13 @@ | ||
value: function init() { | ||
var requireAutoInit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
this.instances.forEach(function (instance) { | ||
instance.init(); | ||
if (!requireAutoInit) { | ||
instance.init(); | ||
return; | ||
} | ||
if (instance.autoInit) { | ||
instance.init(); | ||
} | ||
}); | ||
@@ -938,4 +984,4 @@ } | ||
return TypeIt; | ||
}(); | ||
}(Core); | ||
export default TypeIt; |
@@ -5,3 +5,3 @@ /*! | ||
* Author: Alex MacArthur <alex@macarthur.me> (https://macarthur.me) | ||
* Version: v5.10.1 | ||
* Version: v5.10.2 | ||
* URL: https://typeitjs.com | ||
@@ -132,2 +132,26 @@ * License: GPL-2.0 | ||
var inherits = function (subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; | ||
}; | ||
var possibleConstructorReturn = function (self, call) { | ||
if (!self) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return call && (typeof call === "object" || typeof call === "function") ? call : self; | ||
}; | ||
var Instance = function () { | ||
@@ -137,6 +161,7 @@ function Instance(element, id, options, autoInit, typeit) { | ||
this.id = id; | ||
this.typeit = typeit; | ||
this.autoInit = autoInit; | ||
this.element = element; | ||
this.timeouts = []; | ||
this.id = id; | ||
this.autoInit = autoInit; | ||
this.hasStarted = false; | ||
@@ -150,3 +175,2 @@ this.isFrozen = false; | ||
this.style = "display:inline;position:relative;font:inherit;color:inherit;"; | ||
this.element = element; | ||
this.setOptions(options, window.TypeItDefaults, false); | ||
@@ -156,10 +180,6 @@ this.prepareTargetElement(); | ||
this.prepareDelay("loopDelay"); | ||
if (!this.prepareStrings()) { | ||
return; | ||
} | ||
this.prepareDOM(); | ||
this.prepareStrings(); | ||
if (this.options.startDelete) { | ||
if (this.options.startDelete && this.stringsToDelete) { | ||
this.insert(this.stringsToDelete); | ||
@@ -172,2 +192,5 @@ this.queue.push([this.delete]); | ||
//-- We have no strings! So, don't do anything. | ||
if (!this.options.strings.length || !this.options.strings[0]) return; | ||
if (this.autoInit) { | ||
@@ -186,11 +209,3 @@ this.init(); | ||
value: function prepareStrings() { | ||
this.options.strings = toArray(this.options.strings); | ||
this.options.strings = removeComments(this.options.strings); | ||
//-- We don't have anything. Get out of here. | ||
if (this.options.strings.length >= 1 && this.options.strings[0] === "") { | ||
return false; | ||
} | ||
return true; | ||
this.options.strings = removeComments(toArray(this.options.strings)); | ||
} | ||
@@ -318,7 +333,6 @@ | ||
if (rake) { | ||
string = this.rake(string); | ||
string = string[0]; | ||
string = this.rake(string)[0]; | ||
} | ||
//-- @todo Improve this check by using regex. | ||
//-- @todo Improve this check by using regex (rather than startsWith() checks). | ||
//-- If an opening HTML tag is found and we're not already printing inside a tag | ||
@@ -726,6 +740,6 @@ if (this.options.html && startsWith(string[0], "<") && !startsWith(string[0], "</")) { | ||
var TypeIt = function () { | ||
function TypeIt(element, args) { | ||
var Core = function () { | ||
function Core(element, args) { | ||
var autoInit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; | ||
classCallCheck(this, TypeIt); | ||
classCallCheck(this, Core); | ||
@@ -756,3 +770,3 @@ this.id = generateHash(); | ||
createClass(TypeIt, [{ | ||
createClass(Core, [{ | ||
key: "generateInstances", | ||
@@ -780,2 +794,4 @@ value: function generateInstances() { | ||
this.init(true); | ||
this.instances.forEach(function (instance) { | ||
@@ -787,5 +803,24 @@ instance.queue.push([instance[action], argument]); | ||
} | ||
//-- We KNOW we have items to process now, so make sure we set this to false. | ||
instance.isComplete = false; | ||
}); | ||
} | ||
}]); | ||
return Core; | ||
}(); | ||
var TypeIt = function (_Core) { | ||
inherits(TypeIt, _Core); | ||
function TypeIt(element, args) { | ||
var autoInit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; | ||
classCallCheck(this, TypeIt); | ||
return possibleConstructorReturn(this, (TypeIt.__proto__ || Object.getPrototypeOf(TypeIt)).call(this, element, args, autoInit)); | ||
} | ||
createClass(TypeIt, [{ | ||
key: "type", | ||
/** | ||
@@ -797,8 +832,7 @@ * If used after typing has started, will append strings to the end of the existing queue. If used when typing is paused, will restart it. | ||
*/ | ||
}, { | ||
key: "type", | ||
value: function type() { | ||
var string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; | ||
this.init(true); | ||
this.instances.forEach(function (instance) { | ||
@@ -811,2 +845,5 @@ //-- Queue up a string right off the bat. | ||
} | ||
//-- We KNOW we have items to process now, so make sure we set this to false. | ||
instance.isComplete = false; | ||
}); | ||
@@ -909,4 +946,13 @@ | ||
value: function init() { | ||
var requireAutoInit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
this.instances.forEach(function (instance) { | ||
instance.init(); | ||
if (!requireAutoInit) { | ||
instance.init(); | ||
return; | ||
} | ||
if (instance.autoInit) { | ||
instance.init(); | ||
} | ||
}); | ||
@@ -944,3 +990,3 @@ } | ||
return TypeIt; | ||
}(); | ||
}(Core); | ||
@@ -947,0 +993,0 @@ return TypeIt; |
@@ -5,3 +5,3 @@ /*! | ||
* Author: Alex MacArthur <alex@macarthur.me> (https://macarthur.me) | ||
* Version: v5.10.1 | ||
* Version: v5.10.2 | ||
* URL: https://typeitjs.com | ||
@@ -11,2 +11,2 @@ * License: GPL-2.0 | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.TypeIt=e()}(this,function(){"use strict";function t(t){var e=t.getBoundingClientRect();return!(e.right>window.innerWidth||e.bottom>window.innerHeight)&&!(e.top<0||e.left<0)}function e(t,e){return Math.abs(Math.random()*(t+e-(t-e))+(t-e))}function i(t,e){return 0===t.indexOf(e)}function n(t){return Array.isArray(t)?t.slice(0):t.split("<br>")}window.TypeItDefaults={strings:[],speed:100,deleteSpeed:null,lifeLike:!0,cursor:!0,cursorChar:"|",cursorSpeed:1e3,breakLines:!0,startDelay:250,startDelete:!1,nextStringDelay:750,loop:!1,loopDelay:!1,html:!0,autoStart:!0,callback:!1,beforeString:!1,afterString:!1,beforeStep:!1,afterStep:!1,afterComplete:!1};var s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},r=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),u=function(){function s(t,e,i,n,r){o(this,s),this.typeit=r,this.timeouts=[],this.id=e,this.autoInit=n,this.hasStarted=!1,this.isFrozen=!1,this.isComplete=!1,this.hasBeenDestroyed=!1,this.queue=[],this.isInTag=!1,this.stringsToDelete="",this.style="display:inline;position:relative;font:inherit;color:inherit;",this.element=t,this.setOptions(i,window.TypeItDefaults,!1),this.prepareTargetElement(),this.prepareDelay("nextStringDelay"),this.prepareDelay("loopDelay"),this.prepareStrings()&&(this.prepareDOM(),this.options.startDelete&&(this.insert(this.stringsToDelete),this.queue.push([this.delete]),this.insertSplitPause(1)),this.generateQueue(),this.autoInit&&this.init())}return r(s,[{key:"prepareStrings",value:function(){return this.options.strings=n(this.options.strings),this.options.strings=this.options.strings.map(function(t){return t.replace(/<\!--.*?-->/g,"")}),!(this.options.strings.length>=1&&""===this.options.strings[0])}},{key:"prepareDOM",value:function(){this.element.innerHTML='\n <span style="'+this.style+'" class="ti-container"></span>\n ',this.element.setAttribute("data-typeitid",this.id),this.elementContainer=this.element.querySelector("span")}},{key:"reset",value:function(){return new s(this.element,this.id,this.options,this.autoInit,this.typeit)}},{key:"contents",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return null===t?this.options.html?this.elementContainer.innerHTML:this.elementContainer.innerText:(this.elementContainer[this.options.html?"innerHTML":"innerText"]=t,t)}},{key:"prepareDelay",value:function(t){var e=this.options[t];if(e){var i=Array.isArray(e),n=i?null:e/2;this.options[t]={before:i?e[0]:n,after:i?e[1]:n,total:i?e[0]+e[1]:e}}}},{key:"generateQueue",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;e=null===e?[this.pause,this.options.startDelay]:e,this.queue.push(e),this.options.strings.forEach(function(e,i){if(t.queueString(e),i+1!==t.options.strings.length){if(t.options.breakLines)return t.queue.push([t.break]),void t.insertSplitPause(t.queue.length);t.queueDeletions(e),t.insertSplitPause(t.queue.length,e.length)}})}},{key:"queueDeletions",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e="string"==typeof t?t.length:t,i=0;i<e;i++)this.queue.push([this.delete,1])}},{key:"queueString",value:function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(t){if(t=n(t),document.implementation.createHTMLDocument("").body.innerHTML=t,e&&(t=(t=this.rake(t))[0]),this.options.html&&i(t[0],"<")&&!i(t[0],"</")){var s=t[0].match(/\<(.*?)\>/),o=document.implementation.createHTMLDocument("");o.body.innerHTML="<"+s[1]+"></"+s[1]+">",this.queue.push([this.type,o.body.children[0]])}else this.queue.push([this.type,t[0]]);t.splice(0,1),e&&this.queue[this.queue.length-1].push("first-of-string"),t.length?this.queueString(t,!1):this.queue[this.queue.length-1].push("last-of-string")}}},{key:"insertSplitPause",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;this.queue.splice(t,0,[this.pause,this.options.nextStringDelay.before]),this.queue.splice(t-e,0,[this.pause,this.options.nextStringDelay.after])}},{key:"init",value:function(){if(!this.hasStarted){if(this.cursor(),this.options.autoStart)return this.hasStarted=!0,void this.next();if(t(this.element))return this.hasStarted=!0,void this.next();var e=this;window.addEventListener("scroll",function i(n){t(e.element)&&!e.hasStarted&&(e.hasStarted=!0,e.next(),n.currentTarget.removeEventListener(n.type,i))})}}},{key:"cursor",value:function(){var t="visibility: hidden;";if(this.options.cursor){var e=document.createElement("style");e.id=this.id;var i="\n @keyframes blink-"+this.id+" {\n 0% {opacity: 0}\n 49% {opacity: 0}\n 50% {opacity: 1}\n }\n\n [data-typeitid='"+this.id+"'] .ti-cursor {\n animation: blink-"+this.id+" "+this.options.cursorSpeed/1e3+"s infinite;\n }\n ";e.appendChild(document.createTextNode(i)),document.head.appendChild(e),t=""}this.element.insertAdjacentHTML("beforeend",'<span style="'+this.style+t+'" class="ti-cursor">'+this.options.cursorChar+"</span>")}},{key:"insert",value:function(t){arguments.length>1&&void 0!==arguments[1]&&arguments[1]?this.elementContainer.lastChild.insertAdjacentHTML("beforeend",t):this.elementContainer.insertAdjacentHTML("beforeend",t),this.contents(this.contents().split("").join(""))}},{key:"prepareTargetElement",value:function(){var t=this;[].slice.call(this.element.childNodes).forEach(function(e){void 0!==e.classList&&e.classList.contains("ti-container")&&(t.element.innerHTML="")}),!this.options.startDelete&&this.element.innerHTML.length>0?this.options.strings=this.element.innerHTML.trim():this.stringsToDelete=this.element.innerHTML}},{key:"break",value:function(){this.insert("<br>"),this.next()}},{key:"pause",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];setTimeout(function(){t.next()},e||this.options.nextStringDelay.total)}},{key:"rake",value:function(t){var e=this;return t.map(function(t){return t=t.split(""),e.options.html?function(t){for(var e=[],i=void 0,n=!1,s=0;s<t.length;s++)"<"!==t[s]&&"&"!==t[s]||(e[0]=s,n="&"===t[s]),(">"===t[s]||";"===t[s]&&n)&&(e[1]=s,s=0,i=t.slice(e[0],e[1]+1).join(""),t.splice(e[0],e[1]-e[0]+1,i),n=!1);return t}(t):t})}},{key:"type",value:function(t){var e=this;this.setPace(),this.timeouts[0]=setTimeout(function(){return"string"!=typeof t?(t.innerHTML="",e.elementContainer.appendChild(t),e.isInTag=!0,void e.next()):i(t,"</")?(e.isInTag=!1,void e.next()):(e.insert(t,e.isInTag),void e.next())},this.typePace)}},{key:"setOptions",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],n={};for(var s in null===e&&(e=this.options),e)n[s]=e[s];for(var o in t)n[o]=t[o];this.options=n,i&&this.next()}},{key:"setPace",value:function(){var t=this.options.speed,i=null!==this.options.deleteSpeed?this.options.deleteSpeed:this.options.speed/3,n=t/2,s=i/2;this.typePace=this.options.lifeLike?e(t,n):t,this.deletePace=this.options.lifeLike?e(i,s):i}},{key:"delete",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;this.timeouts[1]=setTimeout(function(){t.setPace();for(var i=t.contents().split(""),n=i.length-1;n>-1;n--){if(">"!==i[n]&&";"!==i[n]||!t.options.html){i.pop();break}for(var s=n;s>-1;s--){if("<br>"===i.slice(s-3,s+1).join("")){i.splice(s-3,4);break}if("&"===i[s]){i.splice(s,n-s+1);break}if("<"===i[s]&&">"!==i[s-1]){if(";"===i[s-1])for(var o=s-1;o>-1;o--)if("&"===i[o]){i.splice(o,s-o);break}i.splice(s-1,1);break}}break}if(t.options.html&&t.contents().indexOf("></")>-1)for(var r=t.contents().indexOf("></")-2;r>=0;r--)if("<"===i[r]){i.splice(r,i.length-r);break}t.contents(i.join("").replace(/<[^\/>][^>]*><\/[^>]+>/,"")),null===e&&t.queue.unshift([t.delete,i.length]),e>1&&t.queue.unshift([t.delete,e-1]),t.next()},this.deletePace)}},{key:"empty",value:function(){this.contents(""),this.next()}},{key:"next",value:function(){var t=this;if(!this.isFrozen){if(this.queue.length>0)return this.step=this.queue.shift(),"first-of-string"===this.step[2]&&this.options.beforeString&&this.options.beforeString(this.step,this.queue,this.typeit),this.options.beforeStep&&this.options.beforeStep(this.step,this.queue,this.typeit),this.step[0].call(this,this.step[1],this.step[2]),"last-of-string"===this.step[2]&&this.options.afterString&&this.options.afterString(this.step,this.queue,this.typeit),void(this.options.afterStep&&this.options.afterStep(this.step,this.queue,this.typeit));if(this.options.callback&&this.options.callback(),this.options.afterComplete&&this.options.afterComplete(this.typeit),this.options.loop){var e=this.options.loopDelay?this.options.loopDelay:this.options.nextStringDelay;return this.queueDeletions(this.contents()),this.generateQueue([this.pause,e.before]),void setTimeout(function(){t.next()},e.after)}this.isComplete=!0}}}]),s}();return function(){function t(e,i){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];o(this,t),this.id=Math.random().toString(36).substring(2,15),this.instances=[],this.elements=[],this.args=i,this.autoInit=n,"object"===(void 0===e?"undefined":s(e))&&(void 0===e.length?this.elements.push(e):this.elements=e),"string"==typeof e&&(this.elements=document.querySelectorAll(e)),this.generateInstances()}return r(t,[{key:"generateInstances",value:function(){var t=this;[].slice.call(this.elements).forEach(function(e){t.instances.push(new u(e,t.id,t.args,t.autoInit,t))})}},{key:"queueUp",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this.instances.forEach(function(i){i.queue.push([i[t],e]),!0===i.isComplete&&i.next()})}},{key:"type",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return this.instances.forEach(function(e){e.queueString(t),!0===e.isComplete&&e.next()}),this}},{key:"delete",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return this.queueUp("delete",t),this}},{key:"pause",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return this.queueUp("pause",t),this}},{key:"empty",value:function(){return this.queueUp("empty"),this}},{key:"break",value:function(){return this.queueUp("break"),this}},{key:"options",value:function(t){return this.queueUp("setOptions",t),this}},{key:"freeze",value:function(){this.instances.forEach(function(t){t.isFrozen=!0})}},{key:"unfreeze",value:function(){this.instances.forEach(function(t){t.isFrozen&&(t.isFrozen=!1,t.next())})}},{key:"destroy",value:function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.instances.forEach(function(e){e.timeouts.forEach(function(t){clearTimeout(t)}),e.timeouts=[],t&&e.options.cursor&&e.element.removeChild(e.element.querySelector(".ti-cursor")),e.hasBeenDestroyed=!0})}},{key:"reset",value:function(){this.instances=this.instances.map(function(t){return t.reset()})}},{key:"init",value:function(){this.instances.forEach(function(t){t.init()})}},{key:"isComplete",get:function(){return!!this.instances.length&&this.instances[0].isComplete}},{key:"hasBeenDestroyed",get:function(){return!!this.instances.length&&this.instances[0].hasBeenDestroyed}},{key:"hasStarted",get:function(){return!!this.instances.length&&this.instances[0].hasStarted}},{key:"isFrozen",get:function(){return!!this.instances.length&&this.instances[0].isFrozen}}]),t}()}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.TypeIt=e()}(this,function(){"use strict";function t(t){var e=t.getBoundingClientRect();return!(e.right>window.innerWidth||e.bottom>window.innerHeight)&&!(e.top<0||e.left<0)}function e(t,e){return Math.abs(Math.random()*(t+e-(t-e))+(t-e))}function i(t,e){return 0===t.indexOf(e)}function n(t){return Array.isArray(t)?t.slice(0):t.split("<br>")}window.TypeItDefaults={strings:[],speed:100,deleteSpeed:null,lifeLike:!0,cursor:!0,cursorChar:"|",cursorSpeed:1e3,breakLines:!0,startDelay:250,startDelete:!1,nextStringDelay:750,loop:!1,loopDelay:!1,html:!0,autoStart:!0,callback:!1,beforeString:!1,afterString:!1,beforeStep:!1,afterStep:!1,afterComplete:!1};var s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},r=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),u=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},h=function(){function s(t,e,i,n,r){o(this,s),this.id=e,this.typeit=r,this.autoInit=n,this.element=t,this.timeouts=[],this.hasStarted=!1,this.isFrozen=!1,this.isComplete=!1,this.hasBeenDestroyed=!1,this.queue=[],this.isInTag=!1,this.stringsToDelete="",this.style="display:inline;position:relative;font:inherit;color:inherit;",this.setOptions(i,window.TypeItDefaults,!1),this.prepareTargetElement(),this.prepareDelay("nextStringDelay"),this.prepareDelay("loopDelay"),this.prepareDOM(),this.prepareStrings(),this.options.startDelete&&this.stringsToDelete&&(this.insert(this.stringsToDelete),this.queue.push([this.delete]),this.insertSplitPause(1)),this.generateQueue(),this.options.strings.length&&this.options.strings[0]&&this.autoInit&&this.init()}return r(s,[{key:"prepareStrings",value:function(){this.options.strings=n(this.options.strings).map(function(t){return t.replace(/<\!--.*?-->/g,"")})}},{key:"prepareDOM",value:function(){this.element.innerHTML='\n <span style="'+this.style+'" class="ti-container"></span>\n ',this.element.setAttribute("data-typeitid",this.id),this.elementContainer=this.element.querySelector("span")}},{key:"reset",value:function(){return new s(this.element,this.id,this.options,this.autoInit,this.typeit)}},{key:"contents",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return null===t?this.options.html?this.elementContainer.innerHTML:this.elementContainer.innerText:(this.elementContainer[this.options.html?"innerHTML":"innerText"]=t,t)}},{key:"prepareDelay",value:function(t){var e=this.options[t];if(e){var i=Array.isArray(e),n=i?null:e/2;this.options[t]={before:i?e[0]:n,after:i?e[1]:n,total:i?e[0]+e[1]:e}}}},{key:"generateQueue",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;e=null===e?[this.pause,this.options.startDelay]:e,this.queue.push(e),this.options.strings.forEach(function(e,i){if(t.queueString(e),i+1!==t.options.strings.length){if(t.options.breakLines)return t.queue.push([t.break]),void t.insertSplitPause(t.queue.length);t.queueDeletions(e),t.insertSplitPause(t.queue.length,e.length)}})}},{key:"queueDeletions",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e="string"==typeof t?t.length:t,i=0;i<e;i++)this.queue.push([this.delete,1])}},{key:"queueString",value:function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(t){if(t=n(t),document.implementation.createHTMLDocument("").body.innerHTML=t,e&&(t=this.rake(t)[0]),this.options.html&&i(t[0],"<")&&!i(t[0],"</")){var s=t[0].match(/\<(.*?)\>/),o=document.implementation.createHTMLDocument("");o.body.innerHTML="<"+s[1]+"></"+s[1]+">",this.queue.push([this.type,o.body.children[0]])}else this.queue.push([this.type,t[0]]);t.splice(0,1),e&&this.queue[this.queue.length-1].push("first-of-string"),t.length?this.queueString(t,!1):this.queue[this.queue.length-1].push("last-of-string")}}},{key:"insertSplitPause",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;this.queue.splice(t,0,[this.pause,this.options.nextStringDelay.before]),this.queue.splice(t-e,0,[this.pause,this.options.nextStringDelay.after])}},{key:"init",value:function(){if(!this.hasStarted){if(this.cursor(),this.options.autoStart)return this.hasStarted=!0,void this.next();if(t(this.element))return this.hasStarted=!0,void this.next();var e=this;window.addEventListener("scroll",function i(n){t(e.element)&&!e.hasStarted&&(e.hasStarted=!0,e.next(),n.currentTarget.removeEventListener(n.type,i))})}}},{key:"cursor",value:function(){var t="visibility: hidden;";if(this.options.cursor){var e=document.createElement("style");e.id=this.id;var i="\n @keyframes blink-"+this.id+" {\n 0% {opacity: 0}\n 49% {opacity: 0}\n 50% {opacity: 1}\n }\n\n [data-typeitid='"+this.id+"'] .ti-cursor {\n animation: blink-"+this.id+" "+this.options.cursorSpeed/1e3+"s infinite;\n }\n ";e.appendChild(document.createTextNode(i)),document.head.appendChild(e),t=""}this.element.insertAdjacentHTML("beforeend",'<span style="'+this.style+t+'" class="ti-cursor">'+this.options.cursorChar+"</span>")}},{key:"insert",value:function(t){arguments.length>1&&void 0!==arguments[1]&&arguments[1]?this.elementContainer.lastChild.insertAdjacentHTML("beforeend",t):this.elementContainer.insertAdjacentHTML("beforeend",t),this.contents(this.contents().split("").join(""))}},{key:"prepareTargetElement",value:function(){var t=this;[].slice.call(this.element.childNodes).forEach(function(e){void 0!==e.classList&&e.classList.contains("ti-container")&&(t.element.innerHTML="")}),!this.options.startDelete&&this.element.innerHTML.length>0?this.options.strings=this.element.innerHTML.trim():this.stringsToDelete=this.element.innerHTML}},{key:"break",value:function(){this.insert("<br>"),this.next()}},{key:"pause",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];setTimeout(function(){t.next()},e||this.options.nextStringDelay.total)}},{key:"rake",value:function(t){var e=this;return t.map(function(t){return t=t.split(""),e.options.html?function(t){for(var e=[],i=void 0,n=!1,s=0;s<t.length;s++)"<"!==t[s]&&"&"!==t[s]||(e[0]=s,n="&"===t[s]),(">"===t[s]||";"===t[s]&&n)&&(e[1]=s,s=0,i=t.slice(e[0],e[1]+1).join(""),t.splice(e[0],e[1]-e[0]+1,i),n=!1);return t}(t):t})}},{key:"type",value:function(t){var e=this;this.setPace(),this.timeouts[0]=setTimeout(function(){return"string"!=typeof t?(t.innerHTML="",e.elementContainer.appendChild(t),e.isInTag=!0,void e.next()):i(t,"</")?(e.isInTag=!1,void e.next()):(e.insert(t,e.isInTag),void e.next())},this.typePace)}},{key:"setOptions",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],n={};for(var s in null===e&&(e=this.options),e)n[s]=e[s];for(var o in t)n[o]=t[o];this.options=n,i&&this.next()}},{key:"setPace",value:function(){var t=this.options.speed,i=null!==this.options.deleteSpeed?this.options.deleteSpeed:this.options.speed/3,n=t/2,s=i/2;this.typePace=this.options.lifeLike?e(t,n):t,this.deletePace=this.options.lifeLike?e(i,s):i}},{key:"delete",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;this.timeouts[1]=setTimeout(function(){t.setPace();for(var i=t.contents().split(""),n=i.length-1;n>-1;n--){if(">"!==i[n]&&";"!==i[n]||!t.options.html){i.pop();break}for(var s=n;s>-1;s--){if("<br>"===i.slice(s-3,s+1).join("")){i.splice(s-3,4);break}if("&"===i[s]){i.splice(s,n-s+1);break}if("<"===i[s]&&">"!==i[s-1]){if(";"===i[s-1])for(var o=s-1;o>-1;o--)if("&"===i[o]){i.splice(o,s-o);break}i.splice(s-1,1);break}}break}if(t.options.html&&t.contents().indexOf("></")>-1)for(var r=t.contents().indexOf("></")-2;r>=0;r--)if("<"===i[r]){i.splice(r,i.length-r);break}t.contents(i.join("").replace(/<[^\/>][^>]*><\/[^>]+>/,"")),null===e&&t.queue.unshift([t.delete,i.length]),e>1&&t.queue.unshift([t.delete,e-1]),t.next()},this.deletePace)}},{key:"empty",value:function(){this.contents(""),this.next()}},{key:"next",value:function(){var t=this;if(!this.isFrozen){if(this.queue.length>0)return this.step=this.queue.shift(),"first-of-string"===this.step[2]&&this.options.beforeString&&this.options.beforeString(this.step,this.queue,this.typeit),this.options.beforeStep&&this.options.beforeStep(this.step,this.queue,this.typeit),this.step[0].call(this,this.step[1],this.step[2]),"last-of-string"===this.step[2]&&this.options.afterString&&this.options.afterString(this.step,this.queue,this.typeit),void(this.options.afterStep&&this.options.afterStep(this.step,this.queue,this.typeit));if(this.options.callback&&this.options.callback(),this.options.afterComplete&&this.options.afterComplete(this.typeit),this.options.loop){var e=this.options.loopDelay?this.options.loopDelay:this.options.nextStringDelay;return this.queueDeletions(this.contents()),this.generateQueue([this.pause,e.before]),void setTimeout(function(){t.next()},e.after)}this.isComplete=!0}}}]),s}(),a=function(){function t(e,i){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];o(this,t),this.id=Math.random().toString(36).substring(2,15),this.instances=[],this.elements=[],this.args=i,this.autoInit=n,"object"===(void 0===e?"undefined":s(e))&&(void 0===e.length?this.elements.push(e):this.elements=e),"string"==typeof e&&(this.elements=document.querySelectorAll(e)),this.generateInstances()}return r(t,[{key:"generateInstances",value:function(){var t=this;[].slice.call(this.elements).forEach(function(e){t.instances.push(new h(e,t.id,t.args,t.autoInit,t))})}},{key:"queueUp",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this.init(!0),this.instances.forEach(function(i){i.queue.push([i[t],e]),!0===i.isComplete&&i.next(),i.isComplete=!1})}}]),t}();return function(t){function e(t,i){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return o(this,e),u(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,i,n))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,a),r(e,[{key:"type",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return this.init(!0),this.instances.forEach(function(e){e.queueString(t),!0===e.isComplete&&e.next(),e.isComplete=!1}),this}},{key:"delete",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return this.queueUp("delete",t),this}},{key:"pause",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return this.queueUp("pause",t),this}},{key:"empty",value:function(){return this.queueUp("empty"),this}},{key:"break",value:function(){return this.queueUp("break"),this}},{key:"options",value:function(t){return this.queueUp("setOptions",t),this}},{key:"freeze",value:function(){this.instances.forEach(function(t){t.isFrozen=!0})}},{key:"unfreeze",value:function(){this.instances.forEach(function(t){t.isFrozen&&(t.isFrozen=!1,t.next())})}},{key:"destroy",value:function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.instances.forEach(function(e){e.timeouts.forEach(function(t){clearTimeout(t)}),e.timeouts=[],t&&e.options.cursor&&e.element.removeChild(e.element.querySelector(".ti-cursor")),e.hasBeenDestroyed=!0})}},{key:"reset",value:function(){this.instances=this.instances.map(function(t){return t.reset()})}},{key:"init",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.instances.forEach(function(e){t?e.autoInit&&e.init():e.init()})}},{key:"isComplete",get:function(){return!!this.instances.length&&this.instances[0].isComplete}},{key:"hasBeenDestroyed",get:function(){return!!this.instances.length&&this.instances[0].hasBeenDestroyed}},{key:"hasStarted",get:function(){return!!this.instances.length&&this.instances[0].hasStarted}},{key:"isFrozen",get:function(){return!!this.instances.length&&this.instances[0].isFrozen}}]),e}()}); |
{ | ||
"name": "typeit", | ||
"version": "5.10.1", | ||
"version": "5.10.2", | ||
"description": "The most versatile animated typing utility on the planet.", | ||
@@ -5,0 +5,0 @@ "author": "Alex MacArthur <alex@macarthur.me> (https://macarthur.me)", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
106845
1650