Socket
Socket
Sign inDemoInstall

typeit

Package Overview
Dependencies
Maintainers
1
Versions
119
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typeit - npm Package Compare versions

Comparing version 5.0.1 to 5.0.2

dist/typeit.es.js

316

dist/typeit.js
/*!
*
*
* typeit - The most versatile animated typing utility on the planet.
* Author: Alex MacArthur <alex@macarthur.me> (https://macarthur.me)
* Version: v5.0.1
* Version: v5.0.2
* URL: https://typeitjs.com
* License: GPL-2.0
*
*
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["TypeIt"] = factory();
else
root["TypeIt"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.TypeIt = factory());
}(this, (function () { 'use strict';
"use strict";
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Instance = __webpack_require__(1).default;
module.exports = function () {
function TypeIt(element, options) {
_classCallCheck(this, TypeIt);
this.elements = [];
this.instances = [];
if ((typeof element === "undefined" ? "undefined" : _typeof(element)) === "object") {
//-- There's only one!
if (element.length === undefined) {
this.elements.push(element);
} else {
//-- It's already an array!
this.elements = element;
}
}
//-- Convert to array of elements.
if (typeof element === "string") {
this.elements = document.querySelectorAll(element);
}
this.createInstances(options);
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
_createClass(TypeIt, [{
key: "createInstances",
value: function createInstances(options) {
var _this = this;
[].slice.call(this.elements).forEach(function (element) {
_this.instances.push(new Instance(element, options));
});
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}, {
key: "pushAction",
value: function pushAction(func) {
var argument = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
}
this.instances.forEach(function (instance) {
instance.queue.push([instance[func], argument]);
});
}
}, {
key: "type",
value: function type(string) {
this.pushAction("type", string);
return this;
}
}, {
key: "delete",
value: function _delete(numCharacters) {
this.pushAction("delete", numCharacters);
return this;
}
}, {
key: "empty",
value: function empty() {
this.pushAction("empty");
return this;
}
}, {
key: "pause",
value: function pause(ms) {
this.pushAction("pause", ms);
return this;
}
}, {
key: "break",
value: function _break() {
this.pushAction("break");
return this;
}
}, {
key: "options",
value: function options(_options) {
this.pushAction("setOptions", _options);
return this;
}
}]);
return TypeIt;
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Instance = function () {
function Instance(element, options) {
_classCallCheck(this, Instance);
classCallCheck(this, Instance);

@@ -234,3 +91,3 @@ this.defaults = {

_createClass(Instance, [{
createClass(Instance, [{
key: "init",

@@ -373,2 +230,5 @@ value: function init() {

}
//-- Split & rejoin to avoid odd spacing issues in some browsers.
this.elementContainer.innerHTML = this.elementContainer.innerHTML.split("").join("");
}

@@ -384,3 +244,3 @@

key: "toArray",
value: function toArray(string) {
value: function toArray$$1(string) {
return string.constructor === Array ? string.slice(0) : string.split("<br>");

@@ -552,3 +412,3 @@ }

value: function setOptions(settings) {
var defaults = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var defaults$$1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var autoExecuteQueue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;

@@ -558,8 +418,8 @@

if (defaults === null) {
defaults = this.options;
if (defaults$$1 === null) {
defaults$$1 = this.options;
}
for (var attrname in defaults) {
mergedSettings[attrname] = defaults[attrname];
for (var attrname in defaults$$1) {
mergedSettings[attrname] = defaults$$1[attrname];
}

@@ -707,10 +567,90 @@

}]);
return Instance;
}();
exports.default = Instance;
var TypeIt = function () {
function TypeIt(element, options) {
classCallCheck(this, TypeIt);
/***/ })
/******/ ]);
});
this.elements = [];
this.instances = [];
if ((typeof element === "undefined" ? "undefined" : _typeof(element)) === "object") {
//-- There's only one!
if (element.length === undefined) {
this.elements.push(element);
} else {
//-- It's already an array!
this.elements = element;
}
}
//-- Convert to array of elements.
if (typeof element === "string") {
this.elements = document.querySelectorAll(element);
}
this.createInstances(options);
}
createClass(TypeIt, [{
key: "createInstances",
value: function createInstances(options) {
var _this = this;
[].slice.call(this.elements).forEach(function (element) {
_this.instances.push(new Instance(element, options));
});
}
}, {
key: "pushAction",
value: function pushAction(func) {
var argument = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
this.instances.forEach(function (instance) {
instance.queue.push([instance[func], argument]);
});
}
}, {
key: "type",
value: function type(string) {
this.pushAction("type", string);
return this;
}
}, {
key: "delete",
value: function _delete(numCharacters) {
this.pushAction("delete", numCharacters);
return this;
}
}, {
key: "empty",
value: function empty() {
this.pushAction("empty");
return this;
}
}, {
key: "pause",
value: function pause(ms) {
this.pushAction("pause", ms);
return this;
}
}, {
key: "break",
value: function _break() {
this.pushAction("break");
return this;
}
}, {
key: "options",
value: function options(_options) {
this.pushAction("setOptions", _options);
return this;
}
}]);
return TypeIt;
}();
return TypeIt;
})));
/*!
*
*
* typeit - The most versatile animated typing utility on the planet.
* Author: Alex MacArthur <alex@macarthur.me> (https://macarthur.me)
* Version: v5.0.1
* Version: v5.0.2
* URL: https://typeitjs.com
* License: GPL-2.0
*
*
*/
(function(a,b){'object'==typeof exports&&'object'==typeof module?module.exports=b():'function'==typeof define&&define.amd?define([],b):'object'==typeof exports?exports.TypeIt=b():a.TypeIt=b()})(this,function(){return function(a){function b(d){if(c[d])return c[d].exports;var e=c[d]={i:d,l:!1,exports:{}};return a[d].call(e.exports,e,e.exports,b),e.l=!0,e.exports}var c={};return b.m=a,b.c=c,b.d=function(a,c,d){b.o(a,c)||Object.defineProperty(a,c,{configurable:!1,enumerable:!0,get:d})},b.n=function(a){var c=a&&a.__esModule?function(){return a['default']}:function(){return a};return b.d(c,'a',c),c},b.o=function(a,b){return Object.prototype.hasOwnProperty.call(a,b)},b.p='',b(b.s=0)}([function(a,b,c){'use strict';function d(a,b){if(!(a instanceof b))throw new TypeError('Cannot call a class as a function')}var e='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&'function'==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?'symbol':typeof a},f=function(){function a(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,'value'in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),g=c(1).default;a.exports=function(){function a(b,c){d(this,a),this.elements=[],this.instances=[],'object'===('undefined'==typeof b?'undefined':e(b))&&(void 0===b.length?this.elements.push(b):this.elements=b),'string'==typeof b&&(this.elements=document.querySelectorAll(b)),this.createInstances(c)}return f(a,[{key:'createInstances',value:function(a){var b=this;[].slice.call(this.elements).forEach(function(c){b.instances.push(new g(c,a))})}},{key:'pushAction',value:function(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null;this.instances.forEach(function(c){c.queue.push([c[a],b])})}},{key:'type',value:function(a){return this.pushAction('type',a),this}},{key:'delete',value:function(a){return this.pushAction('delete',a),this}},{key:'empty',value:function(){return this.pushAction('empty'),this}},{key:'pause',value:function(a){return this.pushAction('pause',a),this}},{key:'break',value:function(){return this.pushAction('break'),this}},{key:'options',value:function(a){return this.pushAction('setOptions',a),this}}]),a}()},function(a,b){'use strict';function c(a,b){if(!(a instanceof b))throw new TypeError('Cannot call a class as a function')}Object.defineProperty(b,'__esModule',{value:!0});var d=function(){function a(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,'value'in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),e=function(){function a(b,d){c(this,a),this.defaults={strings:[],speed:100,deleteSpeed:void 0,lifeLike:!0,cursor:!0,cursorSpeed:1e3,breakLines:!0,startDelay:250,startDelete:!1,nextStringDelay:750,loop:!1,loopDelay:750,html:!0,autoStart:!0,callback:function(){}},this.id='',this.queue=[],this.queueIndex=0,this.hasStarted=!1,this.inTag=!1,this.stringsToDelete='',this.style='style="display:inline;position:relative;font:inherit;color:inherit;"',this.element=b,this.setOptions(d,this.defaults,!1),this.init()}return d(a,[{key:'init',value:function(){this.checkElement(),this.options.strings=this.toArray(this.options.strings),1<=this.options.strings.length&&''===this.options.strings[0]||(this.element.innerHTML='<i class="ti-placeholder" style="display:inline-block;width:0;line-height:0;overflow:hidden;">.</i><span '+this.style+' class="ti-container"></span>',this.id=this.generateHash(),this.element.dataset.typeitid=this.id,this.elementContainer=this.element.querySelector('span'),this.options.startDelete&&(this.insert(this.stringsToDelete),this.queue.push([this.delete]),this.insertPauseIntoQueue(1)),this.generateQueue(),this.kickoff())}},{key:'generateQueue',value:function(){for(var a=0;a<this.options.strings.length;a++)this.queue.push([this.type,this.options.strings[a]]),a<this.options.strings.length-1&&(this.queue.push([this.options.breakLines?this.break:this.delete]),this.insertPauseIntoQueue(this.queue.length))}},{key:'insertPauseIntoQueue',value:function(a){var b=this.options.nextStringDelay/2;this.queue.splice(a-1,0,[this.pause,b]),this.queue.splice(a+2,0,[this.pause,b])}},{key:'kickoff',value:function(){if(this.cursor(),this.options.autoStart)this.startQueue();else if(this.isVisible())this.hasStarted=!0,this.startQueue();else{var a=this;window.addEventListener('scroll',function b(c){a.isVisible()&&!a.hasStarted&&(a.hasStarted=!0,a.startQueue(),c.currentTarget.removeEventListener(c.type,b))})}}},{key:'startQueue',value:function(){var a=this;setTimeout(function(){a.executeQueue()},this.options.startDelay)}},{key:'isVisible',value:function(){var a=this.element.getBoundingClientRect(),b={height:window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight,width:window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth};return a.right>b.width||a.bottom>b.height?!1:0>a.top||0>a.left?!1:!0}},{key:'generateHash',value:function(){return Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)}},{key:'cursor',value:function(){if(this.options.cursor){var a=this.generateHash(),b=document.createElement('style'),c='\n @keyframes blink-'+a+' {\n 0% {opacity: 0}\n 49%{opacity: 0}\n 50% {opacity: 1}\n }\n\n [data-typeitid=\''+this.id+'\'] .ti-cursor {\n animation: blink-'+a+' '+this.options.cursorSpeed/1e3+'s infinite;\n }\n ';b.appendChild(document.createTextNode(c)),document.head.appendChild(b),this.element.insertAdjacentHTML('beforeend','<span '+this.style+'class="ti-cursor">|</span>')}}},{key:'insert',value:function(a){var b=1<arguments.length&&void 0!==arguments[1]&&arguments[1];b?this.elementContainer.lastChild.insertAdjacentHTML('beforeend',a):this.elementContainer.insertAdjacentHTML('beforeend',a)}},{key:'toArray',value:function(a){return a.constructor===Array?a.slice(0):a.split('<br>')}},{key:'checkElement',value:function(){!this.options.startDelete&&0<this.element.innerHTML.length?this.options.strings=this.element.innerHTML.trim():this.stringsToDelete=this.element.innerHTML}},{key:'break',value:function(){this.insert('<br>'),this.executeQueue()}},{key:'pause',value:function(a){var b=this;a=void 0===a?this.options.nextStringDelay:a,setTimeout(function(){b.executeQueue()},a)}},{key:'rake',value:function(a){var b=this;return a.map(function(a){if(a=a.split(''),b.options.html)for(var c=[],d=void 0,e=!1,f=0;f<a.length;f++)('<'===a[f]||'&'===a[f])&&(c[0]=f,e='&'===a[f]),('>'===a[f]||';'===a[f]&&e)&&(c[1]=f,f=0,d=a.slice(c[0],c[1]+1).join(''),a.splice(c[0],c[1]-c[0]+1,d),e=!1);return a})}},{key:'print',value:function(a){this.inTag?(this.insert(a,!0),this.tagCount<this.tagDuration?this.tagCount++:this.inTag=!1):this.insert(a)}},{key:'type',value:function(a){var b=this,c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:!0;a=this.toArray(a),c&&(a=this.rake(a),a=a[0]),this.typingTimeout=setTimeout(function(){if(b.setPace(b),b.options.html&&-1!==a[0].indexOf('<')&&-1===a[0].indexOf('</')&&!b.inTag){for(var c=a.length-1;0<=c;c--)-1!==a[c].indexOf('</')&&(b.tagCount=1,b.tagDuration=c);b.inTag=!0;var d=a[0].match(/\<(.*?)\>/),e=document.implementation.createHTMLDocument();e.body.innerHTML='<'+d[1]+'></'+d[1]+'>',b.elementContainer.appendChild(e.body.children[0])}else b.print(a[0]);a.splice(0,1),a.length?b.type(a,!1):b.executeQueue()},this.typePace)}},{key:'removeHelperElements',value:function(){var a=this,b=this.element.querySelectorAll('.ti-container, .ti-cursor, .ti-placeholder');[].forEach.call(b,function(b){a.element.removeChild(b)})}},{key:'setOptions',value:function(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:!0,d={};for(var e in null===b&&(b=this.options),b)d[e]=b[e];for(var f in a)d[f]=a[f];this.options=d,c&&this.executeQueue()}},{key:'randomInRange',value:function(a,b){return Math.abs(Math.random()*(a+b-(a-b))+(a-b))}},{key:'setPace',value:function(){var a=this.options.speed,b=void 0===this.options.deleteSpeed?this.options.speed/3:this.options.deleteSpeed;this.typePace=this.options.lifeLike?this.randomInRange(a,a/2):a,this.deletePace=this.options.lifeLike?this.randomInRange(b,b/2):b}},{key:'delete',value:function(){var a=this,b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:null;this.deleteTimeout=setTimeout(function(){a.setPace();for(var c=a.elementContainer.innerHTML.split(''),d=null===b?c.length-1:b+1,e=c.length-1;-1<e;e--)if(('>'===c[e]||';'===c[e])&&a.options.html){for(var f=e;-1<f;f--){if('<br>'===c.slice(f-3,f+1).join('')){c.splice(f-3,4);break}if('&'===c[f]){c.splice(f,e-f+1);break}if('<'===c[f]&&'>'!==c[f-1]){if(';'===c[f-1])for(var g=f-1;-1<g;g--)if('&'===c[g]){c.splice(g,f-g);break}c.splice(f-1,1);break}}break}else{c.pop();break}if(-1<a.elementContainer.innerHTML.indexOf('></'))for(var h=a.elementContainer.innerHTML.indexOf('></')-2;0<=h;h--)if('<'===c[h]){c.splice(h,c.length-h);break}a.elementContainer.innerHTML=c.join(''),d>(null===b?0:2)?a.delete(null===b?null:b-1):a.executeQueue()},this.deletePace)}},{key:'empty',value:function(){this.elementContainer.innerHTML='',this.executeQueue()}},{key:'executeQueue',value:function(){var a=this;if(this.queueIndex<this.queue.length){var b=this.queue[this.queueIndex];return this.queueIndex++,void(this.isLooping&&1===this.queueIndex?setTimeout(function(){b[0].call(a,b[1])},this.options.loopDelay/2):b[0].call(this,b[1]))}this.options.callback(),this.options.loop&&(this.queueIndex=0,this.isLooping=!0,setTimeout(function(){a.delete()},this.options.loopDelay/2))}}]),a}();b.default=e}])});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.TypeIt=t()}(this,function(){"use strict";var e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},i=function(){function e(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),t}}(),n=function(){function e(i,n){t(this,e),this.defaults={strings:[],speed:100,deleteSpeed:void 0,lifeLike:!0,cursor:!0,cursorSpeed:1e3,breakLines:!0,startDelay:250,startDelete:!1,nextStringDelay:750,loop:!1,loopDelay:750,html:!0,autoStart:!0,callback:function(){}},this.id="",this.queue=[],this.queueIndex=0,this.hasStarted=!1,this.inTag=!1,this.stringsToDelete="",this.style='style="display:inline;position:relative;font:inherit;color:inherit;"',this.element=i,this.setOptions(n,this.defaults,!1),this.init()}return i(e,[{key:"init",value:function(){this.checkElement(),this.options.strings=this.toArray(this.options.strings),this.options.strings.length>=1&&""===this.options.strings[0]||(this.element.innerHTML='<i class="ti-placeholder" style="display:inline-block;width:0;line-height:0;overflow:hidden;">.</i><span '+this.style+' class="ti-container"></span>',this.id=this.generateHash(),this.element.dataset.typeitid=this.id,this.elementContainer=this.element.querySelector("span"),this.options.startDelete&&(this.insert(this.stringsToDelete),this.queue.push([this.delete]),this.insertPauseIntoQueue(1)),this.generateQueue(),this.kickoff())}},{key:"generateQueue",value:function(){for(var e=0;e<this.options.strings.length;e++)this.queue.push([this.type,this.options.strings[e]]),e<this.options.strings.length-1&&(this.queue.push([this.options.breakLines?this.break:this.delete]),this.insertPauseIntoQueue(this.queue.length))}},{key:"insertPauseIntoQueue",value:function(e){var t=this.options.nextStringDelay/2;this.queue.splice(e-1,0,[this.pause,t]),this.queue.splice(e+2,0,[this.pause,t])}},{key:"kickoff",value:function(){if(this.cursor(),this.options.autoStart)this.startQueue();else if(this.isVisible())this.hasStarted=!0,this.startQueue();else{var e=this;window.addEventListener("scroll",function t(i){e.isVisible()&&!e.hasStarted&&(e.hasStarted=!0,e.startQueue(),i.currentTarget.removeEventListener(i.type,t))})}}},{key:"startQueue",value:function(){var e=this;setTimeout(function(){e.executeQueue()},this.options.startDelay)}},{key:"isVisible",value:function(){var e=this.element.getBoundingClientRect(),t=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight,i=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;return!(e.right>i||e.bottom>t)&&!(e.top<0||e.left<0)}},{key:"generateHash",value:function(){return Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)}},{key:"cursor",value:function(){if(this.options.cursor){var e=this.generateHash(),t=document.createElement("style"),i="\n @keyframes blink-"+e+" {\n 0% {opacity: 0}\n 49%{opacity: 0}\n 50% {opacity: 1}\n }\n\n [data-typeitid='"+this.id+"'] .ti-cursor {\n animation: blink-"+e+" "+this.options.cursorSpeed/1e3+"s infinite;\n }\n ";t.appendChild(document.createTextNode(i)),document.head.appendChild(t),this.element.insertAdjacentHTML("beforeend","<span "+this.style+'class="ti-cursor">|</span>')}}},{key:"insert",value:function(e){arguments.length>1&&void 0!==arguments[1]&&arguments[1]?this.elementContainer.lastChild.insertAdjacentHTML("beforeend",e):this.elementContainer.insertAdjacentHTML("beforeend",e),this.elementContainer.innerHTML=this.elementContainer.innerHTML.split("").join("")}},{key:"toArray",value:function(e){return e.constructor===Array?e.slice(0):e.split("<br>")}},{key:"checkElement",value:function(){!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.executeQueue()}},{key:"pause",value:function(e){var t=this;e=void 0===e?this.options.nextStringDelay:e,setTimeout(function(){t.executeQueue()},e)}},{key:"rake",value:function(e){var t=this;return e.map(function(e){if(e=e.split(""),t.options.html)for(var i=[],n=void 0,s=!1,o=0;o<e.length;o++)"<"!==e[o]&&"&"!==e[o]||(i[0]=o,s="&"===e[o]),(">"===e[o]||";"===e[o]&&s)&&(i[1]=o,o=0,n=e.slice(i[0],i[1]+1).join(""),e.splice(i[0],i[1]-i[0]+1,n),s=!1);return e})}},{key:"print",value:function(e){this.inTag?(this.insert(e,!0),this.tagCount<this.tagDuration?this.tagCount++:this.inTag=!1):this.insert(e)}},{key:"type",value:function(e){var t=this,i=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e=this.toArray(e),i&&(e=(e=this.rake(e))[0]),this.typingTimeout=setTimeout(function(){if(t.setPace(t),t.options.html&&-1!==e[0].indexOf("<")&&-1===e[0].indexOf("</")&&!t.inTag){for(var i=e.length-1;i>=0;i--)-1!==e[i].indexOf("</")&&(t.tagCount=1,t.tagDuration=i);t.inTag=!0;var n=e[0].match(/\<(.*?)\>/),s=document.implementation.createHTMLDocument();s.body.innerHTML="<"+n[1]+"></"+n[1]+">",t.elementContainer.appendChild(s.body.children[0])}else t.print(e[0]);e.splice(0,1),e.length?t.type(e,!1):t.executeQueue()},this.typePace)}},{key:"removeHelperElements",value:function(){var e=this,t=this.element.querySelectorAll(".ti-container, .ti-cursor, .ti-placeholder");[].forEach.call(t,function(t){e.element.removeChild(t)})}},{key:"setOptions",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],n={};null===t&&(t=this.options);for(var s in t)n[s]=t[s];for(var o in e)n[o]=e[o];this.options=n,i&&this.executeQueue()}},{key:"randomInRange",value:function(e,t){return Math.abs(Math.random()*(e+t-(e-t))+(e-t))}},{key:"setPace",value:function(){var e=this.options.speed,t=void 0!==this.options.deleteSpeed?this.options.deleteSpeed:this.options.speed/3,i=e/2,n=t/2;this.typePace=this.options.lifeLike?this.randomInRange(e,i):e,this.deletePace=this.options.lifeLike?this.randomInRange(t,n):t}},{key:"delete",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;this.deleteTimeout=setTimeout(function(){e.setPace();for(var i=e.elementContainer.innerHTML.split(""),n=null===t?i.length-1:t+1,s=i.length-1;s>-1;s--){if(">"!==i[s]&&";"!==i[s]||!e.options.html){i.pop();break}for(var o=s;o>-1;o--){if("<br>"===i.slice(o-3,o+1).join("")){i.splice(o-3,4);break}if("&"===i[o]){i.splice(o,s-o+1);break}if("<"===i[o]&&">"!==i[o-1]){if(";"===i[o-1])for(var r=o-1;r>-1;r--)if("&"===i[r]){i.splice(r,o-r);break}i.splice(o-1,1);break}}break}if(e.elementContainer.innerHTML.indexOf("></")>-1)for(var u=e.elementContainer.innerHTML.indexOf("></")-2;u>=0;u--)if("<"===i[u]){i.splice(u,i.length-u);break}e.elementContainer.innerHTML=i.join(""),n>(null===t?0:2)?e.delete(null===t?null:t-1):e.executeQueue()},this.deletePace)}},{key:"empty",value:function(){this.elementContainer.innerHTML="",this.executeQueue()}},{key:"executeQueue",value:function(){var e=this;if(this.queueIndex<this.queue.length){var t=this.queue[this.queueIndex];return this.queueIndex++,void(this.isLooping&&1===this.queueIndex?setTimeout(function(){t[0].call(e,t[1])},this.options.loopDelay/2):t[0].call(this,t[1]))}this.options.callback(),this.options.loop&&(this.queueIndex=0,this.isLooping=!0,setTimeout(function(){e.delete()},this.options.loopDelay/2))}}]),e}();return function(){function s(i,n){t(this,s),this.elements=[],this.instances=[],"object"===(void 0===i?"undefined":e(i))&&(void 0===i.length?this.elements.push(i):this.elements=i),"string"==typeof i&&(this.elements=document.querySelectorAll(i)),this.createInstances(n)}return i(s,[{key:"createInstances",value:function(e){var t=this;[].slice.call(this.elements).forEach(function(i){t.instances.push(new n(i,e))})}},{key:"pushAction",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this.instances.forEach(function(i){i.queue.push([i[e],t])})}},{key:"type",value:function(e){return this.pushAction("type",e),this}},{key:"delete",value:function(e){return this.pushAction("delete",e),this}},{key:"empty",value:function(){return this.pushAction("empty"),this}},{key:"pause",value:function(e){return this.pushAction("pause",e),this}},{key:"break",value:function(){return this.pushAction("break"),this}},{key:"options",value:function(e){return this.pushAction("setOptions",e),this}}]),s}()});
{
"name": "typeit",
"version": "5.0.1",
"version": "5.0.2",
"description": "The most versatile animated typing utility on the planet.",

@@ -12,7 +12,10 @@ "author": "Alex MacArthur <alex@macarthur.me> (https://macarthur.me)",

"main": "dist/typeit.js",
"module": "dist/typeit.es.js",
"files": [
"dist/"
],
"scripts": {
"watch": "NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=webpack.config.js && prettier src/* --write",
"unminified": "NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=webpack.config.js",
"minified": "NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=webpack.config.js",
"build": "yarn run unminified && yarn run minified && prettier src/* --write"
"build": "rollup -c && prettier src/* --write",
"watch": "rollup -c -w",
"serve": "concurrently --kill-others \"rollup -c -w\" \"node serve.js\""
},

@@ -33,11 +36,12 @@ "keywords": [

"devDependencies": {
"@babel/core": "^7.0.0-beta.32",
"babel-cli": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-core": "^6.26.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-env": "^1.6.1",
"babili-webpack-plugin": "^0.1.2",
"banner-webpack-plugin": "^0.2.3",
"concurrently": "^3.5.1",
"express": "^4.16.2",
"prettier": "^1.8.2",
"webpack": "^3.8.1"
"rollup": "^0.52.0",
"rollup-plugin-babel": "^3.0.2",
"rollup-plugin-uglify": "^2.0.1"
}
}

@@ -21,6 +21,6 @@ <pre>Update: TypeIt is now vanilla JavaScript, and no longer dependent upon jQuery!</pre>

For more advanced, controlled typing effects, TypeIt comes with companion functions that can be chained to control your typing down to a single character, enabling you to type an dynamic narrative, with complete control over speed changes, line breaks, deletions, and pauses.
For more advanced, controlled typing effects, TypeIt comes with companion functions that can be chained to control your typing down to a single character, enabling you to type an dynamic narrative, with complete control over speed changes, line breaks, deletions, and pauses.
### Some of the Perks
* Choose to start typing only when your container element becomes visible on the screen.
* Choose to start typing only when your container element becomes visible on the screen.
* Loop your string(s) continuously.

@@ -30,3 +30,3 @@ * Define you strings via an options object or in the HTML (useful in case user doesn't have JavaScript enabled, as well as for SEO).

* Handle HTML tags (including those with classes, ID's, etc.) and entities with ease.
* Use companion functions to chain individual commands together to fine tune your typing.
* Use companion functions to chain individual commands together to fine tune your typing.
* Ready to be included via JS module, or as a separate script loaded on your page.

@@ -42,3 +42,3 @@ * No dependencies!

## Choose a License
Using TypeIt for an open source or personal project is completely free. To use it in a commercial project, purchase a single license, or an unlimited license that'll never expire, no matter how many times you use it.
Using TypeIt for an open source or personal project is completely free. To use it in a commercial project, purchase a single license, or an unlimited license that'll never expire, no matter how many times you use it.
* Personal or Open Source - [FREE](#setup)

@@ -52,3 +52,3 @@ * Single Commercial License - [Purchase Here](https://www.uplabs.com/posts/typeit-a-jquery-animated-typing-plugin)

Get it from this repo, or from the following sources:
Get it from this repo, or from the following sources:

@@ -67,3 +67,3 @@ * <strong><a href="https://cdnjs.com/libraries/typeit">CDN:</a></strong> Include `https://cdnjs.cloudflare.com/ajax/libs/typeit/{ VERSION }/typeit.min.js` on your page.

```js
import TypeIt from 'typeit';
import TypeIt from 'typeit';
```

@@ -83,3 +83,3 @@

Example:
Example:

@@ -123,3 +123,3 @@ ```js

You can modify the options for the plugin by passing in JSON.
You can modify the options for the plugin by passing in JSON.

@@ -147,2 +147,2 @@ There are a number of options you may use to customize TypeIt. For more details on these options, view the <a href="https://typeitjs.com/docs">full documentation</a>.

Please do! The code is available on Github. Spin it up, make a PR, and let's improve TypeIt together!
Please do! The code is available on Github. Check out the [CONTRIBUTING.md](CONTRIBUTING.md) file to see how to get started.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc