Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typeit-react

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typeit-react - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

package-lock.json

8

dist/typeit-react.es.min.js

@@ -5,8 +5,8 @@ /**

* Author: Alex MacArthur <alex@macarthur.me> (https://macarthur.me)
* Version: v0.0.2
* Version: v0.0.3
* License: GPL-2.0
* URL: undefined
* URL: https://typeitjs.com
*
*/
import{createElement as t,useRef as e,useEffect as n,useState as i}from"react";
import{createElement as t,useRef as e,useEffect as n,useState as i,useMemo as r}from"react";
/*! *****************************************************************************

@@ -25,2 +25,2 @@ Copyright (c) Microsoft Corporation. All rights reserved.

and limitations under the License.
***************************************************************************** */var r=function(){return(r=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function o(t){return(o="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})(t)}var s={strings:[],speed:100,cursor:!0,cursorChar:"|",cursorSpeed:1e3,deleteSpeed:null,lifeLike:!0,breakLines:!0,startDelay:250,startDelete:!1,nextStringDelay:750,loop:!1,loopDelay:750,html:!0,waitUntilVisible:!1,beforeString:function(){},afterString:function(){},beforeStep:function(){},afterStep:function(){},afterComplete:function(){}};function u(){var t=this,e=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this.insert=function(e,n){t.waiting.splice(e,0,n)},this.add=function(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return Array.isArray(t[0])?(e.waiting=e.waiting.concat(t),e):(e.waiting[n?"unshift":"push"](t),e)},this.delete=function(e){return t.waiting.splice(e,1),t},this.reset=function(){return t.waiting=t.executed.concat(t.waiting),t.executed=[],t},this.executed=[],this.waiting=n,!n.length&&i&&this.add(i)}var a=function(t){return document.createElement(t)};function c(t,e){return Math.abs(Math.random()*(t+e-(t-e))+(t-e))}function l(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=a("style");n.id=e,n.appendChild(document.createTextNode(t)),document.head.appendChild(n)}function f(t){return t.map((function(t){return t.replace(/<\!--.*?-->/g,"")}))}var h=function(t){return["textarea","input"].indexOf(t.tagName.toLowerCase())>-1},p=function(t){return Array.isArray(t)?t:[t]},d=function(t){return[].slice.call(t)},v=function(t,e){var n=t.nextSibling;return!!n&&!n.isEqualNode(e)},y=function(t,e){var n=e;if(h(t))t.value="".concat(t.value).concat(n);else{var i=d(t.childNodes).filter((function(t){return t.classList&&t.classList.contains("ti-cursor")}));if(i=i.length?i[0]:null,"object"==o(e)&&!(e instanceof HTMLElement)){var r=e.ancestorTree.slice(0).reverse().join(" "),s=d(t.querySelectorAll("".concat(r))),u=(s=s.filter((function(t){return!i||!i.isEqualNode(t)}))).length>0?s[s.length-1]:null;if(u&&function(t,e){if(!t)return!1;for(var n=!1,i=[],r=t;!n;)i.push(v(r,e)),(r=r.parentNode)&&r.hasAttribute&&!r.hasAttribute("data-typeit-id")||(n=!0);return!i.some((function(t){return t}))}(u,i))t=u,n=e.content;else if(n=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",i=a(t);return e.forEach((function(t){i.setAttribute(t.name,t.value)})),i.innerHTML=n,i}(e.ancestorTree[0],e.attributes,e.content),e.ancestorTree.length>1){var c=d(t.querySelectorAll(e.ancestorTree[1]));t=c[c.length-1]}}n="object"==o(n)?n:document.createTextNode(n),t.insertBefore(n,i&&t.hasAttribute("data-typeit-id")?i:null)}},g=function(t){var e=[];return e.concat.apply(e,t)},m=function(t){var e=document.implementation.createHTMLDocument("");return e.body.innerHTML=t,e.body},b=function(t){return d(t.childNodes).map((function(t){return 3===t.nodeType?t.nodeValue.split(""):t}))},w=function(t,e,n){return{ancestorTree:e,attributes:(i=t,d(i.attributes).map((function(t){return{name:t.name,value:t.nodeValue}}))),content:n};var i},S=function(t,e){var n=w(t,e,""),i=b(t).map((function(n,i){return Array.isArray(n)?n.map((function(n,i){return w(t,e,n)})):n}));return i.unshift(n),g(i)},q=function(t){return t instanceof HTMLElement&&"BR"!==t.tagName},A=function t(e){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],i=e.map((function(t){if(q(t)){if(!n)return d(t.childNodes);for(var e=t.parentNode,i=[t.tagName];["BODY","HTML"].indexOf(e.tagName)<0;)i.push(e.tagName),e=e.parentNode;return S(t,i)}return t}));return(i=g(i)).some((function(t){return q(t)}))?t(i,n):i};function T(t){var e=m(t),n=b(e);return A(n)}function N(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return e?T(t):t.split("")}var L=function(t,e){e?t.value="":t.querySelector(".ti-cursor")&&(t.innerHTML="")},x=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=!Array.isArray(t),r=t.length;return(t=i?new Array(t).fill(0):t).map((function(t,o){if(i)return e;var s=[e,t];return n&&(0===o&&s.push({isFirst:!0}),o+1===r&&s.push({isLast:!0})),s}))},O=function(t){t.parentNode.removeChild(t)},E=function(t){return 3!==t.nodeType&&"BR"!==t.tagName&&!t.firstChild},D=function(t){return t.some((function(t){return E(t)}))},$=function(t){for(var e=d(t.querySelectorAll("*")),n=D(e);e.length&&n;){var i=!1;e.forEach((function(t){E(t)&&(O(t),i=!0)})),i&&(e=d(t.querySelectorAll("*"))),n=D(e)}return e},M=function(t){return Array.isArray(t)||(t=[t/2,t/2]),{before:t[0],after:t[1],total:t[0]+t[1]}};function P(t,e,n){var i=(e=null!==e?e:t/3)/2;return n?[c(t,t/2),c(e,i)]:[t,e]}function I(){var t=this,e=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=n.typeIt,r=n.element,c=n.id,v=n.options,g=n.queue,b=void 0===g?[]:g,w=n.isAReset,S=void 0!==w&&w,q=function(){var e=d(t.$e.childNodes).filter((function(t){return!t.isEqualNode(k)}));return A(e,!1)},E=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,i=e.opts.nextStringDelay;e.queue.insert(t,[e.pause,i.before]),e.queue.insert(t+n+1,[e.pause,i.after])},D=function(){!B&&t.opts.cursor&&(l("@keyframes blink-".concat(c," { 0% {opacity: 0} 49% {opacity: 0} 50% {opacity: 1} }[data-typeit-id='").concat(c,"'] .ti-cursor { animation: blink-").concat(c," ").concat(t.opts.cursorSpeed/1e3,"s infinite; }"),c),(k=a("span")).innerHTML=m(t.opts.cursorChar).innerHTML,k.className="ti-cursor",k.setAttribute("style","display:inline;position:relative;font:inherit;color:inherit;line-height:inherit;"),t.$e.appendChild(k))};this.wait=function(t,e){this.timeouts.push(setTimeout(t,e))};var j=function(){t.opts.strings.forEach((function(e,n){var i=N(e,t.opts.html);t.queue.add(x(i,t.type,!0));var r=t.queue.waiting.length;if(n+1!==t.opts.strings.length){if(t.opts.breakLines)return t.queue.add([t.type,a("BR")]),void E(r);t.queue.add(x(i,t.delete)),E(r,e.length)}}))},H=function(e){t.queue.reset().delete(0).add([t.pause,e.before],!0);for(var n=0;n<q().length;n++)t.queue.add([t.delete,null,{isPhantom:!0}],!0)},C=function(e){var n=t.$e.innerHTML;return n?(t.$e.innerHTML="",t.opts.startDelete?(T(n).forEach((function(e){y(t.$e,e)})),t.queue.add([t.delete,!0]),E(1),e):[n.trim()].concat(e)):e};this.pause=function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return new Promise((function(n,i){t.wait((function(){return n()}),e||t.opts.nextStringDelay.total)}))},this.reset=function(){return this.queue.reset(),new I({typeIt:i,element:this.$e,id:c,options:this.opts,queue:this.queue.waiting,isAReset:!0})},this.init=function(){var t=this;if(!this.status.started){if(D(),!this.opts.waitUntilVisible)return this.status.started=!0,this.fire();new IntersectionObserver((function(e,n){e.forEach((function(e){e.isIntersecting&&(t.fire(),n.unobserve(t.$e))}))}),{threshold:1}).observe(this.$e)}},this.fire=function(){for(var t=this,e=this,n=this.queue.waiting.slice(),r=Promise.resolve(),o=function(t){var o=n[t],s=[o,e.queue,i];r=r.then((function(){return new Promise((function(t,n){var i,r;if(e.status.frozen)return n();e.pace=P(e.opts.speed,e.opts.deleteSpeed,e.opts.lifeLike),o[2]&&o[2].isFirst&&(i=e.opts).beforeString.apply(i,s),(r=e.opts).beforeStep.apply(r,s),o[0].call(e,o[1],o[2]).then((function(){var n,i,r=e.queue.waiting.shift();return o[2]&&o[2].isPhantom?t():(o[2]&&o[2].isLast&&(n=e.opts).afterString.apply(n,s),(i=e.opts).afterStep.apply(i,s),e.queue.executed.push(r),t())}))}))}))},s=0;s<n.length;s++)o(s);r.then((function(){if(t.opts.loop){var e=t.opts.loopDelay?t.opts.loopDelay:t.opts.nextStringDelay;t.wait((function(){H(e),t.fire()}),e.after)}t.status.completed=!0,t.opts.afterComplete(i)})).catch((function(){}))},this.type=function(t){var e=this;return"object"!=o(t)||t.content?new Promise((function(n){e.wait((function(){return y(e.$e,t),n()}),e.pace[0])})):(y(this.$e,t),Promise.resolve())},this.empty=function(){var t=this;return new Promise((function(e){return B?t.$e.value="":d(t.$e.childNodes).forEach((function(t){k.isEqualNode(t)||O(t)})),e()}))},this.delete=function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return new Promise((function(n){t.wait((function(){var i=q();return i.length&&O(i[i.length-1]),$(t.$e),e&&i.length-1>0?t.delete(!0).then((function(){return n()})):n()}),t.pace[1])}))},this.setOptions=function(t){var e=this;return new Promise((function(n){return e.opts=Object.assign({},e.opts,t),n()}))};var k=null,B=h(r);this.status={started:!1,complete:!1,frozen:!1,destroyed:!1},this.$e=r,this.timeouts=[],this.opts=Object.assign({},s,v),this.opts.html=!B&&this.opts.html,this.opts.nextStringDelay=M(this.opts.nextStringDelay),this.opts.loopDelay=M(this.opts.loopDelay),this.queue=new u(b,[this.pause,this.opts.startDelay]),this.$e.setAttribute("data-typeit-id",c),l("[data-typeit-id]:before {content: '.'; display: inline-block; width: 0; visibility: hidden;}"),L(r,B);var R=p(this.opts.strings);R=C(R),this.opts.strings=f(R),this.opts.strings.length&&!S&&j()}function j(t,e){var n,i=this,r=this;this.instances=(n=t,"string"==typeof n?n=document.querySelectorAll(n):n.forEach||(n=[n]),d(n)).map((function(t){return new I({typeIt:i,element:t,id:Math.random().toString(36).substring(2,15),options:e,queue:[],isAReset:!1})}));var o=function(t){i.instances.forEach((function(e){t.call(i,e)}))},s=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;o((function(i){var o="string"!=typeof t,s=o?t:i[t],u=x(n,[s,o?r:e]);i.queue.add(u)}))};this.is=function(t){return e=this.instances,n=t,!0,!!e.length&&!e.some((function(t){return!0!==t.status[n]}));var e,n},this.freeze=function(){o((function(t){t.status.frozen=!0}))},this.unfreeze=function(){o((function(t){t.status.frozen&&(t.status.frozen=!1,t.fire())}))},this.type=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return o((function(e){var n=N(t,e.opts.html);e.queue.add(x(n,e.type,!0))})),this},this.delete=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return s("delete",null===t,null===t?1:t),this},this.pause=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return s("pause",t),this},this.break=function(){return s("type",a("BR")),this},this.options=function(t){return s("setOptions",t),this},this.exec=function(t){return s(t),this},this.destroy=function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.instances=this.instances.map((function(e){if(e.timeouts.forEach((function(t){clearTimeout(t)})),e.timeouts=[],t){var n=e.isInput?null:e.$e.querySelector(".ti-cursor");n&&e.$e.removeChild(n)}return e.status.destroyed=!0,e}))},this.empty=function(){return s("empty"),this},this.reset=function(){return this.destroy(),this.instances=this.instances.map((function(t){return t.reset()})),this},this.go=function(){return o((function(t){t.init()})),this}}var H=e,C=n,k=i,B=function(e){var n=k(!0),i=n[0],o=n[1],s=H(null),u=e.options,a=e.element,c=e.children,l=e.getBeforeInit,f=e.getAfterInit,h=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(n[i[r]]=t[i[r]])}return n}(e,["options","element","children","getBeforeInit","getAfterInit"]),p=a;return C((function(){c&&(u.strings=s.current.innerHTML),o(!1)}),[]),C((function(){if(!i){var t=new j(s.current,r({},u));return(t=l(t)).go(),t=f(t),function(){t.destroy()}}}),[i]),t("div",{style:{opacity:i?0:1}},t(p,r({ref:s},h),i&&c))};B.defaultProps={element:"span",options:{},getBeforeInit:function(t){return t},getAfterInit:function(t){return t}};export default B;
***************************************************************************** */var o=function(){return(o=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function s(t){return(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})(t)}var u={strings:[],speed:100,cursor:!0,cursorChar:"|",cursorSpeed:1e3,deleteSpeed:null,lifeLike:!0,breakLines:!0,startDelay:250,startDelete:!1,nextStringDelay:750,loop:!1,loopDelay:750,html:!0,waitUntilVisible:!1,beforeString:function(){},afterString:function(){},beforeStep:function(){},afterStep:function(){},afterComplete:function(){}};function a(){var t=this,e=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this.insert=function(e,n){t.waiting.splice(e,0,n)},this.add=function(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return Array.isArray(t[0])?(e.waiting=e.waiting.concat(t),e):(e.waiting[n?"unshift":"push"](t),e)},this.delete=function(e){return t.waiting.splice(e,1),t},this.reset=function(){return t.waiting=t.executed.concat(t.waiting),t.executed=[],t},this.executed=[],this.waiting=n,!n.length&&i&&this.add(i)}var c=function(t){return document.createElement(t)};function l(t,e){return Math.abs(Math.random()*(t+e-(t-e))+(t-e))}function f(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=c("style");n.id=e,n.appendChild(document.createTextNode(t)),document.head.appendChild(n)}function h(t){return t.map((function(t){return t.replace(/<\!--.*?-->/g,"")}))}var p=function(t){return["textarea","input"].indexOf(t.tagName.toLowerCase())>-1},d=function(t){return Array.isArray(t)?t:[t]},v=function(t){return[].slice.call(t)},y=function(t,e){var n=t.nextSibling;return!!n&&!n.isEqualNode(e)},g=function(t,e){var n=e;if(p(t))t.value="".concat(t.value).concat(n);else{var i=v(t.childNodes).filter((function(t){return t.classList&&t.classList.contains("ti-cursor")}));if(i=i.length?i[0]:null,"object"==s(e)&&!(e instanceof HTMLElement)){var r=e.ancestorTree.slice(0).reverse().join(" "),o=v(t.querySelectorAll("".concat(r))),u=(o=o.filter((function(t){return!i||!i.isEqualNode(t)}))).length>0?o[o.length-1]:null;if(u&&function(t,e){if(!t)return!1;for(var n=!1,i=[],r=t;!n;)i.push(y(r,e)),(r=r.parentNode)&&r.hasAttribute&&!r.hasAttribute("data-typeit-id")||(n=!0);return!i.some((function(t){return t}))}(u,i))t=u,n=e.content;else if(n=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",i=c(t);return e.forEach((function(t){i.setAttribute(t.name,t.value)})),i.innerHTML=n,i}(e.ancestorTree[0],e.attributes,e.content),e.ancestorTree.length>1){var a=v(t.querySelectorAll(e.ancestorTree[1]));t=a[a.length-1]}}n="object"==s(n)?n:document.createTextNode(n),t.insertBefore(n,i&&t.hasAttribute("data-typeit-id")?i:null)}},m=function(t){var e=[];return e.concat.apply(e,t)},b=function(t){var e=document.implementation.createHTMLDocument("");return e.body.innerHTML=t,e.body},w=function(t){return v(t.childNodes).map((function(t){return 3===t.nodeType?t.nodeValue.split(""):t}))},S=function(t,e,n){return{ancestorTree:e,attributes:(i=t,v(i.attributes).map((function(t){return{name:t.name,value:t.nodeValue}}))),content:n};var i},q=function(t,e){var n=S(t,e,""),i=w(t).map((function(n,i){return Array.isArray(n)?n.map((function(n,i){return S(t,e,n)})):n}));return i.unshift(n),m(i)},A=function(t){return t instanceof HTMLElement&&"BR"!==t.tagName},T=function t(e){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],i=e.map((function(t){if(A(t)){if(!n)return v(t.childNodes);for(var e=t.parentNode,i=[t.tagName];["BODY","HTML"].indexOf(e.tagName)<0;)i.push(e.tagName),e=e.parentNode;return q(t,i)}return t}));return(i=m(i)).some((function(t){return A(t)}))?t(i,n):i};function L(t){var e=b(t),n=w(e);return T(n)}function N(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return e?L(t):t.split("")}var x=function(t,e){e?t.value="":t.querySelector(".ti-cursor")&&(t.innerHTML="")},O=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=!Array.isArray(t),r=t.length;return(t=i?new Array(t).fill(0):t).map((function(t,o){if(i)return e;var s=[e,t];return n&&(0===o&&s.push({isFirst:!0}),o+1===r&&s.push({isLast:!0})),s}))},E=function(t){t.parentNode.removeChild(t)},D=function(t){return 3!==t.nodeType&&"BR"!==t.tagName&&!t.firstChild},$=function(t){return t.some((function(t){return D(t)}))},M=function(t){for(var e=v(t.querySelectorAll("*")),n=$(e);e.length&&n;){var i=!1;e.forEach((function(t){D(t)&&(E(t),i=!0)})),i&&(e=v(t.querySelectorAll("*"))),n=$(e)}return e},P=function(t){return Array.isArray(t)||(t=[t/2,t/2]),{before:t[0],after:t[1],total:t[0]+t[1]}};function I(t,e,n){var i=(e=null!==e?e:t/3)/2;return n?[l(t,t/2),l(e,i)]:[t,e]}function j(){var t=this,e=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=n.typeIt,r=n.element,o=n.id,l=n.options,y=n.queue,m=void 0===y?[]:y,w=n.isAReset,S=void 0!==w&&w,q=function(){var e=v(t.$e.childNodes).filter((function(t){return!t.isEqualNode(k)}));return T(e,!1)},A=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,i=e.opts.nextStringDelay;e.queue.insert(t,[e.pause,i.before]),e.queue.insert(t+n+1,[e.pause,i.after])},D=function(){!B&&t.opts.cursor&&(f("@keyframes blink-".concat(o," { 0% {opacity: 0} 49% {opacity: 0} 50% {opacity: 1} }[data-typeit-id='").concat(o,"'] .ti-cursor { animation: blink-").concat(o," ").concat(t.opts.cursorSpeed/1e3,"s infinite; }"),o),(k=c("span")).innerHTML=b(t.opts.cursorChar).innerHTML,k.className="ti-cursor",k.setAttribute("style","display:inline;position:relative;font:inherit;color:inherit;line-height:inherit;"),t.$e.appendChild(k))};this.wait=function(t,e){this.timeouts.push(setTimeout(t,e))};var $=function(){t.opts.strings.forEach((function(e,n){var i=N(e,t.opts.html);t.queue.add(O(i,t.type,!0));var r=t.queue.waiting.length;if(n+1!==t.opts.strings.length){if(t.opts.breakLines)return t.queue.add([t.type,c("BR")]),void A(r);t.queue.add(O(i,t.delete)),A(r,e.length)}}))},C=function(e){t.queue.reset().delete(0).add([t.pause,e.before],!0);for(var n=0;n<q().length;n++)t.queue.add([t.delete,null,{isPhantom:!0}],!0)},H=function(e){var n=t.$e.innerHTML;return n?(t.$e.innerHTML="",t.opts.startDelete?(L(n).forEach((function(e){g(t.$e,e)})),t.queue.add([t.delete,!0]),A(1),e):[n.trim()].concat(e)):e};this.pause=function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return new Promise((function(n,i){t.wait((function(){return n()}),e||t.opts.nextStringDelay.total)}))},this.reset=function(){return this.queue.reset(),new j({typeIt:i,element:this.$e,id:o,options:this.opts,queue:this.queue.waiting,isAReset:!0})},this.init=function(){var t=this;if(!this.status.started){if(D(),!this.opts.waitUntilVisible)return this.status.started=!0,this.fire();new IntersectionObserver((function(e,n){e.forEach((function(e){e.isIntersecting&&(t.fire(),n.unobserve(t.$e))}))}),{threshold:1}).observe(this.$e)}},this.fire=function(){for(var t=this,e=this,n=this.queue.waiting.slice(),r=Promise.resolve(),o=function(t){var o=n[t],s=[o,e.queue,i];r=r.then((function(){return new Promise((function(t,n){var i,r;if(e.status.frozen)return n();e.pace=I(e.opts.speed,e.opts.deleteSpeed,e.opts.lifeLike),o[2]&&o[2].isFirst&&(i=e.opts).beforeString.apply(i,s),(r=e.opts).beforeStep.apply(r,s),o[0].call(e,o[1],o[2]).then((function(){var n,i,r=e.queue.waiting.shift();return o[2]&&o[2].isPhantom?t():(o[2]&&o[2].isLast&&(n=e.opts).afterString.apply(n,s),(i=e.opts).afterStep.apply(i,s),e.queue.executed.push(r),t())}))}))}))},s=0;s<n.length;s++)o(s);r.then((function(){if(t.opts.loop){var e=t.opts.loopDelay?t.opts.loopDelay:t.opts.nextStringDelay;t.wait((function(){C(e),t.fire()}),e.after)}t.status.completed=!0,t.opts.afterComplete(i)})).catch((function(){}))},this.type=function(t){var e=this;return"object"!=s(t)||t.content?new Promise((function(n){e.wait((function(){return g(e.$e,t),n()}),e.pace[0])})):(g(this.$e,t),Promise.resolve())},this.empty=function(){var t=this;return new Promise((function(e){return B?t.$e.value="":v(t.$e.childNodes).forEach((function(t){k.isEqualNode(t)||E(t)})),e()}))},this.delete=function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return new Promise((function(n){t.wait((function(){var i=q();return i.length&&E(i[i.length-1]),M(t.$e),e&&i.length-1>0?t.delete(!0).then((function(){return n()})):n()}),t.pace[1])}))},this.setOptions=function(t){var e=this;return new Promise((function(n){return e.opts=Object.assign({},e.opts,t),n()}))};var k=null,B=p(r);this.status={started:!1,complete:!1,frozen:!1,destroyed:!1},this.$e=r,this.timeouts=[],this.opts=Object.assign({},u,l),this.opts.html=!B&&this.opts.html,this.opts.nextStringDelay=P(this.opts.nextStringDelay),this.opts.loopDelay=P(this.opts.loopDelay),this.queue=new a(m,[this.pause,this.opts.startDelay]),this.$e.setAttribute("data-typeit-id",o),f("[data-typeit-id]:before {content: '.'; display: inline-block; width: 0; visibility: hidden;}"),x(r,B);var R=d(this.opts.strings);R=H(R),this.opts.strings=h(R),this.opts.strings.length&&!S&&$()}function C(t,e){var n,i=this,r=this;this.instances=(n=t,"string"==typeof n?n=document.querySelectorAll(n):n.forEach||(n=[n]),v(n)).map((function(t){return new j({typeIt:i,element:t,id:Math.random().toString(36).substring(2,15),options:e,queue:[],isAReset:!1})}));var o=function(t){i.instances.forEach((function(e){t.call(i,e)}))},s=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;o((function(i){var o="string"!=typeof t,s=o?t:i[t],u=O(n,[s,o?r:e]);i.queue.add(u)}))};this.is=function(t){return e=this.instances,n=t,!0,!!e.length&&!e.some((function(t){return!0!==t.status[n]}));var e,n},this.freeze=function(){o((function(t){t.status.frozen=!0}))},this.unfreeze=function(){o((function(t){t.status.frozen&&(t.status.frozen=!1,t.fire())}))},this.type=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return o((function(e){var n=N(t,e.opts.html);e.queue.add(O(n,e.type,!0))})),this},this.delete=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return s("delete",null===t,null===t?1:t),this},this.pause=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return s("pause",t),this},this.break=function(){return s("type",c("BR")),this},this.options=function(t){return s("setOptions",t),this},this.exec=function(t){return s(t),this},this.destroy=function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.instances=this.instances.map((function(e){if(e.timeouts.forEach((function(t){clearTimeout(t)})),e.timeouts=[],t){var n=e.isInput?null:e.$e.querySelector(".ti-cursor");n&&e.$e.removeChild(n)}return e.status.destroyed=!0,e}))},this.empty=function(){return s("empty"),this},this.reset=function(){return this.destroy(),this.instances=this.instances.map((function(t){return t.reset()})),this},this.go=function(){return o((function(t){t.init()})),this}}var H=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],k=e,B=n,R=i,z=r,V=function(e){var n=R(!0),i=n[0],r=n[1],s=k(null),u=e.options,a=e.element,c=e.children,l=e.getBeforeInit,f=e.getAfterInit,h=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(n[i[r]]=t[i[r]])}return n}(e,["options","element","children","getBeforeInit","getAfterInit"]),p=a,d=z((function(){return t=p,H.indexOf(t.toLowerCase())>-1;var t}),[p]);return B((function(){c&&(u.strings=s.current.innerHTML),r(!1)}),[]),B((function(){if(!i){var t=new C(s.current,o({},u));return(t=l(t)).go(),t=f(t),function(){t.destroy()}}}),[i]),t("div",{style:{opacity:i?0:1}},d?t(p,o({ref:s},h)):t(p,o({ref:s},h),i&&c))};V.defaultProps={element:"span",options:{},getBeforeInit:function(t){return t},getAfterInit:function(t){return t}};export default V;

@@ -5,5 +5,5 @@ /**

* Author: Alex MacArthur <alex@macarthur.me> (https://macarthur.me)
* Version: v0.0.2
* Version: v0.0.3
* License: GPL-2.0
* URL: undefined
* URL: https://typeitjs.com
*

@@ -25,2 +25,2 @@ */

and limitations under the License.
***************************************************************************** */var e=function(){return(e=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function n(t){return(n="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})(t)}var i={strings:[],speed:100,cursor:!0,cursorChar:"|",cursorSpeed:1e3,deleteSpeed:null,lifeLike:!0,breakLines:!0,startDelay:250,startDelete:!1,nextStringDelay:750,loop:!1,loopDelay:750,html:!0,waitUntilVisible:!1,beforeString:function(){},afterString:function(){},beforeStep:function(){},afterStep:function(){},afterComplete:function(){}};function r(){var t=this,e=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this.insert=function(e,n){t.waiting.splice(e,0,n)},this.add=function(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return Array.isArray(t[0])?(e.waiting=e.waiting.concat(t),e):(e.waiting[n?"unshift":"push"](t),e)},this.delete=function(e){return t.waiting.splice(e,1),t},this.reset=function(){return t.waiting=t.executed.concat(t.waiting),t.executed=[],t},this.executed=[],this.waiting=n,!n.length&&i&&this.add(i)}var o=function(t){return document.createElement(t)};function u(t,e){return Math.abs(Math.random()*(t+e-(t-e))+(t-e))}function s(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=o("style");n.id=e,n.appendChild(document.createTextNode(t)),document.head.appendChild(n)}function a(t){return t.map((function(t){return t.replace(/<\!--.*?-->/g,"")}))}var c=function(t){return["textarea","input"].indexOf(t.tagName.toLowerCase())>-1},f=function(t){return Array.isArray(t)?t:[t]},l=function(t){return[].slice.call(t)},h=function(t,e){var n=t.nextSibling;return!!n&&!n.isEqualNode(e)},p=function(t,e){var i=e;if(c(t))t.value="".concat(t.value).concat(i);else{var r=l(t.childNodes).filter((function(t){return t.classList&&t.classList.contains("ti-cursor")}));if(r=r.length?r[0]:null,"object"==n(e)&&!(e instanceof HTMLElement)){var u=e.ancestorTree.slice(0).reverse().join(" "),s=l(t.querySelectorAll("".concat(u))),a=(s=s.filter((function(t){return!r||!r.isEqualNode(t)}))).length>0?s[s.length-1]:null;if(a&&function(t,e){if(!t)return!1;for(var n=!1,i=[],r=t;!n;)i.push(h(r,e)),(r=r.parentNode)&&r.hasAttribute&&!r.hasAttribute("data-typeit-id")||(n=!0);return!i.some((function(t){return t}))}(a,r))t=a,i=e.content;else if(i=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",i=o(t);return e.forEach((function(t){i.setAttribute(t.name,t.value)})),i.innerHTML=n,i}(e.ancestorTree[0],e.attributes,e.content),e.ancestorTree.length>1){var f=l(t.querySelectorAll(e.ancestorTree[1]));t=f[f.length-1]}}i="object"==n(i)?i:document.createTextNode(i),t.insertBefore(i,r&&t.hasAttribute("data-typeit-id")?r:null)}},d=function(t){var e=[];return e.concat.apply(e,t)},v=function(t){var e=document.implementation.createHTMLDocument("");return e.body.innerHTML=t,e.body},y=function(t){return l(t.childNodes).map((function(t){return 3===t.nodeType?t.nodeValue.split(""):t}))},g=function(t,e,n){return{ancestorTree:e,attributes:(i=t,l(i.attributes).map((function(t){return{name:t.name,value:t.nodeValue}}))),content:n};var i},m=function(t,e){var n=g(t,e,""),i=y(t).map((function(n,i){return Array.isArray(n)?n.map((function(n,i){return g(t,e,n)})):n}));return i.unshift(n),d(i)},b=function(t){return t instanceof HTMLElement&&"BR"!==t.tagName},w=function t(e){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],i=e.map((function(t){if(b(t)){if(!n)return l(t.childNodes);for(var e=t.parentNode,i=[t.tagName];["BODY","HTML"].indexOf(e.tagName)<0;)i.push(e.tagName),e=e.parentNode;return m(t,i)}return t}));return(i=d(i)).some((function(t){return b(t)}))?t(i,n):i};function S(t){var e=v(t),n=y(e);return w(n)}function q(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return e?S(t):t.split("")}var A=function(t,e){e?t.value="":t.querySelector(".ti-cursor")&&(t.innerHTML="")},T=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=!Array.isArray(t),r=t.length;return(t=i?new Array(t).fill(0):t).map((function(t,o){if(i)return e;var u=[e,t];return n&&(0===o&&u.push({isFirst:!0}),o+1===r&&u.push({isLast:!0})),u}))},N=function(t){t.parentNode.removeChild(t)},x=function(t){return 3!==t.nodeType&&"BR"!==t.tagName&&!t.firstChild},L=function(t){return t.some((function(t){return x(t)}))},E=function(t){for(var e=l(t.querySelectorAll("*")),n=L(e);e.length&&n;){var i=!1;e.forEach((function(t){x(t)&&(N(t),i=!0)})),i&&(e=l(t.querySelectorAll("*"))),n=L(e)}return e},O=function(t){return Array.isArray(t)||(t=[t/2,t/2]),{before:t[0],after:t[1],total:t[0]+t[1]}};function D(t,e,n){var i=(e=null!==e?e:t/3)/2;return n?[u(t,t/2),u(e,i)]:[t,e]}function $(){var t=this,e=this,u=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},h=u.typeIt,d=u.element,y=u.id,g=u.options,m=u.queue,b=void 0===m?[]:m,x=u.isAReset,L=void 0!==x&&x,M=function(){var e=l(t.$e.childNodes).filter((function(t){return!t.isEqualNode(k)}));return w(e,!1)},P=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,i=e.opts.nextStringDelay;e.queue.insert(t,[e.pause,i.before]),e.queue.insert(t+n+1,[e.pause,i.after])},I=function(){!B&&t.opts.cursor&&(s("@keyframes blink-".concat(y," { 0% {opacity: 0} 49% {opacity: 0} 50% {opacity: 1} }[data-typeit-id='").concat(y,"'] .ti-cursor { animation: blink-").concat(y," ").concat(t.opts.cursorSpeed/1e3,"s infinite; }"),y),(k=o("span")).innerHTML=v(t.opts.cursorChar).innerHTML,k.className="ti-cursor",k.setAttribute("style","display:inline;position:relative;font:inherit;color:inherit;line-height:inherit;"),t.$e.appendChild(k))};this.wait=function(t,e){this.timeouts.push(setTimeout(t,e))};var j=function(){t.opts.strings.forEach((function(e,n){var i=q(e,t.opts.html);t.queue.add(T(i,t.type,!0));var r=t.queue.waiting.length;if(n+1!==t.opts.strings.length){if(t.opts.breakLines)return t.queue.add([t.type,o("BR")]),void P(r);t.queue.add(T(i,t.delete)),P(r,e.length)}}))},H=function(e){t.queue.reset().delete(0).add([t.pause,e.before],!0);for(var n=0;n<M().length;n++)t.queue.add([t.delete,null,{isPhantom:!0}],!0)},C=function(e){var n=t.$e.innerHTML;return n?(t.$e.innerHTML="",t.opts.startDelete?(S(n).forEach((function(e){p(t.$e,e)})),t.queue.add([t.delete,!0]),P(1),e):[n.trim()].concat(e)):e};this.pause=function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return new Promise((function(n,i){t.wait((function(){return n()}),e||t.opts.nextStringDelay.total)}))},this.reset=function(){return this.queue.reset(),new $({typeIt:h,element:this.$e,id:y,options:this.opts,queue:this.queue.waiting,isAReset:!0})},this.init=function(){var t=this;if(!this.status.started){if(I(),!this.opts.waitUntilVisible)return this.status.started=!0,this.fire();new IntersectionObserver((function(e,n){e.forEach((function(e){e.isIntersecting&&(t.fire(),n.unobserve(t.$e))}))}),{threshold:1}).observe(this.$e)}},this.fire=function(){for(var t=this,e=this,n=this.queue.waiting.slice(),i=Promise.resolve(),r=function(t){var r=n[t],o=[r,e.queue,h];i=i.then((function(){return new Promise((function(t,n){var i,u;if(e.status.frozen)return n();e.pace=D(e.opts.speed,e.opts.deleteSpeed,e.opts.lifeLike),r[2]&&r[2].isFirst&&(i=e.opts).beforeString.apply(i,o),(u=e.opts).beforeStep.apply(u,o),r[0].call(e,r[1],r[2]).then((function(){var n,i,u=e.queue.waiting.shift();return r[2]&&r[2].isPhantom?t():(r[2]&&r[2].isLast&&(n=e.opts).afterString.apply(n,o),(i=e.opts).afterStep.apply(i,o),e.queue.executed.push(u),t())}))}))}))},o=0;o<n.length;o++)r(o);i.then((function(){if(t.opts.loop){var e=t.opts.loopDelay?t.opts.loopDelay:t.opts.nextStringDelay;t.wait((function(){H(e),t.fire()}),e.after)}t.status.completed=!0,t.opts.afterComplete(h)})).catch((function(){}))},this.type=function(t){var e=this;return"object"!=n(t)||t.content?new Promise((function(n){e.wait((function(){return p(e.$e,t),n()}),e.pace[0])})):(p(this.$e,t),Promise.resolve())},this.empty=function(){var t=this;return new Promise((function(e){return B?t.$e.value="":l(t.$e.childNodes).forEach((function(t){k.isEqualNode(t)||N(t)})),e()}))},this.delete=function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return new Promise((function(n){t.wait((function(){var i=M();return i.length&&N(i[i.length-1]),E(t.$e),e&&i.length-1>0?t.delete(!0).then((function(){return n()})):n()}),t.pace[1])}))},this.setOptions=function(t){var e=this;return new Promise((function(n){return e.opts=Object.assign({},e.opts,t),n()}))};var k=null,B=c(d);this.status={started:!1,complete:!1,frozen:!1,destroyed:!1},this.$e=d,this.timeouts=[],this.opts=Object.assign({},i,g),this.opts.html=!B&&this.opts.html,this.opts.nextStringDelay=O(this.opts.nextStringDelay),this.opts.loopDelay=O(this.opts.loopDelay),this.queue=new r(b,[this.pause,this.opts.startDelay]),this.$e.setAttribute("data-typeit-id",y),s("[data-typeit-id]:before {content: '.'; display: inline-block; width: 0; visibility: hidden;}"),A(d,B);var R=f(this.opts.strings);R=C(R),this.opts.strings=a(R),this.opts.strings.length&&!L&&j()}function M(t,e){var n,i=this,r=this;this.instances=(n=t,"string"==typeof n?n=document.querySelectorAll(n):n.forEach||(n=[n]),l(n)).map((function(t){return new $({typeIt:i,element:t,id:Math.random().toString(36).substring(2,15),options:e,queue:[],isAReset:!1})}));var u=function(t){i.instances.forEach((function(e){t.call(i,e)}))},s=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;u((function(i){var o="string"!=typeof t,u=o?t:i[t],s=T(n,[u,o?r:e]);i.queue.add(s)}))};this.is=function(t){return e=this.instances,n=t,!0,!!e.length&&!e.some((function(t){return!0!==t.status[n]}));var e,n},this.freeze=function(){u((function(t){t.status.frozen=!0}))},this.unfreeze=function(){u((function(t){t.status.frozen&&(t.status.frozen=!1,t.fire())}))},this.type=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return u((function(e){var n=q(t,e.opts.html);e.queue.add(T(n,e.type,!0))})),this},this.delete=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return s("delete",null===t,null===t?1:t),this},this.pause=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return s("pause",t),this},this.break=function(){return s("type",o("BR")),this},this.options=function(t){return s("setOptions",t),this},this.exec=function(t){return s(t),this},this.destroy=function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.instances=this.instances.map((function(e){if(e.timeouts.forEach((function(t){clearTimeout(t)})),e.timeouts=[],t){var n=e.isInput?null:e.$e.querySelector(".ti-cursor");n&&e.$e.removeChild(n)}return e.status.destroyed=!0,e}))},this.empty=function(){return s("empty"),this},this.reset=function(){return this.destroy(),this.instances=this.instances.map((function(t){return t.reset()})),this},this.go=function(){return u((function(t){t.init()})),this}}var P=t.useRef,I=t.useEffect,j=t.useState,H=function(n){var i=j(!0),r=i[0],o=i[1],u=P(null),s=n.options,a=n.element,c=n.children,f=n.getBeforeInit,l=n.getAfterInit,h=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(n[i[r]]=t[i[r]])}return n}(n,["options","element","children","getBeforeInit","getAfterInit"]),p=a;return I((function(){c&&(s.strings=u.current.innerHTML),o(!1)}),[]),I((function(){if(!r){var t=new M(u.current,e({},s));return(t=f(t)).go(),t=l(t),function(){t.destroy()}}}),[r]),t.createElement("div",{style:{opacity:r?0:1}},t.createElement(p,e({ref:u},h),r&&c))};return H.defaultProps={element:"span",options:{},getBeforeInit:function(t){return t},getAfterInit:function(t){return t}},H}));
***************************************************************************** */var e=function(){return(e=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function n(t){return(n="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})(t)}var i={strings:[],speed:100,cursor:!0,cursorChar:"|",cursorSpeed:1e3,deleteSpeed:null,lifeLike:!0,breakLines:!0,startDelay:250,startDelete:!1,nextStringDelay:750,loop:!1,loopDelay:750,html:!0,waitUntilVisible:!1,beforeString:function(){},afterString:function(){},beforeStep:function(){},afterStep:function(){},afterComplete:function(){}};function r(){var t=this,e=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this.insert=function(e,n){t.waiting.splice(e,0,n)},this.add=function(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return Array.isArray(t[0])?(e.waiting=e.waiting.concat(t),e):(e.waiting[n?"unshift":"push"](t),e)},this.delete=function(e){return t.waiting.splice(e,1),t},this.reset=function(){return t.waiting=t.executed.concat(t.waiting),t.executed=[],t},this.executed=[],this.waiting=n,!n.length&&i&&this.add(i)}var o=function(t){return document.createElement(t)};function u(t,e){return Math.abs(Math.random()*(t+e-(t-e))+(t-e))}function s(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=o("style");n.id=e,n.appendChild(document.createTextNode(t)),document.head.appendChild(n)}function a(t){return t.map((function(t){return t.replace(/<\!--.*?-->/g,"")}))}var c=function(t){return["textarea","input"].indexOf(t.tagName.toLowerCase())>-1},f=function(t){return Array.isArray(t)?t:[t]},l=function(t){return[].slice.call(t)},h=function(t,e){var n=t.nextSibling;return!!n&&!n.isEqualNode(e)},p=function(t,e){var i=e;if(c(t))t.value="".concat(t.value).concat(i);else{var r=l(t.childNodes).filter((function(t){return t.classList&&t.classList.contains("ti-cursor")}));if(r=r.length?r[0]:null,"object"==n(e)&&!(e instanceof HTMLElement)){var u=e.ancestorTree.slice(0).reverse().join(" "),s=l(t.querySelectorAll("".concat(u))),a=(s=s.filter((function(t){return!r||!r.isEqualNode(t)}))).length>0?s[s.length-1]:null;if(a&&function(t,e){if(!t)return!1;for(var n=!1,i=[],r=t;!n;)i.push(h(r,e)),(r=r.parentNode)&&r.hasAttribute&&!r.hasAttribute("data-typeit-id")||(n=!0);return!i.some((function(t){return t}))}(a,r))t=a,i=e.content;else if(i=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",i=o(t);return e.forEach((function(t){i.setAttribute(t.name,t.value)})),i.innerHTML=n,i}(e.ancestorTree[0],e.attributes,e.content),e.ancestorTree.length>1){var f=l(t.querySelectorAll(e.ancestorTree[1]));t=f[f.length-1]}}i="object"==n(i)?i:document.createTextNode(i),t.insertBefore(i,r&&t.hasAttribute("data-typeit-id")?r:null)}},d=function(t){var e=[];return e.concat.apply(e,t)},v=function(t){var e=document.implementation.createHTMLDocument("");return e.body.innerHTML=t,e.body},y=function(t){return l(t.childNodes).map((function(t){return 3===t.nodeType?t.nodeValue.split(""):t}))},m=function(t,e,n){return{ancestorTree:e,attributes:(i=t,l(i.attributes).map((function(t){return{name:t.name,value:t.nodeValue}}))),content:n};var i},g=function(t,e){var n=m(t,e,""),i=y(t).map((function(n,i){return Array.isArray(n)?n.map((function(n,i){return m(t,e,n)})):n}));return i.unshift(n),d(i)},b=function(t){return t instanceof HTMLElement&&"BR"!==t.tagName},w=function t(e){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],i=e.map((function(t){if(b(t)){if(!n)return l(t.childNodes);for(var e=t.parentNode,i=[t.tagName];["BODY","HTML"].indexOf(e.tagName)<0;)i.push(e.tagName),e=e.parentNode;return g(t,i)}return t}));return(i=d(i)).some((function(t){return b(t)}))?t(i,n):i};function S(t){var e=v(t),n=y(e);return w(n)}function q(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return e?S(t):t.split("")}var A=function(t,e){e?t.value="":t.querySelector(".ti-cursor")&&(t.innerHTML="")},T=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=!Array.isArray(t),r=t.length;return(t=i?new Array(t).fill(0):t).map((function(t,o){if(i)return e;var u=[e,t];return n&&(0===o&&u.push({isFirst:!0}),o+1===r&&u.push({isLast:!0})),u}))},x=function(t){t.parentNode.removeChild(t)},L=function(t){return 3!==t.nodeType&&"BR"!==t.tagName&&!t.firstChild},N=function(t){return t.some((function(t){return L(t)}))},E=function(t){for(var e=l(t.querySelectorAll("*")),n=N(e);e.length&&n;){var i=!1;e.forEach((function(t){L(t)&&(x(t),i=!0)})),i&&(e=l(t.querySelectorAll("*"))),n=N(e)}return e},O=function(t){return Array.isArray(t)||(t=[t/2,t/2]),{before:t[0],after:t[1],total:t[0]+t[1]}};function D(t,e,n){var i=(e=null!==e?e:t/3)/2;return n?[u(t,t/2),u(e,i)]:[t,e]}function $(){var t=this,e=this,u=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},h=u.typeIt,d=u.element,y=u.id,m=u.options,g=u.queue,b=void 0===g?[]:g,L=u.isAReset,N=void 0!==L&&L,M=function(){var e=l(t.$e.childNodes).filter((function(t){return!t.isEqualNode(k)}));return w(e,!1)},P=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,i=e.opts.nextStringDelay;e.queue.insert(t,[e.pause,i.before]),e.queue.insert(t+n+1,[e.pause,i.after])},I=function(){!B&&t.opts.cursor&&(s("@keyframes blink-".concat(y," { 0% {opacity: 0} 49% {opacity: 0} 50% {opacity: 1} }[data-typeit-id='").concat(y,"'] .ti-cursor { animation: blink-").concat(y," ").concat(t.opts.cursorSpeed/1e3,"s infinite; }"),y),(k=o("span")).innerHTML=v(t.opts.cursorChar).innerHTML,k.className="ti-cursor",k.setAttribute("style","display:inline;position:relative;font:inherit;color:inherit;line-height:inherit;"),t.$e.appendChild(k))};this.wait=function(t,e){this.timeouts.push(setTimeout(t,e))};var j=function(){t.opts.strings.forEach((function(e,n){var i=q(e,t.opts.html);t.queue.add(T(i,t.type,!0));var r=t.queue.waiting.length;if(n+1!==t.opts.strings.length){if(t.opts.breakLines)return t.queue.add([t.type,o("BR")]),void P(r);t.queue.add(T(i,t.delete)),P(r,e.length)}}))},C=function(e){t.queue.reset().delete(0).add([t.pause,e.before],!0);for(var n=0;n<M().length;n++)t.queue.add([t.delete,null,{isPhantom:!0}],!0)},H=function(e){var n=t.$e.innerHTML;return n?(t.$e.innerHTML="",t.opts.startDelete?(S(n).forEach((function(e){p(t.$e,e)})),t.queue.add([t.delete,!0]),P(1),e):[n.trim()].concat(e)):e};this.pause=function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return new Promise((function(n,i){t.wait((function(){return n()}),e||t.opts.nextStringDelay.total)}))},this.reset=function(){return this.queue.reset(),new $({typeIt:h,element:this.$e,id:y,options:this.opts,queue:this.queue.waiting,isAReset:!0})},this.init=function(){var t=this;if(!this.status.started){if(I(),!this.opts.waitUntilVisible)return this.status.started=!0,this.fire();new IntersectionObserver((function(e,n){e.forEach((function(e){e.isIntersecting&&(t.fire(),n.unobserve(t.$e))}))}),{threshold:1}).observe(this.$e)}},this.fire=function(){for(var t=this,e=this,n=this.queue.waiting.slice(),i=Promise.resolve(),r=function(t){var r=n[t],o=[r,e.queue,h];i=i.then((function(){return new Promise((function(t,n){var i,u;if(e.status.frozen)return n();e.pace=D(e.opts.speed,e.opts.deleteSpeed,e.opts.lifeLike),r[2]&&r[2].isFirst&&(i=e.opts).beforeString.apply(i,o),(u=e.opts).beforeStep.apply(u,o),r[0].call(e,r[1],r[2]).then((function(){var n,i,u=e.queue.waiting.shift();return r[2]&&r[2].isPhantom?t():(r[2]&&r[2].isLast&&(n=e.opts).afterString.apply(n,o),(i=e.opts).afterStep.apply(i,o),e.queue.executed.push(u),t())}))}))}))},o=0;o<n.length;o++)r(o);i.then((function(){if(t.opts.loop){var e=t.opts.loopDelay?t.opts.loopDelay:t.opts.nextStringDelay;t.wait((function(){C(e),t.fire()}),e.after)}t.status.completed=!0,t.opts.afterComplete(h)})).catch((function(){}))},this.type=function(t){var e=this;return"object"!=n(t)||t.content?new Promise((function(n){e.wait((function(){return p(e.$e,t),n()}),e.pace[0])})):(p(this.$e,t),Promise.resolve())},this.empty=function(){var t=this;return new Promise((function(e){return B?t.$e.value="":l(t.$e.childNodes).forEach((function(t){k.isEqualNode(t)||x(t)})),e()}))},this.delete=function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return new Promise((function(n){t.wait((function(){var i=M();return i.length&&x(i[i.length-1]),E(t.$e),e&&i.length-1>0?t.delete(!0).then((function(){return n()})):n()}),t.pace[1])}))},this.setOptions=function(t){var e=this;return new Promise((function(n){return e.opts=Object.assign({},e.opts,t),n()}))};var k=null,B=c(d);this.status={started:!1,complete:!1,frozen:!1,destroyed:!1},this.$e=d,this.timeouts=[],this.opts=Object.assign({},i,m),this.opts.html=!B&&this.opts.html,this.opts.nextStringDelay=O(this.opts.nextStringDelay),this.opts.loopDelay=O(this.opts.loopDelay),this.queue=new r(b,[this.pause,this.opts.startDelay]),this.$e.setAttribute("data-typeit-id",y),s("[data-typeit-id]:before {content: '.'; display: inline-block; width: 0; visibility: hidden;}"),A(d,B);var R=f(this.opts.strings);R=H(R),this.opts.strings=a(R),this.opts.strings.length&&!N&&j()}function M(t,e){var n,i=this,r=this;this.instances=(n=t,"string"==typeof n?n=document.querySelectorAll(n):n.forEach||(n=[n]),l(n)).map((function(t){return new $({typeIt:i,element:t,id:Math.random().toString(36).substring(2,15),options:e,queue:[],isAReset:!1})}));var u=function(t){i.instances.forEach((function(e){t.call(i,e)}))},s=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;u((function(i){var o="string"!=typeof t,u=o?t:i[t],s=T(n,[u,o?r:e]);i.queue.add(s)}))};this.is=function(t){return e=this.instances,n=t,!0,!!e.length&&!e.some((function(t){return!0!==t.status[n]}));var e,n},this.freeze=function(){u((function(t){t.status.frozen=!0}))},this.unfreeze=function(){u((function(t){t.status.frozen&&(t.status.frozen=!1,t.fire())}))},this.type=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return u((function(e){var n=q(t,e.opts.html);e.queue.add(T(n,e.type,!0))})),this},this.delete=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return s("delete",null===t,null===t?1:t),this},this.pause=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return s("pause",t),this},this.break=function(){return s("type",o("BR")),this},this.options=function(t){return s("setOptions",t),this},this.exec=function(t){return s(t),this},this.destroy=function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.instances=this.instances.map((function(e){if(e.timeouts.forEach((function(t){clearTimeout(t)})),e.timeouts=[],t){var n=e.isInput?null:e.$e.querySelector(".ti-cursor");n&&e.$e.removeChild(n)}return e.status.destroyed=!0,e}))},this.empty=function(){return s("empty"),this},this.reset=function(){return this.destroy(),this.instances=this.instances.map((function(t){return t.reset()})),this},this.go=function(){return u((function(t){t.init()})),this}}var P=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],I=t.useRef,j=t.useEffect,C=t.useState,H=t.useMemo,k=function(n){var i=C(!0),r=i[0],o=i[1],u=I(null),s=n.options,a=n.element,c=n.children,f=n.getBeforeInit,l=n.getAfterInit,h=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(n[i[r]]=t[i[r]])}return n}(n,["options","element","children","getBeforeInit","getAfterInit"]),p=a,d=H((function(){return t=p,P.indexOf(t.toLowerCase())>-1;var t}),[p]);return j((function(){c&&(s.strings=u.current.innerHTML),o(!1)}),[]),j((function(){if(!r){var t=new M(u.current,e({},s));return(t=f(t)).go(),t=l(t),function(){t.destroy()}}}),[r]),t.createElement("div",{style:{opacity:r?0:1}},d?t.createElement(p,e({ref:u},h)):t.createElement(p,e({ref:u},h),r&&c))};return k.defaultProps={element:"span",options:{},getBeforeInit:function(t){return t},getAfterInit:function(t){return t}},k}));
{
"name": "typeit-react",
"version": "0.0.2",
"version": "0.0.3",
"description": "React component for the most versatile JavaScript animated typing utility on the planet.",
"homepage": "https://typeitjs.com",
"main": "dist/typeit-react.min.js",

@@ -14,2 +15,7 @@ "module": "dist/typeit-react.es.min.js",

},
"files": [
"dist/",
"src/",
"package-lock.json"
],
"bugs": {

@@ -16,0 +22,0 @@ "url": "https://github.com/alexmacarthur/typeit-react/issues"

@@ -28,5 +28,3 @@ # TypeIt - React

<div className="App">
<TypeIt>
This will be typed in a `span` element!
</TypeIt>
<TypeIt>This will be typed in a `span` element!</TypeIt>
</div>

@@ -45,7 +43,5 @@ );

