typeit-react
Advanced tools
Comparing version 0.1.0-rc2 to 0.1.0-rc3
@@ -5,3 +5,3 @@ /** | ||
* Author: Alex MacArthur <alex@macarthur.me> (https://macarthur.me) | ||
* Version: v0.1.0-rc2 | ||
* Version: v0.1.0-rc3 | ||
* License: GPL-2.0 | ||
@@ -25,2 +25,2 @@ * URL: https://typeitjs.com | ||
and limitations under the License. | ||
***************************************************************************** */var o=function(){return(o=Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var i in t=arguments[e])Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i]);return n}).apply(this,arguments)};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(){}},c=function(n){return n.map((function(n){return void 0===n[1]&&n.push(null),void 0===n[2]&&n.push({}),n}))},a=function(n,t){return Object.assign({},n,t)},f=function(n){return Array.isArray(n)},s=function(n,t){return n[2]=a(n[2],t)||t,n},l=function(n,t){return f(n[0])?n.map((function(n){return s(n,t)})):s(n,t)},d=function(n,t,e,r){r=r||!1,e=e||{};var i=!f(n),o=n.length;return(n=i?new Array(n).fill(0):n).map((function(n,u){if(i)return t;var c=[t,n,e];return r&&(0===u&&(c=l(c,{isFirst:!0})),u+1===o&&(c=l(c,{isLast:!0}))),c}))};function h(n){this.insert=function(n,e){t.splice(n,0,e)},this.add=function(n,e,r){return n=f(n)?n:[n,null],r=r||!1,e=e||1,f(n[0])||(n=d(e,n)),t=r?n.concat(t):t.concat(n),this},this.delete=function(n){return t.splice(n,1),this},this.reset=function(){return t=c(t).map((function(n){return n[2].executed=!1,n})),this},this.getItems=function(){return c(t).filter((function(n){return!n.executed}))};var t=[];n&&this.add(n)}var p=function(n){return Array.from(n)},v=function(n){var t=[];return t.concat.apply(t,n)},m=function(n){var t=document.implementation.createHTMLDocument("");return t.body.innerHTML=n,t.body},y=function(n){return 3===n.nodeType||"BR"===n.tagName},g=function n(t,e,r){e=e||null,r=void 0!==r&&r;var i=p(t.childNodes).map((function(t){return y(t)?t:n(t)}));return i=v(i),e&&(i=i.filter((function(n){return!n.parentNode.isEqualNode(e)}))),r?i.reverse():i},b=function(n){return"BODY"===n.tagName},S=function(n,t){t=t||null;var e=n instanceof HTMLElement;return{node:t,isTopLevelText:(!t||b(t.parentNode))&&!e,isHTMLElement:e,content:n}};function T(n){var t,e=m(n);return t=g(e).map((function(n){return n.nodeValue?p(n.nodeValue).map((function(t){return S(t,n)})):S(n)})),v(t)}function N(n,t){return(t=void 0===t||t)?T(n):p(n).map((function(n){return S(n)}))}var w=function(n){return document.createElement(n)},L=function(n,t){var e=w("style");e.id=t||"",e.appendChild(document.createTextNode(n)),document.head.appendChild(e)},x=function(n){return f(n)||(n=[n/2,n/2]),{before:n[0],after:n[1],total:n[0]+n[1]}},M=function(n,t){return Math.abs(Math.random()*(n+t-(n-t))+(n-t))},O=function(n){return["textarea","input"].indexOf(n.tagName.toLowerCase())>-1},D=function(n,t){var e=t.querySelectorAll("*");return[t].concat(p(e).reverse()).find((function(t){return t.cloneNode().outerHTML===n.outerHTML}))},E=function(n,t,e,r){e=e||null;var i=t.isHTMLElement,o=i?t.content:document.createTextNode(t.content);if(O(n))n.value="".concat(n.value).concat(t.content);else{if(!t.isTopLevelText&&!i){var u=t.node.parentNode,c=D(u.cloneNode(),n);if(function(n,t){if(!n)return!1;var e=n.nextSibling;return!e||e.isEqualNode(t)}(c,e))n=c;else if((o=u.cloneNode()).innerText=t.content,!b(u.parentNode)){for(var a=u.parentNode,f=a.cloneNode(),s=D(f,n);!s&&!b(a);)f.innerHTML=o.outerHTML,o=f,f=a.parentNode.cloneNode(),a=a.parentNode,s=D(f,n);n=s||n}}var l=g(n,e,!0)[r-1],d=l?l.parentNode:n;d.insertBefore(o,d.contains(e)?e:null)}},P=function(n){return n&&n.parentNode.removeChild(n)},C=function(n){return!n.firstChild&&!y(n)},H=function(n){return n.some((function(n){return C(n)}))},A=function(n,t,e){var r,i="string"==typeof n,o=!1,u=-1*n;return i&&(u=(r="END"===n.toUpperCase())?-1:1,o=r?t+u>0:t+u<e.length),{isString:i,numberOfSteps:u,canKeepMoving:o}};function I(n,t,e){return e?t?t(n):n:(n&&n.then||(n=Promise.resolve(n)),t?n.then(t):n)}function k(n){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];try{return Promise.resolve(n.apply(this,t))}catch(n){return Promise.reject(n)}}}function z(){}function B(n,t){if(!t)return n&&n.then?n.then(z):Promise.resolve()}function j(n,t){var e=n();return e&&e.then?e.then(t):t(e)}function q(n,t,e){if(!n.s){if(e instanceof R){if(!e.s)return void(e.o=q.bind(null,n,t));1&t&&(t=e.s),e=e.v}if(e&&e.then)return void e.then(q.bind(null,n,t),q.bind(null,n,2));n.s=t,n.v=e;var r=n.o;r&&r(n)}}var R=function(){function n(){}return n.prototype.then=function(t,e){var r=new n,i=this.s;if(i){var o=1&i?t:e;if(o){try{q(r,1,o(this.v))}catch(n){q(r,2,n)}return r}return this}return this.o=function(n){try{var i=n.v;1&n.s?q(r,1,t?t(i):i):e?q(r,1,e(i)):q(r,2,i)}catch(n){q(r,2,n)}},r},n}();function V(n,t){return n&&n.then?n.then(t):t(n)}function U(n,t){var e=this,r=this;t=t||{};var i=function(n,t){return cn.add(n,t),e},o=function(n){n=n||{};var t=a({},tn),e=a(t,n);return[[K,e,{force:!0}],[K,t,{force:!0}]]},c=function(){return W?p(J.value):g(J,an,!0)},s=function(n,t){t=t||1;var e=tn.nextStringDelay;cn.insert(n,[D,e.before]),cn.insert(n+t+1,[D,e.after])},l=function(n){an&&(an.classList.toggle("disabled",n),an.classList.toggle("with-delay",!n))},v=k((function(n,t){return Z.push(setTimeout(n,t)),I()})),y=k((function(n){return j((function(){if($)return B(move(-1*$))}),(function(){cn.reset().delete(0).add([D,n.before],!0),c().forEach((function(n){cn.add([Y,null,{isPhantom:!0}],1,!0)}))}))})),b=k((function(){nn.started=!0;var n=cn.getItems();return V(function(n,t){try{var e=n()}catch(n){return t(n)}return e&&e.then?e.then(void 0,t):e}((function(){return V(function(n,t,e){var r,i,o=-1;return function e(u){try{for(;++o<n.length;)if((u=t(o))&&u.then){if(!((c=u)instanceof R&&1&c.s))return void u.then(e,i||(i=q.bind(null,r=new R,2)));u=u.v}r?q(r,1,u):r=u}catch(n){q(r||(r=new R),2,n)}var c}(),r}(n,(function(t){if(nn.frozen||nn.destroyed)throw"";var e,i,o,u,c=n[t],a=c[2],f=[c,cn,r];return a.freezeCursor&&l(!0),e=tn.speed,i=tn.deleteSpeed,o=tn.lifeLike,u=(i=null!==i?i:e/3)/2,X=o?[M(e,e/2),M(i,u)]:[e,i],j((function(){var n;if(null==a?void 0:a.isFirst)return B((n=tn).beforeString.apply(n,f))}),(function(){var n;return I((n=tn).beforeStep.apply(n,f),(function(){return I(c[0].call(r,c[1],a),(function(){return j((function(){if(!a||!a.isPhantom)return j((function(){var n,t;if(null===(n=c[2])||void 0===n?void 0:n.isLast)return B((t=tn).afterString.apply(t,f))}),(function(){var n;return I((n=tn).afterStep.apply(n,f),(function(){c[2].executed=!0}))}))}),(function(){l(!1)}))}))}))}))})),(function(n){return nn.completed=!0,I(tn.afterComplete(r),(function(){if(tn.loop){var n=tn.loopDelay||tn.nextStringDelay;v((function(){return I(y(n),(function(){b()}))}),n.after)}}))}))}),z),(function(n){return r}))})),D=function(n){return new Promise((function(t){v((function(){return t()}),n||tn.nextStringDelay.total)}))},U=function n(t){var e=c(),r=A(t,$,e);return $+=r.numberOfSteps,new Promise((function(t){v(k((function(){return function(n,t,e,r){if(e){var i=r,o=t[(i=i>t.length?t.length:i)-1];(n=o?o.parentNode:n).insertBefore(e,o||null)}}(J,c(),an,$),j((function(){if(r.isString&&r.canKeepMoving)return B(n(r.numberOfSteps>0?"START":"END"))}),(function(){return t()}))})),X[0])}))},F=function(n){return new Promise((function(t){v((function(){return E(J,n,an,$),t()}),X[0])}))},K=k((function(n){tn=a(tn,n)})),Q=k((function(){W?J.value="":c().forEach((function(n){P(n)}))})),Y=function n(t){return t=!0===t,new Promise((function(e){v(k((function(){var r=!1,i=c();return i.length&&(W?J.value=J.value.slice(0,-1):P(i[$])),function(n){for(var t=p(n.querySelectorAll("*")),e=H(t);t.length&&e;){var r=!1;t.forEach((function(n){C(n)&&(P(n),r=!0)})),r&&(t=p(n.querySelectorAll("*"))),e=H(t)}}(J),j((function(){if(t&&i.length-1>0)return I(n(!0),(function(){return r=!0,e()}))}),(function(n){return r?n:e()}))})),X[1])}))};this.break=function(){return i([F,S(w("BR"))])},this.delete=function(n,t){var e=o(t);return cn.add(e[0]),cn.add([Y,!n,_],n||1),cn.add(e[1]),this},this.destroy=function(n){n=void 0===n||n,Z.forEach((function(n){clearTimeout(n)})),Z=[],n&&P(an),nn.destroyed=!0},this.empty=function(){return i(Q)},this.exec=function(n,t){var e=o(t);return i([e[0],[n,null],e[1]])},this.is=function(n){return nn[n]},this.move=function(n,t){var e=A(n,$,c()),r=o(t);return cn.add(r[0]),cn.add([U,e.isString?n:Math.sign(n),_],Math.abs(n)),cn.add(r[1]),this},this.freeze=function(){nn.frozen=!0},this.unfreeze=function(){nn.frozen=!1,!nn.frozen&&b()},this.options=function(n){return i([K,n])},this.pause=function(n){return i([D,n||null])},this.type=function(n,t){var e=o(t),r=N(n,tn.html),u=[e[0]].concat(d(r,F,_,!0),[e[1]]);return i(u)},this.getQueue=function(){return cn},this.getOptions=function(){return tn},this.reset=function(){for(var n in!this.is("destroyed")&&this.destroy(),cn.reset(),nn)nn[n]=!1;return this},this.go=function(){return nn.started?this:(function(){if(an){var n="[data-typeit-id='".concat(un,"'] .ti-cursor");L("@keyframes blink-".concat(un," { 0% {opacity: 0} 49% {opacity: 0} 50% {opacity: 1} } ").concat(n," { animation: blink-").concat(un," ").concat(tn.cursorSpeed/1e3,"s infinite; } ").concat(n,".with-delay { animation-delay: 500ms; } ").concat(n,".disabled { animation: none; }"),un),J.appendChild(an)}}(),tn.waitUntilVisible?(function(n,t){new IntersectionObserver((function(e,r){e.forEach((function(e){e.isIntersecting&&(t(),r.unobserve(n))}))}),{threshold:1}).observe(n)}(J,b.bind(this)),this):(b(),this))};var G,J="string"==typeof(G=n)?document.querySelector(G):G,W=O(J),X=[],Z=[],$=0,_={freezeCursor:!0},nn={started:!1,completed:!1,frozen:!1,destroyed:!1},tn=a(u,t);tn=a(tn,{html:!W&&tn.html,nextStringDelay:x(tn.nextStringDelay),loopDelay:x(tn.loopDelay)});var en,rn,on,un=Math.random().toString().substring(2,9),cn=new h([D,tn.startDelay]);J.setAttribute("data-typeit-id",un),L("[data-typeit-id]:before {content: '.'; display: inline-block; width: 0; visibility: hidden;}"),tn.strings=(on=tn.strings,en=f(on)?on:[on],(rn=function(n){return n.innerHTML.replace(/<\!--.*?-->/g,"").trim()}(J))?(J.innerHTML="",tn.startDelete?(T(rn).forEach((function(n){E(J,n,an,$)})),cn.add([Y,!0]),s(1),en):[rn.trim()].concat(en)):en);var an=function(){if(W||!tn.cursor)return null;var n=w("span");return n.innerHTML=m(tn.cursorChar).innerHTML,n.className="ti-cursor",n.style.cssText="position:absolute;display:inline;margin-left:-.025em;".concat(function(n){var t=["font","lineHeight","color"],e=w("SPAN"),r=window.getComputedStyle(n,null);for(var i in r)t.indexOf(i)>-1&&r[i]&&(e.style[i]=r[i]);return e.style.cssText}(J)),n}();tn.strings.length&&function(){var n=tn.strings;n.forEach((function(t,e){var r=N(t,tn.html);cn.add(d(r,F,_,!0));var i=cn.getItems().length;if(e+1!==n.length){if(tn.breakLines){var o=S(w("BR"));return cn.add([F,o,_]),void s(i)}cn.add(d(r,Y,_)),s(i,t.length)}}))}()}var F=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],K=t,Q=e,Y=r,G=i,J=function(t){var e=Y(!0),r=e[0],i=e[1],u=K(null),c=t.options,a=t.element,f=t.children,s=t.getBeforeInit,l=t.getAfterInit,d=function(n,t){var e={};for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&t.indexOf(r)<0&&(e[r]=n[r]);if(null!=n&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(n);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(n,r[i])&&(e[r[i]]=n[r[i]])}return e}(t,["options","element","children","getBeforeInit","getAfterInit"]),h=a,p=G((function(){return n=h,F.indexOf(n.toLowerCase())>-1;var n}),[h]);return Q((function(){f&&(c.strings=u.current.innerHTML),i(!1)}),[]),Q((function(){if(!r){var n=new U(u.current,o({},c));return(n=s(n)).go(),n=l(n),function(){n.destroy()}}}),[r]),n("div",{style:{opacity:r?0:1}},p?n(h,o({ref:u},d)):n(h,o({ref:u},d),r&&f))};J.defaultProps={element:"span",options:{},getBeforeInit:function(n){return n},getAfterInit:function(n){return n}};export default J; | ||
***************************************************************************** */var o=function(){return(o=Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var i in t=arguments[e])Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i]);return n}).apply(this,arguments)};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(){}},c=function(n){return n.map((function(n){return void 0===n[1]&&n.push(null),void 0===n[2]&&n.push({}),n}))},a=function(n,t){return Object.assign({},n,t)},f=function(n){return Array.isArray(n)},s=function(n,t){return n[2]=a(n[2],t)||t,n},l=function(n,t){return f(n[0])?n.map((function(n){return s(n,t)})):s(n,t)},d=function(n,t,e,r){r=r||!1,e=e||{};var i=!f(n),o=n.length;return(n=i?new Array(n).fill(0):n).map((function(n,u){if(i)return t;var c=[t,n,e];return r&&(0===u&&(c=l(c,{isFirst:!0})),u+1===o&&(c=l(c,{isLast:!0}))),c}))};function h(n){this.insert=function(n,e){t.splice(n,0,e)},this.add=function(n,e,r){return n=f(n)?n:[n,null],r=r||!1,e=e||1,f(n[0])||(n=d(e,n)),t=r?n.concat(t):t.concat(n),this},this.delete=function(n){return t.splice(n,1),this},this.reset=function(){return t=c(t).map((function(n){return n[2].executed=!1,n})),this},this.getItems=function(){return c(t).filter((function(n){return!n.executed}))};var t=[];n&&this.add(n)}var p=function(n){return Array.from(n)},v=function(n){var t=[];return t.concat.apply(t,n)},m=function(n){var t=document.implementation.createHTMLDocument("");return t.body.innerHTML=n,t.body},y=function(n){return 3===n.nodeType||"BR"===n.tagName},g=function n(t,e,r){e=e||null,r=void 0!==r&&r;var i=p(t.childNodes).map((function(t){return y(t)?t:n(t)}));return i=v(i),e&&(i=i.filter((function(n){return!n.parentNode.isEqualNode(e)}))),r?i.reverse():i},b=function(n){return"BODY"===n.tagName},S=function(n,t){t=t||null;var e=n instanceof HTMLElement;return{node:t,isTopLevelText:(!t||b(t.parentNode))&&!e,isHTMLElement:e,content:n}};function T(n){var t,e=m(n);return t=g(e).map((function(n){return n.nodeValue?p(n.nodeValue).map((function(t){return S(t,n)})):S(n)})),v(t)}function N(n,t){return(t=void 0===t||t)?T(n):p(n).map((function(n){return S(n)}))}var w=function(n){return document.createElement(n)},L=function(n,t){var e=w("style");e.id=t||"",e.appendChild(document.createTextNode(n)),document.head.appendChild(e)},x=function(n){return f(n)||(n=[n/2,n/2]),{before:n[0],after:n[1],total:n[0]+n[1]}},M=function(n,t){return Math.abs(Math.random()*(n+t-(n-t))+(n-t))},O=function(n){return["textarea","input"].indexOf(n.tagName.toLowerCase())>-1},D=function(n,t){var e=t.querySelectorAll("*");return[t].concat(p(e).reverse()).find((function(t){return t.cloneNode().outerHTML===n.outerHTML}))},E=function(n,t,e,r){e=e||null;var i=t.isHTMLElement,o=i?t.content:document.createTextNode(t.content);if(O(n))n.value="".concat(n.value).concat(t.content);else{if(!t.isTopLevelText&&!i){var u=t.node.parentNode,c=D(u.cloneNode(),n);if(function(n,t){if(!n)return!1;var e=n.nextSibling;return!e||e.isEqualNode(t)}(c,e))n=c;else if((o=u.cloneNode()).innerText=t.content,!b(u.parentNode)){for(var a=u.parentNode,f=a.cloneNode(),s=D(f,n);!s&&!b(a);)f.innerHTML=o.outerHTML,o=f,f=a.parentNode.cloneNode(),a=a.parentNode,s=D(f,n);n=s||n}}var l=g(n,e,!0)[r-1],d=l?l.parentNode:n;d.insertBefore(o,d.contains(e)?e:null)}},P=function(n){return n&&n.parentNode.removeChild(n)},C=function(n){return!n.firstChild&&!y(n)},H=function(n){return n.some((function(n){return C(n)}))},A=function(n,t,e){var r,i="string"==typeof n,o=!1,u=-1*n;return i&&(u=(r="END"===n.toUpperCase())?-1:1,o=r?t+u>0:t+u<e.length),{isString:i,numberOfSteps:u,canKeepMoving:o}};function I(n,t,e){return e?t?t(n):n:(n&&n.then||(n=Promise.resolve(n)),t?n.then(t):n)}function k(n){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];try{return Promise.resolve(n.apply(this,t))}catch(n){return Promise.reject(n)}}}function z(){}function B(n,t){if(!t)return n&&n.then?n.then(z):Promise.resolve()}function j(n,t){var e=n();return e&&e.then?e.then(t):t(e)}function q(n,t,e){if(!n.s){if(e instanceof R){if(!e.s)return void(e.o=q.bind(null,n,t));1&t&&(t=e.s),e=e.v}if(e&&e.then)return void e.then(q.bind(null,n,t),q.bind(null,n,2));n.s=t,n.v=e;var r=n.o;r&&r(n)}}var R=function(){function n(){}return n.prototype.then=function(t,e){var r=new n,i=this.s;if(i){var o=1&i?t:e;if(o){try{q(r,1,o(this.v))}catch(n){q(r,2,n)}return r}return this}return this.o=function(n){try{var i=n.v;1&n.s?q(r,1,t?t(i):i):e?q(r,1,e(i)):q(r,2,i)}catch(n){q(r,2,n)}},r},n}();function V(n,t){return n&&n.then?n.then(t):t(n)}function U(n,t){var e=this,r=this;t=t||{};var i=function(n,t){return cn.add(n,t),e},o=function(n){n=n||{};var t=a({},tn),e=a(t,n);return[[K,e,{force:!0}],[K,t,{force:!0}]]},c=function(){return W?p(J.value):g(J,an,!0)},s=function(n,t){t=t||1;var e=tn.nextStringDelay;cn.insert(n,[D,e.before]),cn.insert(n+t+1,[D,e.after])},l=function(n){an&&(an.classList.toggle("disabled",n),an.classList.toggle("with-delay",!n))},v=k((function(n,t){return Z.push(setTimeout(n,t)),I()})),y=k((function(n){return j((function(){if($)return B(move(-1*$))}),(function(){cn.reset().delete(0).add([D,n.before],!0),c().forEach((function(n){cn.add([Y,null,{isPhantom:!0}],1,!0)}))}))})),b=k((function(){nn.started=!0;var n=cn.getItems();return V(function(n,t){try{var e=n()}catch(n){return t(n)}return e&&e.then?e.then(void 0,t):e}((function(){return V(function(n,t,e){var r,i,o=-1;return function e(u){try{for(;++o<n.length;)if((u=t(o))&&u.then){if(!((c=u)instanceof R&&1&c.s))return void u.then(e,i||(i=q.bind(null,r=new R,2)));u=u.v}r?q(r,1,u):r=u}catch(n){q(r||(r=new R),2,n)}var c}(),r}(n,(function(t){if(nn.frozen||nn.destroyed)throw"";var e,i,o,u,c=n[t],a=c[2],f=[c,r];return a.freezeCursor&&l(!0),e=tn.speed,i=tn.deleteSpeed,o=tn.lifeLike,u=(i=null!==i?i:e/3)/2,X=o?[M(e,e/2),M(i,u)]:[e,i],j((function(){var n;if(null==a?void 0:a.isFirst)return B((n=tn).beforeString.apply(n,f))}),(function(){var n;return I((n=tn).beforeStep.apply(n,f),(function(){return I(c[0].call(r,c[1],a),(function(){return j((function(){if(!a||!a.isPhantom)return j((function(){var n,t;if(null===(n=c[2])||void 0===n?void 0:n.isLast)return B((t=tn).afterString.apply(t,f))}),(function(){var n;return I((n=tn).afterStep.apply(n,f),(function(){c[2].executed=!0}))}))}),(function(){l(!1)}))}))}))}))})),(function(n){return nn.completed=!0,I(tn.afterComplete(r),(function(){if(tn.loop){var n=tn.loopDelay||tn.nextStringDelay;v((function(){return I(y(n),(function(){b()}))}),n.after)}}))}))}),z),(function(n){return r}))})),D=function(n){return new Promise((function(t){v((function(){return t()}),n||tn.nextStringDelay.total)}))},U=function n(t){var e=c(),r=A(t,$,e);return $+=r.numberOfSteps,new Promise((function(t){v(k((function(){return function(n,t,e,r){if(e){var i=r,o=t[(i=i>t.length?t.length:i)-1];(n=o?o.parentNode:n).insertBefore(e,o||null)}}(J,c(),an,$),j((function(){if(r.isString&&r.canKeepMoving)return B(n(r.numberOfSteps>0?"START":"END"))}),(function(){return t()}))})),X[0])}))},F=function(n){return new Promise((function(t){v((function(){return E(J,n,an,$),t()}),X[0])}))},K=k((function(n){tn=a(tn,n)})),Q=k((function(){W?J.value="":c().forEach((function(n){P(n)}))})),Y=function n(t){return t=!0===t,new Promise((function(e){v(k((function(){var r=!1,i=c();return i.length&&(W?J.value=J.value.slice(0,-1):P(i[$])),function(n){for(var t=p(n.querySelectorAll("*")),e=H(t);t.length&&e;){var r=!1;t.forEach((function(n){C(n)&&(P(n),r=!0)})),r&&(t=p(n.querySelectorAll("*"))),e=H(t)}}(J),j((function(){if(t&&i.length-1>0)return I(n(!0),(function(){return r=!0,e()}))}),(function(n){return r?n:e()}))})),X[1])}))};this.break=function(){return i([F,S(w("BR"))])},this.delete=function(n,t){var e=o(t);return cn.add(e[0]),cn.add([Y,!n,_],n||1),cn.add(e[1]),this},this.destroy=function(n){n=void 0===n||n,Z.forEach((function(n){clearTimeout(n)})),Z=[],n&&P(an),nn.destroyed=!0},this.empty=function(){return i(Q)},this.exec=function(n,t){var e=o(t);return i([e[0],[n,null],e[1]])},this.is=function(n){return nn[n]},this.move=function(n,t){var e=A(n,$,c()),r=o(t);return cn.add(r[0]),cn.add([U,e.isString?n:Math.sign(n),_],Math.abs(n)),cn.add(r[1]),this},this.freeze=function(){nn.frozen=!0},this.unfreeze=function(){nn.frozen=!1,!nn.frozen&&b()},this.options=function(n){return i([K,n])},this.pause=function(n){return i([D,n||null])},this.type=function(n,t){var e=o(t),r=N(n,tn.html),u=[e[0]].concat(d(r,F,_,!0),[e[1]]);return i(u)},this.getQueue=function(){return cn},this.getOptions=function(){return tn},this.getElement=function(){return J},this.reset=function(){for(var n in!this.is("destroyed")&&this.destroy(),cn.reset(),nn)nn[n]=!1;return this},this.go=function(){return nn.started?this:(function(){if(an){var n="[data-typeit-id='".concat(un,"'] .ti-cursor");L("@keyframes blink-".concat(un," { 0% {opacity: 0} 49% {opacity: 0} 50% {opacity: 1} } ").concat(n," { animation: blink-").concat(un," ").concat(tn.cursorSpeed/1e3,"s infinite; } ").concat(n,".with-delay { animation-delay: 500ms; } ").concat(n,".disabled { animation: none; }"),un),J.appendChild(an)}}(),tn.waitUntilVisible?(function(n,t){new IntersectionObserver((function(e,r){e.forEach((function(e){e.isIntersecting&&(t(),r.unobserve(n))}))}),{threshold:1}).observe(n)}(J,b.bind(this)),this):(b(),this))};var G,J="string"==typeof(G=n)?document.querySelector(G):G,W=O(J),X=[],Z=[],$=0,_={freezeCursor:!0},nn={started:!1,completed:!1,frozen:!1,destroyed:!1},tn=a(u,t);tn=a(tn,{html:!W&&tn.html,nextStringDelay:x(tn.nextStringDelay),loopDelay:x(tn.loopDelay)});var en,rn,on,un=Math.random().toString().substring(2,9),cn=new h([D,tn.startDelay]);J.setAttribute("data-typeit-id",un),L("[data-typeit-id]:before {content: '.'; display: inline-block; width: 0; visibility: hidden;}"),tn.strings=(on=tn.strings,en=f(on)?on:[on],(rn=function(n){return n.innerHTML.replace(/<\!--.*?-->/g,"").trim()}(J))?(J.innerHTML="",tn.startDelete?(T(rn).forEach((function(n){E(J,n,an,$)})),cn.add([Y,!0]),s(1),en):[rn.trim()].concat(en)):en);var an=function(){if(W||!tn.cursor)return null;var n=w("span");return n.innerHTML=m(tn.cursorChar).innerHTML,n.className="ti-cursor",n.style.cssText="position:absolute;display:inline;margin-left:-.025em;".concat(function(n){var t=["font","lineHeight","color"],e=w("SPAN"),r=window.getComputedStyle(n,null);for(var i in r)t.indexOf(i)>-1&&r[i]&&(e.style[i]=r[i]);return e.style.cssText}(J)),n}();tn.strings.length&&function(){var n=tn.strings;n.forEach((function(t,e){var r=N(t,tn.html);cn.add(d(r,F,_,!0));var i=cn.getItems().length;if(e+1!==n.length){if(tn.breakLines){var o=S(w("BR"));return cn.add([F,o,_]),void s(i)}cn.add(d(r,Y,_)),s(i,t.length)}}))}()}var F=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],K=t,Q=e,Y=r,G=i,J=function(t){var e=Y(!0),r=e[0],i=e[1],u=K(null),c=t.options,a=t.element,f=t.children,s=t.getBeforeInit,l=t.getAfterInit,d=function(n,t){var e={};for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&t.indexOf(r)<0&&(e[r]=n[r]);if(null!=n&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(n);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(n,r[i])&&(e[r[i]]=n[r[i]])}return e}(t,["options","element","children","getBeforeInit","getAfterInit"]),h=a,p=G((function(){return n=h,F.indexOf(n.toLowerCase())>-1;var n}),[h]);return Q((function(){f&&(c.strings=u.current.innerHTML),i(!1)}),[]),Q((function(){if(!r){var n=new U(u.current,o({},c));return(n=s(n)).go(),n=l(n),function(){n.destroy()}}}),[r]),n("div",{style:{opacity:r?0:1}},p?n(h,o({ref:u},d)):n(h,o({ref:u},d),r&&f))};J.defaultProps={element:"span",options:{},getBeforeInit:function(n){return n},getAfterInit:function(n){return n}};export default J; |
@@ -5,3 +5,3 @@ /** | ||
* Author: Alex MacArthur <alex@macarthur.me> (https://macarthur.me) | ||
* Version: v0.1.0-rc2 | ||
* Version: v0.1.0-rc3 | ||
* License: GPL-2.0 | ||
@@ -25,2 +25,2 @@ * URL: https://typeitjs.com | ||
and limitations under the License. | ||
***************************************************************************** */var t=function(){return(t=Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var i in t=arguments[e])Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i]);return n}).apply(this,arguments)};var e={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(){}},r=function(n){return n.map((function(n){return void 0===n[1]&&n.push(null),void 0===n[2]&&n.push({}),n}))},i=function(n,t){return Object.assign({},n,t)},o=function(n){return Array.isArray(n)},u=function(n,t){return n[2]=i(n[2],t)||t,n},c=function(n,t){return o(n[0])?n.map((function(n){return u(n,t)})):u(n,t)},a=function(n,t,e,r){r=r||!1,e=e||{};var i=!o(n),u=n.length;return(n=i?new Array(n).fill(0):n).map((function(n,o){if(i)return t;var a=[t,n,e];return r&&(0===o&&(a=c(a,{isFirst:!0})),o+1===u&&(a=c(a,{isLast:!0}))),a}))};function f(n){this.insert=function(n,e){t.splice(n,0,e)},this.add=function(n,e,r){return n=o(n)?n:[n,null],r=r||!1,e=e||1,o(n[0])||(n=a(e,n)),t=r?n.concat(t):t.concat(n),this},this.delete=function(n){return t.splice(n,1),this},this.reset=function(){return t=r(t).map((function(n){return n[2].executed=!1,n})),this},this.getItems=function(){return r(t).filter((function(n){return!n.executed}))};var t=[];n&&this.add(n)}var s=function(n){return Array.from(n)},l=function(n){var t=[];return t.concat.apply(t,n)},d=function(n){var t=document.implementation.createHTMLDocument("");return t.body.innerHTML=n,t.body},p=function(n){return 3===n.nodeType||"BR"===n.tagName},h=function n(t,e,r){e=e||null,r=void 0!==r&&r;var i=s(t.childNodes).map((function(t){return p(t)?t:n(t)}));return i=l(i),e&&(i=i.filter((function(n){return!n.parentNode.isEqualNode(e)}))),r?i.reverse():i},v=function(n){return"BODY"===n.tagName},m=function(n,t){t=t||null;var e=n instanceof HTMLElement;return{node:t,isTopLevelText:(!t||v(t.parentNode))&&!e,isHTMLElement:e,content:n}};function y(n){var t,e=d(n);return t=h(e).map((function(n){return n.nodeValue?s(n.nodeValue).map((function(t){return m(t,n)})):m(n)})),l(t)}function g(n,t){return(t=void 0===t||t)?y(n):s(n).map((function(n){return m(n)}))}var b=function(n){return document.createElement(n)},S=function(n,t){var e=b("style");e.id=t||"",e.appendChild(document.createTextNode(n)),document.head.appendChild(e)},T=function(n){return o(n)||(n=[n/2,n/2]),{before:n[0],after:n[1],total:n[0]+n[1]}},N=function(n,t){return Math.abs(Math.random()*(n+t-(n-t))+(n-t))},w=function(n){return["textarea","input"].indexOf(n.tagName.toLowerCase())>-1},x=function(n,t){var e=t.querySelectorAll("*");return[t].concat(s(e).reverse()).find((function(t){return t.cloneNode().outerHTML===n.outerHTML}))},L=function(n,t,e,r){e=e||null;var i=t.isHTMLElement,o=i?t.content:document.createTextNode(t.content);if(w(n))n.value="".concat(n.value).concat(t.content);else{if(!t.isTopLevelText&&!i){var u=t.node.parentNode,c=x(u.cloneNode(),n);if(function(n,t){if(!n)return!1;var e=n.nextSibling;return!e||e.isEqualNode(t)}(c,e))n=c;else if((o=u.cloneNode()).innerText=t.content,!v(u.parentNode)){for(var a=u.parentNode,f=a.cloneNode(),s=x(f,n);!s&&!v(a);)f.innerHTML=o.outerHTML,o=f,f=a.parentNode.cloneNode(),a=a.parentNode,s=x(f,n);n=s||n}}var l=h(n,e,!0)[r-1],d=l?l.parentNode:n;d.insertBefore(o,d.contains(e)?e:null)}},M=function(n){return n&&n.parentNode.removeChild(n)},O=function(n){return!n.firstChild&&!p(n)},E=function(n){return n.some((function(n){return O(n)}))},D=function(n,t,e){var r,i="string"==typeof n,o=!1,u=-1*n;return i&&(u=(r="END"===n.toUpperCase())?-1:1,o=r?t+u>0:t+u<e.length),{isString:i,numberOfSteps:u,canKeepMoving:o}};function P(n,t,e){return e?t?t(n):n:(n&&n.then||(n=Promise.resolve(n)),t?n.then(t):n)}function C(n){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];try{return Promise.resolve(n.apply(this,t))}catch(n){return Promise.reject(n)}}}function H(){}function A(n,t){if(!t)return n&&n.then?n.then(H):Promise.resolve()}function I(n,t){var e=n();return e&&e.then?e.then(t):t(e)}function k(n,t,e){if(!n.s){if(e instanceof j){if(!e.s)return void(e.o=k.bind(null,n,t));1&t&&(t=e.s),e=e.v}if(e&&e.then)return void e.then(k.bind(null,n,t),k.bind(null,n,2));n.s=t,n.v=e;var r=n.o;r&&r(n)}}var j=function(){function n(){}return n.prototype.then=function(t,e){var r=new n,i=this.s;if(i){var o=1&i?t:e;if(o){try{k(r,1,o(this.v))}catch(n){k(r,2,n)}return r}return this}return this.o=function(n){try{var i=n.v;1&n.s?k(r,1,t?t(i):i):e?k(r,1,e(i)):k(r,2,i)}catch(n){k(r,2,n)}},r},n}();function z(n,t){return n&&n.then?n.then(t):t(n)}function B(n,t){var r=this,u=this;t=t||{};var c=function(n,t){return cn.add(n,t),r},l=function(n){n=n||{};var t=i({},tn),e=i(t,n);return[[K,e,{force:!0}],[K,t,{force:!0}]]},p=function(){return W?s(J.value):h(J,an,!0)},v=function(n,t){t=t||1;var e=tn.nextStringDelay;cn.insert(n,[V,e.before]),cn.insert(n+t+1,[V,e.after])},x=function(n){an&&(an.classList.toggle("disabled",n),an.classList.toggle("with-delay",!n))},B=C((function(n,t){return Z.push(setTimeout(n,t)),P()})),q=C((function(n){return I((function(){if($)return A(move(-1*$))}),(function(){cn.reset().delete(0).add([V,n.before],!0),p().forEach((function(n){cn.add([Y,null,{isPhantom:!0}],1,!0)}))}))})),R=C((function(){nn.started=!0;var n=cn.getItems();return z(function(n,t){try{var e=n()}catch(n){return t(n)}return e&&e.then?e.then(void 0,t):e}((function(){return z(function(n,t,e){var r,i,o=-1;return function e(u){try{for(;++o<n.length;)if((u=t(o))&&u.then){if(!((c=u)instanceof j&&1&c.s))return void u.then(e,i||(i=k.bind(null,r=new j,2)));u=u.v}r?k(r,1,u):r=u}catch(n){k(r||(r=new j),2,n)}var c}(),r}(n,(function(t){if(nn.frozen||nn.destroyed)throw"";var e,r,i,o,c=n[t],a=c[2],f=[c,cn,u];return a.freezeCursor&&x(!0),e=tn.speed,r=tn.deleteSpeed,i=tn.lifeLike,o=(r=null!==r?r:e/3)/2,X=i?[N(e,e/2),N(r,o)]:[e,r],I((function(){var n;if(null==a?void 0:a.isFirst)return A((n=tn).beforeString.apply(n,f))}),(function(){var n;return P((n=tn).beforeStep.apply(n,f),(function(){return P(c[0].call(u,c[1],a),(function(){return I((function(){if(!a||!a.isPhantom)return I((function(){var n,t;if(null===(n=c[2])||void 0===n?void 0:n.isLast)return A((t=tn).afterString.apply(t,f))}),(function(){var n;return P((n=tn).afterStep.apply(n,f),(function(){c[2].executed=!0}))}))}),(function(){x(!1)}))}))}))}))})),(function(n){return nn.completed=!0,P(tn.afterComplete(u),(function(){if(tn.loop){var n=tn.loopDelay||tn.nextStringDelay;B((function(){return P(q(n),(function(){R()}))}),n.after)}}))}))}),H),(function(n){return u}))})),V=function(n){return new Promise((function(t){B((function(){return t()}),n||tn.nextStringDelay.total)}))},U=function n(t){var e=p(),r=D(t,$,e);return $+=r.numberOfSteps,new Promise((function(t){B(C((function(){return function(n,t,e,r){if(e){var i=r,o=t[(i=i>t.length?t.length:i)-1];(n=o?o.parentNode:n).insertBefore(e,o||null)}}(J,p(),an,$),I((function(){if(r.isString&&r.canKeepMoving)return A(n(r.numberOfSteps>0?"START":"END"))}),(function(){return t()}))})),X[0])}))},F=function(n){return new Promise((function(t){B((function(){return L(J,n,an,$),t()}),X[0])}))},K=C((function(n){tn=i(tn,n)})),Q=C((function(){W?J.value="":p().forEach((function(n){M(n)}))})),Y=function n(t){return t=!0===t,new Promise((function(e){B(C((function(){var r=!1,i=p();return i.length&&(W?J.value=J.value.slice(0,-1):M(i[$])),function(n){for(var t=s(n.querySelectorAll("*")),e=E(t);t.length&&e;){var r=!1;t.forEach((function(n){O(n)&&(M(n),r=!0)})),r&&(t=s(n.querySelectorAll("*"))),e=E(t)}}(J),I((function(){if(t&&i.length-1>0)return P(n(!0),(function(){return r=!0,e()}))}),(function(n){return r?n:e()}))})),X[1])}))};this.break=function(){return c([F,m(b("BR"))])},this.delete=function(n,t){var e=l(t);return cn.add(e[0]),cn.add([Y,!n,_],n||1),cn.add(e[1]),this},this.destroy=function(n){n=void 0===n||n,Z.forEach((function(n){clearTimeout(n)})),Z=[],n&&M(an),nn.destroyed=!0},this.empty=function(){return c(Q)},this.exec=function(n,t){var e=l(t);return c([e[0],[n,null],e[1]])},this.is=function(n){return nn[n]},this.move=function(n,t){var e=D(n,$,p()),r=l(t);return cn.add(r[0]),cn.add([U,e.isString?n:Math.sign(n),_],Math.abs(n)),cn.add(r[1]),this},this.freeze=function(){nn.frozen=!0},this.unfreeze=function(){nn.frozen=!1,!nn.frozen&&R()},this.options=function(n){return c([K,n])},this.pause=function(n){return c([V,n||null])},this.type=function(n,t){var e=l(t),r=g(n,tn.html),i=[e[0]].concat(a(r,F,_,!0),[e[1]]);return c(i)},this.getQueue=function(){return cn},this.getOptions=function(){return tn},this.reset=function(){for(var n in!this.is("destroyed")&&this.destroy(),cn.reset(),nn)nn[n]=!1;return this},this.go=function(){return nn.started?this:(function(){if(an){var n="[data-typeit-id='".concat(un,"'] .ti-cursor");S("@keyframes blink-".concat(un," { 0% {opacity: 0} 49% {opacity: 0} 50% {opacity: 1} } ").concat(n," { animation: blink-").concat(un," ").concat(tn.cursorSpeed/1e3,"s infinite; } ").concat(n,".with-delay { animation-delay: 500ms; } ").concat(n,".disabled { animation: none; }"),un),J.appendChild(an)}}(),tn.waitUntilVisible?(function(n,t){new IntersectionObserver((function(e,r){e.forEach((function(e){e.isIntersecting&&(t(),r.unobserve(n))}))}),{threshold:1}).observe(n)}(J,R.bind(this)),this):(R(),this))};var G,J="string"==typeof(G=n)?document.querySelector(G):G,W=w(J),X=[],Z=[],$=0,_={freezeCursor:!0},nn={started:!1,completed:!1,frozen:!1,destroyed:!1},tn=i(e,t);tn=i(tn,{html:!W&&tn.html,nextStringDelay:T(tn.nextStringDelay),loopDelay:T(tn.loopDelay)});var en,rn,on,un=Math.random().toString().substring(2,9),cn=new f([V,tn.startDelay]);J.setAttribute("data-typeit-id",un),S("[data-typeit-id]:before {content: '.'; display: inline-block; width: 0; visibility: hidden;}"),tn.strings=(on=tn.strings,en=o(on)?on:[on],(rn=function(n){return n.innerHTML.replace(/<\!--.*?-->/g,"").trim()}(J))?(J.innerHTML="",tn.startDelete?(y(rn).forEach((function(n){L(J,n,an,$)})),cn.add([Y,!0]),v(1),en):[rn.trim()].concat(en)):en);var an=function(){if(W||!tn.cursor)return null;var n=b("span");return n.innerHTML=d(tn.cursorChar).innerHTML,n.className="ti-cursor",n.style.cssText="position:absolute;display:inline;margin-left:-.025em;".concat(function(n){var t=["font","lineHeight","color"],e=b("SPAN"),r=window.getComputedStyle(n,null);for(var i in r)t.indexOf(i)>-1&&r[i]&&(e.style[i]=r[i]);return e.style.cssText}(J)),n}();tn.strings.length&&function(){var n=tn.strings;n.forEach((function(t,e){var r=g(t,tn.html);cn.add(a(r,F,_,!0));var i=cn.getItems().length;if(e+1!==n.length){if(tn.breakLines){var o=m(b("BR"));return cn.add([F,o,_]),void v(i)}cn.add(a(r,Y,_)),v(i,t.length)}}))}()}var q=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],R=n.useRef,V=n.useEffect,U=n.useState,F=n.useMemo,K=function(e){var r=U(!0),i=r[0],o=r[1],u=R(null),c=e.options,a=e.element,f=e.children,s=e.getBeforeInit,l=e.getAfterInit,d=function(n,t){var e={};for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&t.indexOf(r)<0&&(e[r]=n[r]);if(null!=n&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(n);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(n,r[i])&&(e[r[i]]=n[r[i]])}return e}(e,["options","element","children","getBeforeInit","getAfterInit"]),p=a,h=F((function(){return n=p,q.indexOf(n.toLowerCase())>-1;var n}),[p]);return V((function(){f&&(c.strings=u.current.innerHTML),o(!1)}),[]),V((function(){if(!i){var n=new B(u.current,t({},c));return(n=s(n)).go(),n=l(n),function(){n.destroy()}}}),[i]),n.createElement("div",{style:{opacity:i?0:1}},h?n.createElement(p,t({ref:u},d)):n.createElement(p,t({ref:u},d),i&&f))};return K.defaultProps={element:"span",options:{},getBeforeInit:function(n){return n},getAfterInit:function(n){return n}},K})); | ||
***************************************************************************** */var t=function(){return(t=Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var i in t=arguments[e])Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i]);return n}).apply(this,arguments)};var e={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(){}},r=function(n){return n.map((function(n){return void 0===n[1]&&n.push(null),void 0===n[2]&&n.push({}),n}))},i=function(n,t){return Object.assign({},n,t)},o=function(n){return Array.isArray(n)},u=function(n,t){return n[2]=i(n[2],t)||t,n},c=function(n,t){return o(n[0])?n.map((function(n){return u(n,t)})):u(n,t)},a=function(n,t,e,r){r=r||!1,e=e||{};var i=!o(n),u=n.length;return(n=i?new Array(n).fill(0):n).map((function(n,o){if(i)return t;var a=[t,n,e];return r&&(0===o&&(a=c(a,{isFirst:!0})),o+1===u&&(a=c(a,{isLast:!0}))),a}))};function f(n){this.insert=function(n,e){t.splice(n,0,e)},this.add=function(n,e,r){return n=o(n)?n:[n,null],r=r||!1,e=e||1,o(n[0])||(n=a(e,n)),t=r?n.concat(t):t.concat(n),this},this.delete=function(n){return t.splice(n,1),this},this.reset=function(){return t=r(t).map((function(n){return n[2].executed=!1,n})),this},this.getItems=function(){return r(t).filter((function(n){return!n.executed}))};var t=[];n&&this.add(n)}var s=function(n){return Array.from(n)},l=function(n){var t=[];return t.concat.apply(t,n)},d=function(n){var t=document.implementation.createHTMLDocument("");return t.body.innerHTML=n,t.body},h=function(n){return 3===n.nodeType||"BR"===n.tagName},p=function n(t,e,r){e=e||null,r=void 0!==r&&r;var i=s(t.childNodes).map((function(t){return h(t)?t:n(t)}));return i=l(i),e&&(i=i.filter((function(n){return!n.parentNode.isEqualNode(e)}))),r?i.reverse():i},v=function(n){return"BODY"===n.tagName},m=function(n,t){t=t||null;var e=n instanceof HTMLElement;return{node:t,isTopLevelText:(!t||v(t.parentNode))&&!e,isHTMLElement:e,content:n}};function y(n){var t,e=d(n);return t=p(e).map((function(n){return n.nodeValue?s(n.nodeValue).map((function(t){return m(t,n)})):m(n)})),l(t)}function g(n,t){return(t=void 0===t||t)?y(n):s(n).map((function(n){return m(n)}))}var b=function(n){return document.createElement(n)},S=function(n,t){var e=b("style");e.id=t||"",e.appendChild(document.createTextNode(n)),document.head.appendChild(e)},T=function(n){return o(n)||(n=[n/2,n/2]),{before:n[0],after:n[1],total:n[0]+n[1]}},N=function(n,t){return Math.abs(Math.random()*(n+t-(n-t))+(n-t))},w=function(n){return["textarea","input"].indexOf(n.tagName.toLowerCase())>-1},x=function(n,t){var e=t.querySelectorAll("*");return[t].concat(s(e).reverse()).find((function(t){return t.cloneNode().outerHTML===n.outerHTML}))},L=function(n,t,e,r){e=e||null;var i=t.isHTMLElement,o=i?t.content:document.createTextNode(t.content);if(w(n))n.value="".concat(n.value).concat(t.content);else{if(!t.isTopLevelText&&!i){var u=t.node.parentNode,c=x(u.cloneNode(),n);if(function(n,t){if(!n)return!1;var e=n.nextSibling;return!e||e.isEqualNode(t)}(c,e))n=c;else if((o=u.cloneNode()).innerText=t.content,!v(u.parentNode)){for(var a=u.parentNode,f=a.cloneNode(),s=x(f,n);!s&&!v(a);)f.innerHTML=o.outerHTML,o=f,f=a.parentNode.cloneNode(),a=a.parentNode,s=x(f,n);n=s||n}}var l=p(n,e,!0)[r-1],d=l?l.parentNode:n;d.insertBefore(o,d.contains(e)?e:null)}},M=function(n){return n&&n.parentNode.removeChild(n)},O=function(n){return!n.firstChild&&!h(n)},E=function(n){return n.some((function(n){return O(n)}))},D=function(n,t,e){var r,i="string"==typeof n,o=!1,u=-1*n;return i&&(u=(r="END"===n.toUpperCase())?-1:1,o=r?t+u>0:t+u<e.length),{isString:i,numberOfSteps:u,canKeepMoving:o}};function P(n,t,e){return e?t?t(n):n:(n&&n.then||(n=Promise.resolve(n)),t?n.then(t):n)}function C(n){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];try{return Promise.resolve(n.apply(this,t))}catch(n){return Promise.reject(n)}}}function H(){}function A(n,t){if(!t)return n&&n.then?n.then(H):Promise.resolve()}function I(n,t){var e=n();return e&&e.then?e.then(t):t(e)}function k(n,t,e){if(!n.s){if(e instanceof j){if(!e.s)return void(e.o=k.bind(null,n,t));1&t&&(t=e.s),e=e.v}if(e&&e.then)return void e.then(k.bind(null,n,t),k.bind(null,n,2));n.s=t,n.v=e;var r=n.o;r&&r(n)}}var j=function(){function n(){}return n.prototype.then=function(t,e){var r=new n,i=this.s;if(i){var o=1&i?t:e;if(o){try{k(r,1,o(this.v))}catch(n){k(r,2,n)}return r}return this}return this.o=function(n){try{var i=n.v;1&n.s?k(r,1,t?t(i):i):e?k(r,1,e(i)):k(r,2,i)}catch(n){k(r,2,n)}},r},n}();function z(n,t){return n&&n.then?n.then(t):t(n)}function B(n,t){var r=this,u=this;t=t||{};var c=function(n,t){return cn.add(n,t),r},l=function(n){n=n||{};var t=i({},tn),e=i(t,n);return[[K,e,{force:!0}],[K,t,{force:!0}]]},h=function(){return W?s(J.value):p(J,an,!0)},v=function(n,t){t=t||1;var e=tn.nextStringDelay;cn.insert(n,[V,e.before]),cn.insert(n+t+1,[V,e.after])},x=function(n){an&&(an.classList.toggle("disabled",n),an.classList.toggle("with-delay",!n))},B=C((function(n,t){return Z.push(setTimeout(n,t)),P()})),q=C((function(n){return I((function(){if($)return A(move(-1*$))}),(function(){cn.reset().delete(0).add([V,n.before],!0),h().forEach((function(n){cn.add([Y,null,{isPhantom:!0}],1,!0)}))}))})),R=C((function(){nn.started=!0;var n=cn.getItems();return z(function(n,t){try{var e=n()}catch(n){return t(n)}return e&&e.then?e.then(void 0,t):e}((function(){return z(function(n,t,e){var r,i,o=-1;return function e(u){try{for(;++o<n.length;)if((u=t(o))&&u.then){if(!((c=u)instanceof j&&1&c.s))return void u.then(e,i||(i=k.bind(null,r=new j,2)));u=u.v}r?k(r,1,u):r=u}catch(n){k(r||(r=new j),2,n)}var c}(),r}(n,(function(t){if(nn.frozen||nn.destroyed)throw"";var e,r,i,o,c=n[t],a=c[2],f=[c,u];return a.freezeCursor&&x(!0),e=tn.speed,r=tn.deleteSpeed,i=tn.lifeLike,o=(r=null!==r?r:e/3)/2,X=i?[N(e,e/2),N(r,o)]:[e,r],I((function(){var n;if(null==a?void 0:a.isFirst)return A((n=tn).beforeString.apply(n,f))}),(function(){var n;return P((n=tn).beforeStep.apply(n,f),(function(){return P(c[0].call(u,c[1],a),(function(){return I((function(){if(!a||!a.isPhantom)return I((function(){var n,t;if(null===(n=c[2])||void 0===n?void 0:n.isLast)return A((t=tn).afterString.apply(t,f))}),(function(){var n;return P((n=tn).afterStep.apply(n,f),(function(){c[2].executed=!0}))}))}),(function(){x(!1)}))}))}))}))})),(function(n){return nn.completed=!0,P(tn.afterComplete(u),(function(){if(tn.loop){var n=tn.loopDelay||tn.nextStringDelay;B((function(){return P(q(n),(function(){R()}))}),n.after)}}))}))}),H),(function(n){return u}))})),V=function(n){return new Promise((function(t){B((function(){return t()}),n||tn.nextStringDelay.total)}))},U=function n(t){var e=h(),r=D(t,$,e);return $+=r.numberOfSteps,new Promise((function(t){B(C((function(){return function(n,t,e,r){if(e){var i=r,o=t[(i=i>t.length?t.length:i)-1];(n=o?o.parentNode:n).insertBefore(e,o||null)}}(J,h(),an,$),I((function(){if(r.isString&&r.canKeepMoving)return A(n(r.numberOfSteps>0?"START":"END"))}),(function(){return t()}))})),X[0])}))},F=function(n){return new Promise((function(t){B((function(){return L(J,n,an,$),t()}),X[0])}))},K=C((function(n){tn=i(tn,n)})),Q=C((function(){W?J.value="":h().forEach((function(n){M(n)}))})),Y=function n(t){return t=!0===t,new Promise((function(e){B(C((function(){var r=!1,i=h();return i.length&&(W?J.value=J.value.slice(0,-1):M(i[$])),function(n){for(var t=s(n.querySelectorAll("*")),e=E(t);t.length&&e;){var r=!1;t.forEach((function(n){O(n)&&(M(n),r=!0)})),r&&(t=s(n.querySelectorAll("*"))),e=E(t)}}(J),I((function(){if(t&&i.length-1>0)return P(n(!0),(function(){return r=!0,e()}))}),(function(n){return r?n:e()}))})),X[1])}))};this.break=function(){return c([F,m(b("BR"))])},this.delete=function(n,t){var e=l(t);return cn.add(e[0]),cn.add([Y,!n,_],n||1),cn.add(e[1]),this},this.destroy=function(n){n=void 0===n||n,Z.forEach((function(n){clearTimeout(n)})),Z=[],n&&M(an),nn.destroyed=!0},this.empty=function(){return c(Q)},this.exec=function(n,t){var e=l(t);return c([e[0],[n,null],e[1]])},this.is=function(n){return nn[n]},this.move=function(n,t){var e=D(n,$,h()),r=l(t);return cn.add(r[0]),cn.add([U,e.isString?n:Math.sign(n),_],Math.abs(n)),cn.add(r[1]),this},this.freeze=function(){nn.frozen=!0},this.unfreeze=function(){nn.frozen=!1,!nn.frozen&&R()},this.options=function(n){return c([K,n])},this.pause=function(n){return c([V,n||null])},this.type=function(n,t){var e=l(t),r=g(n,tn.html),i=[e[0]].concat(a(r,F,_,!0),[e[1]]);return c(i)},this.getQueue=function(){return cn},this.getOptions=function(){return tn},this.getElement=function(){return J},this.reset=function(){for(var n in!this.is("destroyed")&&this.destroy(),cn.reset(),nn)nn[n]=!1;return this},this.go=function(){return nn.started?this:(function(){if(an){var n="[data-typeit-id='".concat(un,"'] .ti-cursor");S("@keyframes blink-".concat(un," { 0% {opacity: 0} 49% {opacity: 0} 50% {opacity: 1} } ").concat(n," { animation: blink-").concat(un," ").concat(tn.cursorSpeed/1e3,"s infinite; } ").concat(n,".with-delay { animation-delay: 500ms; } ").concat(n,".disabled { animation: none; }"),un),J.appendChild(an)}}(),tn.waitUntilVisible?(function(n,t){new IntersectionObserver((function(e,r){e.forEach((function(e){e.isIntersecting&&(t(),r.unobserve(n))}))}),{threshold:1}).observe(n)}(J,R.bind(this)),this):(R(),this))};var G,J="string"==typeof(G=n)?document.querySelector(G):G,W=w(J),X=[],Z=[],$=0,_={freezeCursor:!0},nn={started:!1,completed:!1,frozen:!1,destroyed:!1},tn=i(e,t);tn=i(tn,{html:!W&&tn.html,nextStringDelay:T(tn.nextStringDelay),loopDelay:T(tn.loopDelay)});var en,rn,on,un=Math.random().toString().substring(2,9),cn=new f([V,tn.startDelay]);J.setAttribute("data-typeit-id",un),S("[data-typeit-id]:before {content: '.'; display: inline-block; width: 0; visibility: hidden;}"),tn.strings=(on=tn.strings,en=o(on)?on:[on],(rn=function(n){return n.innerHTML.replace(/<\!--.*?-->/g,"").trim()}(J))?(J.innerHTML="",tn.startDelete?(y(rn).forEach((function(n){L(J,n,an,$)})),cn.add([Y,!0]),v(1),en):[rn.trim()].concat(en)):en);var an=function(){if(W||!tn.cursor)return null;var n=b("span");return n.innerHTML=d(tn.cursorChar).innerHTML,n.className="ti-cursor",n.style.cssText="position:absolute;display:inline;margin-left:-.025em;".concat(function(n){var t=["font","lineHeight","color"],e=b("SPAN"),r=window.getComputedStyle(n,null);for(var i in r)t.indexOf(i)>-1&&r[i]&&(e.style[i]=r[i]);return e.style.cssText}(J)),n}();tn.strings.length&&function(){var n=tn.strings;n.forEach((function(t,e){var r=g(t,tn.html);cn.add(a(r,F,_,!0));var i=cn.getItems().length;if(e+1!==n.length){if(tn.breakLines){var o=m(b("BR"));return cn.add([F,o,_]),void v(i)}cn.add(a(r,Y,_)),v(i,t.length)}}))}()}var q=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],R=n.useRef,V=n.useEffect,U=n.useState,F=n.useMemo,K=function(e){var r=U(!0),i=r[0],o=r[1],u=R(null),c=e.options,a=e.element,f=e.children,s=e.getBeforeInit,l=e.getAfterInit,d=function(n,t){var e={};for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&t.indexOf(r)<0&&(e[r]=n[r]);if(null!=n&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(n);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(n,r[i])&&(e[r[i]]=n[r[i]])}return e}(e,["options","element","children","getBeforeInit","getAfterInit"]),h=a,p=F((function(){return n=h,q.indexOf(n.toLowerCase())>-1;var n}),[h]);return V((function(){f&&(c.strings=u.current.innerHTML),o(!1)}),[]),V((function(){if(!i){var n=new B(u.current,t({},c));return(n=s(n)).go(),n=l(n),function(){n.destroy()}}}),[i]),n.createElement("div",{style:{opacity:i?0:1}},p?n.createElement(h,t({ref:u},d)):n.createElement(h,t({ref:u},d),i&&f))};return K.defaultProps={element:"span",options:{},getBeforeInit:function(n){return n},getAfterInit:function(n){return n}},K})); |
{ | ||
"name": "typeit-react", | ||
"version": "0.1.0-rc2", | ||
"version": "0.1.0-rc3", | ||
"description": "React component for the most versatile JavaScript animated typing utility on the planet.", | ||
@@ -40,3 +40,3 @@ "homepage": "https://typeitjs.com", | ||
"@types/react": "^16.9.19", | ||
"typeit": "^7.0.0-rc3" | ||
"typeit": "^7.0.0-rc5" | ||
}, | ||
@@ -43,0 +43,0 @@ "peerDependencies": { |
Sorry, the diff of this file is too big to display
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
199515
4595
Updatedtypeit@^7.0.0-rc5