// This could be any component that generates HTML.
const SuperStrong = ({children}) => {
return (
<strong style={{fontSize: "80px"}}>{children}</strong>
)
}
const SuperStrong = ({ children }) => {
return <strong style={{ fontSize: "80px" }}>{children}</strong>;
};

@@ -103,3 +99,3 @@ export default () => {

TypeIt comes with a set of [special methods](https://typeitjs.com/docs#instance-methods) that let you fine-tune an animation down to the smallest detail. To leverage them here, pass a function as the `onBeforeInit` prop, which will give you access to the instance you can modify with these methods, and then return back to the component before the animation is initialized.
TypeIt comes with a set of [special methods](https://typeitjs.com/docs#instance-methods) that let you fine-tune an animation down to the smallest detail. To leverage them here, pass a function as the `onBeforeInit` prop, which will give you access to the instance you can modify with these methods, and then return back to the component before the animation is initialized.

@@ -109,4 +105,4 @@ ```javascript

<TypeIt
getBeforeInit={(instance) => {
<TypeIt
getBeforeInit={instance => {
instance

@@ -122,3 +118,3 @@ .type("Hi, I'm Alxe")

}}
/>
/>;
```

@@ -135,22 +131,20 @@

const toggleFreeze = () => {
if(instance.is('frozen')) {
const toggleFreeze = () => {
if (instance.is("frozen")) {
instance.unfreeze();
setButtonText('Freeze');
setButtonText("Freeze");
return;
}
}
instance.freeze();
setButtonText('Unfreeze');
}
setButtonText("Unfreeze");
};
return (
<div className="App">
<button onClick={toggleFreeze}>
{buttonText}
</button>
<button onClick={toggleFreeze}>{buttonText}</button>
<TypeIt
<TypeIt
options={{ loop: true }}
getAfterInit={(instance) => {
getAfterInit={instance => {
setInstance(instance);

@@ -164,3 +158,3 @@ return instance;

);
}
};
```

@@ -167,0 +161,0 @@

Sorry, the diff of this file is not supported yet

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