Comparing version 8.0.3 to 8.0.4
// TypeIt by Alex MacArthur - https://typeitjs.com | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e||self).TypeIt=t()}(this,function(){const e=[null,null,{}];var t=(e,t)=>Object.assign({},e,t),n=e=>Array.from(e),r=e=>{let t=document.implementation.createHTMLDocument();return t.body.innerHTML=e,t.body};const o=(e,t=null,r=!1)=>{let i=n(e.childNodes).flatMap(e=>{return 3===(t=e).nodeType||"BR"===t.tagName?e:o(e);var t});return t&&(i=i.filter(e=>!t.contains(e))),r?i.reverse():i},i=(e,t=null)=>({node:t,content:e});function s(e){let t=r(e);return o(t).flatMap(e=>e.nodeValue?n(e.nodeValue).map(t=>i(t,e)):i(e))}function u(e,t=!0){return t?s(e):n(e).map(e=>i(e))}var l=e=>document.createElement(e),c=e=>document.createTextNode(e),a=(e,t="")=>{let n=l("style");n.id=t,n.appendChild(c(e)),document.head.appendChild(n)},f=e=>Array.isArray(e);const h=e=>Number.isInteger(e),d=(e,t=document,n=!1)=>t["querySelector"+(n?"All":"")](e),m="ti-cursor",v="START",p={started:!1,completed:!1,frozen:!1,destroyed:!1},y={breakLines:!0,cursor:!0,cursorChar:"|",cursorSpeed:1e3,deleteSpeed:null,html:!0,lifeLike:!0,loop:!1,loopDelay:750,nextStringDelay:750,speed:100,startDelay:250,startDelete:!1,strings:[],waitUntilVisible:!1,beforeString:()=>{},afterString:()=>{},beforeStep:()=>{},afterStep:()=>{},afterComplete:()=>{}};var g=({el:e,move:t,cursorPos:n,to:r})=>h(t)?-1*t:((e,t,n=v)=>{let r=new RegExp("END","i").test(n),i=d(".ti-cursor",t),s=e?d(e,t):t,u=o(s,i,!0),l=u[0],c=u[u.length-1],a=r&&!e?0:o(t,i,!0).findIndex(e=>e.isSameNode(r?l:c));return r&&a--,a+1})(t,e,r)-n,P=e=>(f(e)||(e=[e/2,e/2]),e),b=(e,t)=>Math.abs(Math.random()*(e+t-(e-t))+(e-t));let N=e=>e/2;var S=e=>"value"in e;const M=e=>"function"==typeof e?e():e;var T=e=>"BODY"===e.tagName;const j=(e,t)=>{let r=n(d("*",t,!0));return[t].concat(r.reverse()).find(t=>t.cloneNode().isEqualNode(e.cloneNode()))},L=(e,t,n,r)=>{let i=t.content instanceof HTMLElement,s=t.node,u=null==s?void 0:s.parentNode,l=i?t.content:c(t.content);if(S(e))return void(e.value=""+e.value+t.content);if(!i&&u&&!T(u)){let r=j(u,e);if(r&&((e,t)=>{let n=e.nextSibling;return!n||n.isEqualNode(t)})(r,n))e=r;else{l=u.cloneNode(),l.appendChild(c(t.content));let n=u.parentNode,r=n.cloneNode();if(!T(n)){let t=j(r,e);for(;!t&&!T(n);){let o=r;o.innerHTML=l.outerHTML,l=o,n=n.parentNode,r=n.cloneNode(),t=j(r,e)}e=t||e}}}let a=o(e,n,!0)[r-1],f=a?a.parentNode:e;f.insertBefore(l,f.contains(n)?n:null)};var w=e=>e&&e.remove();const x={"font-family":"","font-weight":"","font-size":"","font-style":"","line-height":"",color:"","margin-left":"-.125em","margin-right":".125em"};function D(e,t,n){if(!e.s){if(n instanceof E){if(!n.s)return void(n.o=D.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(D.bind(null,e,t),D.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}const E=function(){function e(){}return e.prototype.then=function(t,n){const r=new e,o=this.s;if(o){const e=1&o?t:n;if(e){try{D(r,1,e(this.v))}catch(e){D(r,2,e)}return r}return this}return this.o=function(e){try{const o=e.v;1&e.s?D(r,1,t?t(o):o):n?D(r,1,n(o)):D(r,2,o)}catch(e){D(r,2,e)}},r},e}();function k(e){return e instanceof E&&1&e.s}function C(e,t,n){var r,o,i=-1;return function s(u){try{for(;++i<e.length&&(!n||!n());)if((u=t(i))&&u.then){if(!k(u))return void u.then(s,o||(o=D.bind(null,r=new E,2)));u=u.v}r?D(r,1,u):r=u}catch(e){D(r||(r=new E),2,e)}}(),r}function H(e,t,n){for(var r;;){var o=e();if(k(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!k(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!k(s)){r=2;break}}}var u=new E,l=D.bind(null,u,2);return(0===r?o.then(a):1===r?i.then(c):s.then(f)).then(void 0,l),u;function c(r){i=r;do{if(t&&(s=t())&&s.then&&!k(s))return void s.then(f).then(void 0,l);if(!(o=e())||k(o)&&!o.v)return void D(u,1,i);if(o.then)return void o.then(a).then(void 0,l);k(i=n())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,l)}function a(e){e?(i=n())&&i.then?i.then(c).then(void 0,l):c(i):D(u,1,i)}function f(){(o=e())?o.then?o.then(a).then(void 0,l):a(o):D(u,1,i)}}return function(c,T={}){const j=this,D=this,E=function(e,t,n=!1){try{function r(){function r(r){return Promise.resolve(function(e,t,n){try{return Promise.resolve(new Promise(r=>{n.push(setTimeout(function(){try{return Promise.resolve(e()).then(function(){r()})}catch(e){return Promise.reject(e)}},t))}))}catch(e){return Promise.reject(e)}}(e,t,X)).then(function(){return n?void 0:Promise.resolve(ee.afterStep(j)).then(function(e){})})}return n?r():Promise.resolve(ee.beforeStep(j)).then(r)}const o=function(){if(_.frozen)return Promise.resolve(new Promise(e=>{j.unfreeze=()=>{_.frozen=!1,e()}})).then(function(){})}();return Promise.resolve(o&&o.then?o.then(r):r())}catch(e){return Promise.reject(e)}},k=()=>S(K),z=e=>function(e){let{speed:t,deleteSpeed:n,lifeLike:r}=e;return n=null!==n?n:t/3,r?[b(t,N(t)),b(n,N(n))]:[t,n]}(ee)[e],I=(e,t=0)=>e?z(t):0,B=(e,t)=>(ne.add(e),((e={})=>{let t=e.delay;t&&ne.add([[U,t]])})(t),this),R=()=>(e=>S(e)?n(e.value):o(e,d(".ti-cursor",e),!0))(K),A=(e={})=>[[F,e],[F,ee]],O=e=>{let t=ee.nextStringDelay;ne.add([[U,t[0]],...e,[U,t[1]]])},V=e=>{re&&(oe.classList.toggle("disabled",e),oe.classList.toggle("with-delay",!e))},q=function(){try{let e;_.started=!0;let t=ne.getItems();const n=function(e,n){try{var r=function(){function e(){return _.completed=!0,Promise.resolve(ee.afterComplete(D)).then(function(){if(!ee.loop)throw"";let e=ee.loopDelay;E(function(){try{return Promise.resolve(function(e){try{function t(t){return ne.reset(),ne.set(0,[U,e,{}]),Promise.resolve(J({num:null})).then(function(){})}return Promise.resolve(Z?Promise.resolve(Q({value:Z})).then(t):t())}catch(e){return Promise.reject(e)}}(e[0])).then(function(){q()})}catch(e){return Promise.reject(e)}},e[1])})}const n=C(t,function(e){let n=t[e],r=n[2];return r.freezeCursor&&V(!0),Promise.resolve(n[0].call(D,n[1],r)).then(function(){ne.setMeta(e,{executed:!0}),V(!1)})});return n&&n.then?n.then(e):e()}()}catch(e){return}return r&&r.then?r.then(void 0,function(){}):r}();return Promise.resolve(n&&n.then?n.then(function(t){return e?t:D}):e?n:D)}catch(e){return Promise.reject(e)}},U=(e=0)=>E(()=>{},e),Q=function({value:e,to:t=v,instant:n=!1}){try{let r=g({el:K,move:e,cursorPos:Z,to:t}),o=()=>{var e,t,n;e=r<0?-1:1,t=Z,n=R(),Z=Math.min(Math.max(t+e,0),n.length),((e,t,n,r)=>{let o=t[r-1];(e=(null==o?void 0:o.parentNode)||e).insertBefore(n,o||null)})(K,R(),oe,Z)};return Promise.resolve(E(function(){try{let e=0;const t=H(function(){return e<Math.abs(r)},function(){return e++},function(){return n?void o():Promise.resolve(E(o,z(0))).then(function(e){})});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},I(n))).then(function(){})}catch(e){return Promise.reject(e)}},Y=({chars:e,instant:t,silent:n})=>{const r=this;return E(function(){try{function o(o){function s(){return n?void 0:Promise.resolve(ee.afterString(e,r)).then(function(e){})}const u=C(e,function(n){return t?void i(e[n]):Promise.resolve(E(()=>{i(e[n])},z(0))).then(function(e){})});return u&&u.then?u.then(s):s()}const i=e=>L(K,e,oe,Z);return Promise.resolve(n?o():Promise.resolve(ee.beforeString(e,r)).then(o))}catch(e){return Promise.reject(e)}},I(t),!0)},F=function(e){try{return ee=t(ee,e),Promise.resolve()}catch(e){return Promise.reject(e)}},G=function(){try{return k()?(K.value="",Promise.resolve()):(R().forEach(e=>{w(e)}),Promise.resolve())}catch(e){return Promise.reject(e)}},J=function({num:e=null,instant:t=!1,to:n=v}){try{return Promise.resolve(E(function(){try{let r=h(e)?e:g({el:K,move:e,cursorPos:Z,to:n});const o=()=>{let e=R();var t;e.length&&(k()?K.value=K.value.slice(0,-1):(w(e[Z]),t=oe,d("*",K,!0).forEach(e=>{if(!e.innerHTML&&"BR"!==e.tagName&&!e.isSameNode(t)){let t=e;for(;1===t.parentElement.childNodes.length;)t=t.parentElement;w(t)}})))};let i=0;const s=H(function(){return i<r},function(){return i++},function(){return t?void o():Promise.resolve(E(o,z(1))).then(function(e){})});return Promise.resolve(s&&s.then?s.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},I(t,1))).then(function(){const t=function(){if(null===e&&R().length-1>0)return Promise.resolve(J({num:null})).then(function(){})}();if(t&&t.then)return t.then(function(){})})}catch(e){return Promise.reject(e)}};this.break=function(e){const t=i(l("BR"));return B([[Y,{chars:[t],silent:!0}]],e)},this.delete=function(e=null,t={}){e=M(e);let n=A(t),r=e,{instant:o,to:i}=t;return B([n[0],[J,{num:r,instant:o,to:i},$],n[1]],t)},this.empty=function(e={}){return B([[G]],e)},this.exec=function(e,t){let n=A(t);return B([n[0],[e,null],n[1]],t)},this.move=function(e,t={}){e=M(e);let n=A(t),{instant:r,to:o}=t;return B([n[0],[Q,{value:null===e?"":e,to:o,instant:r},$],n[1]],t)},this.options=function(e){return e=M(e),B([[F,e]],e)},this.pause=function(e,t={}){return B([[U,M(e)]],t)},this.type=function(e,t={}){e=M(e);let n=A(t),r=u(e,ee.html),{instant:o}=t;return B([n[0],[Y,{chars:r,instant:o},$],n[1]],t)},this.is=function(e){return _[e]},this.destroy=function(e=!0){X.forEach(e=>clearTimeout(e)),X=[],M(e)&&w(oe),_.destroyed=!0},this.freeze=function(){_.frozen=!0},this.unfreeze=function(){},this.reset=function(){!this.is("destroyed")&&this.destroy(),ne.reset(),Z=0;for(let e in _)_[e]=!1;return K[k()?"value":"innerHTML"]="",this},this.go=function(){return _.started?this:(function(){try{!k()&&K.appendChild(oe),re?(((e,t,n)=>{let r="[data-typeit-id='"+e+"'] ."+m,o=getComputedStyle(n),i=Object.entries(x).reduce((e,[t,n])=>e+" "+t+": var(--ti-"+t+", "+(n||o[t])+");","");a("@keyframes blink-"+e+" { 0% {opacity: 0} 49% {opacity: 0} 50% {opacity: 1} } "+r+" { display: inline; letter-spacing: -1em; "+i+" animation: blink-"+e+" "+t.cursorSpeed/1e3+"s infinite; } "+r+".with-delay { animation-delay: 500ms; } "+r+".disabled { animation: none; }",e)})(te,ee,K),Promise.resolve()):Promise.resolve()}catch(e){return Promise.reject(e)}}(),ee.waitUntilVisible?(((e,t)=>{new IntersectionObserver((n,r)=>{n.forEach(n=>{n.isIntersecting&&(t(),r.unobserve(e))})},{threshold:1}).observe(e)})(K,q.bind(this)),this):(q(),this))},this.getQueue=function(){return ne},this.getOptions=function(){return ee},this.getElement=function(){return K};let K="string"==typeof(W=c)?d(W):W;var W;let X=[],Z=0,$={freezeCursor:!0},_=t({},p),ee=t(y,T);ee=t(ee,{html:!k()&&ee.html,nextStringDelay:P(ee.nextStringDelay),loopDelay:P(ee.loopDelay)});let te=Math.random().toString().substring(2,9),ne=function(n){const r=function(t){return o=o.concat(t.map(t=>e.map((e,n)=>t[n]?t[n]:e))),this};let o=[];return r(n),{add:r,set:function(e,t){o[e]=t},reset:function(){o=o.map(e=>(e[2].executed=!1,e))},getItems:function(){return o.filter(e=>!e[2].executed)},setMeta:function(e,n){o[e][2]=t(o[e][2],n)}}}([[U,ee.startDelay]]);K.dataset.typeitId=te,a("[data-typeit-id]:before {content: '.'; display: inline-block; width: 0; visibility: hidden;}");let re=ee.cursor&&!k(),oe=(()=>{if(k())return;let e=l("span");return e.className=m,re?(e.innerHTML=r(ee.cursorChar).innerHTML,e):(e.style.visibility="hidden",e)})();var ie;ee.strings=(e=>{let t=K.innerHTML;return t?(K.innerHTML="",ee.startDelete?(s(t).forEach(e=>{L(K,e,oe,Z)}),O([[J,{num:null}]]),e):t.trim().split(/<br(?:\s*?)(?:\/)?>/).concat(e)):e})(f(ie=ee.strings)?ie:[ie]),ee.strings.length&&(()=>{let e=ee.strings.filter(e=>!!e);e.forEach((t,n)=>{let r=u(t,ee.html);if(ne.add([[Y,{chars:r},$]]),n+1===e.length)return;const o=ee.breakLines?[[Y,{chars:[i(l("BR"))],silent:!0},$]]:[[J,{num:r.length},$]];O(o)})})()}}); | ||
(function($,k){typeof exports=="object"&&typeof module!="undefined"?module.exports=k():typeof define=="function"&&define.amd?define(k):($=typeof globalThis!="undefined"?globalThis:$||self,$.TypeIt=k())})(this,function(){"use strict";const $=[null,null,{}];var k=e=>e.map(n=>$.map((r,s)=>n[s]?n[s]:r)),D=(e,n)=>Object.assign({},e,n);const de=function(e){const n=function(u){return f=f.concat(k(u)),this},r=function(u,h){f[u]=h},s=function(){f=f.map(u=>(u[2].executed=!1,u))},i=function(){return f.filter(u=>!u[2].executed)},y=function(u,h){f[u][2]=D(f[u][2],h)};let f=[];return n(e),{add:n,set:r,reset:s,getItems:i,setMeta:y}};var x=e=>Array.from(e),J=e=>{let n=document.implementation.createHTMLDocument();return n.body.innerHTML=e,n.body},fe=e=>e.nodeType===3||e.tagName==="BR";const N=(e,n=null,r=!1)=>{let s=x(e.childNodes).flatMap(i=>fe(i)?i:N(i));return n&&(s=s.filter(i=>!n.contains(i))),r?s.reverse():s},pe=e=>N(e).flatMap(r=>r.nodeValue?x(r.nodeValue).map(s=>P(s,r)):P(r)),P=(e,n=null)=>({node:n,content:e});function X(e){let n=J(e);return pe(n)}function Z(e,n=!0){return n?X(e):x(e).map(r=>P(r))}var H=e=>document.createElement(e),U=e=>document.createTextNode(e),ee=(e,n="")=>{let r=H("style");r.id=n,r.appendChild(U(e)),document.head.appendChild(r)},te=e=>Array.isArray(e),he=e=>te(e)?e:[e];const ne=e=>Number.isInteger(e),C=(e,n=document,r=!1)=>n[`querySelector${r?"All":""}`](e),re="data-typeit-id",B="ti-cursor",F="START",ye="END",me={started:!1,completed:!1,frozen:!1,destroyed:!1},ge={breakLines:!0,cursor:!0,cursorChar:"|",cursorSpeed:1e3,deleteSpeed:null,html:!0,lifeLike:!0,loop:!1,loopDelay:750,nextStringDelay:750,speed:100,startDelay:250,startDelete:!1,strings:[],waitUntilVisible:!1,beforeString:()=>{},afterString:()=>{},beforeStep:()=>{},afterStep:()=>{},afterComplete:()=>{}},be=(e,n,r=F)=>{let s=new RegExp(ye,"i").test(r),i=C(`.${B}`,n),y=e?C(e,n):n,f=N(y,i,!0),u=f[0],h=f[f.length-1],_=s&&!e?0:N(n,i,!0).findIndex(S=>S.isSameNode(s?u:h));return s&&_--,_+1};var oe=({el:e,move:n,cursorPos:r,to:s})=>ne(n)?n*-1:be(n,e,s)-r,se=e=>(te(e)||(e=[e/2,e/2]),e),ie=(e,n)=>Math.abs(Math.random()*(e+n-(e-n))+(e-n));let le=e=>e/2;function Se(e){let{speed:n,deleteSpeed:r,lifeLike:s}=e;return r=r!==null?r:n/3,s?[ie(n,le(n)),ie(r,le(r))]:[n,r]}var ve=e=>(e.forEach(n=>clearTimeout(n)),[]),Te=()=>Math.random().toString().substring(2,9),O=e=>"value"in e;const _e=e=>O(e)?x(e.value):N(e,C(`.${B}`,e),!0);var we=(e,n)=>{new IntersectionObserver((s,i)=>{s.forEach(y=>{y.isIntersecting&&(n(),i.unobserve(e))})},{threshold:1}).observe(e)};const E=e=>typeof e=="function"?e():e;var V=e=>e.tagName==="BODY";const j=(e,n)=>{let r=x(C("*",n,!0));return[n].concat(r.reverse()).find(s=>s.cloneNode().isEqualNode(e.cloneNode()))},Ne=(e,n)=>{let r=e.nextSibling;return!r||r.isEqualNode(n)},ue=(e,n,r,s)=>{let i=n.content instanceof HTMLElement,y=n.node,f=y==null?void 0:y.parentNode,u=i?n.content:U(n.content);if(O(e)){e.value=`${e.value}${n.content}`;return}if(!i&&f&&!V(f)){let _=j(f,e);if(_&&Ne(_,r))e=_;else{u=f.cloneNode(),u.appendChild(U(n.content));let S=f.parentNode,A=S.cloneNode();if(!V(S)){let M=j(A,e);for(;!M&&!V(S);){let Q=A;Q.innerHTML=u.outerHTML,u=Q,S=S.parentNode,A=S.cloneNode(),M=j(A,e)}e=M||e}}}let h=N(e,r,!0)[s-1],b=h?h.parentNode:e;b.insertBefore(u,b.contains(r)?r:null)},Ce=(e,n,r)=>Math.min(Math.max(n+e,0),r.length);var z=e=>e&&e.remove(),Ee=(e,n)=>{C("*",e,!0).forEach(r=>{if(!r.innerHTML&&r.tagName!=="BR"&&!r.isSameNode(n)){let s=r;for(;s.parentElement.childNodes.length===1;)s=s.parentElement;z(s)}})},Ae=(e,n,r,s)=>{let i=n[s-1];e=(i==null?void 0:i.parentNode)||e,e.insertBefore(r,i||null)};function Me(e){return typeof e=="string"?C(e):e}const Ie=async(e,n,r)=>new Promise(s=>{const i=async()=>{await e(),s()};r.push(setTimeout(i,n))}),Le={"font-family":"","font-weight":"","font-size":"","font-style":"","line-height":"",color:"","margin-left":"-.125em","margin-right":".125em"},$e=(e,n,r)=>{let i=`${`[${re}='${e}']`} .${B}`,y=getComputedStyle(r),f=Object.entries(Le).reduce((u,[h,b])=>`${u} ${h}: var(--ti-${h}, ${b||y[h]});`,"");ee(`@keyframes blink-${e} { 0% {opacity: 0} 49% {opacity: 0} 50% {opacity: 1} } ${i} { display: inline; letter-spacing: -1em; ${f} animation: blink-${e} ${n.cursorSpeed/1e3}s infinite; } ${i}.with-delay { animation-delay: 500ms; } ${i}.disabled { animation: none; }`,e)};function ke(e,n={}){const r=async(t,o,a=!1)=>{v.frozen&&await new Promise(c=>{this.unfreeze=()=>{v.frozen=!1,c()}}),a||await l.beforeStep(this),await Ie(t,o,Y),a||await l.afterStep(this)},s=()=>O(p),i=t=>Se(l)[t],y=(t,o=0)=>t?i(o):0,f=(t={})=>{let o=t.delay;o&&T.add([[I,o]])},u=(t,o)=>(T.add(t),f(o),this),h=()=>_e(p),b=(t={})=>[[W,t],[W,l]],_=t=>{let o=l.nextStringDelay;T.add([[I,o[0]],...t,[I,o[1]]])},S=()=>{if(s())return;let t=H("span");return t.className=B,G?(t.innerHTML=J(l.cursorChar).innerHTML,t):(t.style.visibility="hidden",t)},A=async()=>{!s()&&p.appendChild(w),!!G&&$e(ce,l,p)},M=t=>{G&&(w.classList.toggle("disabled",t),w.classList.toggle("with-delay",!t))},Q=()=>{let t=l.strings.filter(o=>!!o);t.forEach((o,a)=>{let c=Z(o,l.html);if(T.add([[q,{chars:c},L]]),a+1===t.length)return;const d=l.breakLines?[[q,{chars:[P(H("BR"))],silent:!0},L]]:[[R,{num:c.length},L]];_(d)})},De=async t=>{g&&await ae({value:g}),T.reset(),T.set(0,[I,t,{}]),await R({num:null})},xe=t=>{let o=p.innerHTML;return o?(p.innerHTML="",l.startDelete?(X(o).forEach(c=>{ue(p,c,w,g)}),_([[R,{num:null}]]),t):o.trim().split(/<br(?:\s*?)(?:\/)?>/).concat(t)):t},K=async()=>{v.started=!0;let t=T.getItems();try{for(let a=0;a<t.length;a++){let c=t[a],d=c[2];d.freezeCursor&&M(!0),await c[0].call(this,c[1],d),T.setMeta(a,{executed:!0}),M(!1)}if(v.completed=!0,await l.afterComplete(this),!l.loop)throw"";let o=l.loopDelay;r(async()=>{await De(o[0]),K()},o[1])}catch{}return this},I=(t=0)=>r(()=>{},t),ae=async({value:t,to:o=F,instant:a=!1})=>{let c=oe({el:p,move:t,cursorPos:g,to:o}),d=()=>{g=Ce(c<0?-1:1,g,h()),Ae(p,h(),w,g)};await r(async()=>{for(let m=0;m<Math.abs(c);m++)a?d():await r(d,i(0))},y(a))},q=({chars:t,instant:o,silent:a})=>r(async()=>{const c=d=>ue(p,d,w,g);a||await l.beforeString(t,this);for(let d=0;d<t.length;d++)o?c(t[d]):await r(()=>{c(t[d])},i(0));a||await l.afterString(t,this)},y(o),!0),W=async t=>{l=D(l,t)},Pe=async()=>{if(s()){p.value="";return}h().forEach(t=>{z(t)})},R=async({num:t=null,instant:o=!1,to:a=F})=>{await r(async()=>{let c=ne(t)?t:oe({el:p,move:t,cursorPos:g,to:a});const d=()=>{let m=h();!m.length||(s()?p.value=p.value.slice(0,-1):(z(m[g]),Ee(p,w)))};for(let m=0;m<c;m++)o?d():await r(d,i(1))},y(o,1)),t===null&&h().length-1>0&&await R({num:null})};this.break=function(t){const o=P(H("BR"));return u([[q,{chars:[o],silent:!0}]],t)},this.delete=function(t=null,o={}){t=E(t);let a=b(o),c=t,{instant:d,to:m}=o;return u([a[0],[R,{num:c,instant:d,to:m},L],a[1]],o)},this.empty=function(t={}){return u([[Pe]],t)},this.exec=function(t,o){let a=b(o);return u([a[0],[t,null],a[1]],o)},this.move=function(t,o={}){t=E(t);let a=b(o),{instant:c,to:d}=o,m={value:t===null?"":t,to:d,instant:c};return u([a[0],[ae,m,L],a[1]],o)},this.options=function(t){return t=E(t),u([[W,t]],t)},this.pause=function(t,o={}){return u([[I,E(t)]],o)},this.type=function(t,o={}){t=E(t);let a=b(o),c=Z(t,l.html),{instant:d}=o,m=[a[0],[q,{chars:c,instant:d},L],a[1]];return u(m,o)},this.is=function(t){return v[t]},this.destroy=function(t=!0){Y=ve(Y),E(t)&&z(w),v.destroyed=!0},this.freeze=function(){v.frozen=!0},this.unfreeze=function(){},this.reset=function(){!this.is("destroyed")&&this.destroy(),T.reset(),g=0;for(let t in v)v[t]=!1;return p[s()?"value":"innerHTML"]="",this},this.go=function(){return v.started?this:(A(),l.waitUntilVisible?(we(p,K.bind(this)),this):(K(),this))},this.getQueue=function(){return T},this.getOptions=function(){return l},this.getElement=function(){return p};let p=Me(e),Y=[],g=0,L={freezeCursor:!0},v=D({},me),l=D(ge,n);l=D(l,{html:!s()&&l.html,nextStringDelay:se(l.nextStringDelay),loopDelay:se(l.loopDelay)});let ce=Te(),T=de([[I,l.startDelay]]);p.dataset.typeitId=ce,ee(`[${re}]:before {content: '.'; display: inline-block; width: 0; visibility: hidden;}`);let G=l.cursor&&!s(),w=S();l.strings=xe(he(l.strings)),l.strings.length&&Q()}return ke}); |
@@ -1,38 +0,323 @@ | ||
export declare type Character = { | ||
node: Node | null; | ||
content: string | Node; | ||
}; | ||
export declare type Options = { | ||
breakLines?: boolean; | ||
cursor?: boolean; | ||
cursorChar?: string; | ||
cursorSpeed?: number; | ||
deleteSpeed?: null | number; | ||
html?: boolean; | ||
lifeLike?: boolean; | ||
loop?: boolean; | ||
loopDelay?: number; | ||
nextStringDelay?: number; | ||
speed?: number; | ||
startDelay?: number; | ||
startDelete?: boolean; | ||
strings?: string[]; | ||
waitUntilVisible?: boolean; | ||
beforeString?: Function; | ||
afterString?: Function; | ||
beforeStep?: Function; | ||
afterStep?: Function; | ||
afterComplete?: Function; | ||
}; | ||
export declare type ActionOpts = Options & { | ||
to?: "START" | "END"; | ||
instant?: boolean; | ||
delay?: number; | ||
}; | ||
export declare type QueueItem = [Function?, any?, { | ||
[key: string]: any; | ||
}?]; | ||
export declare type Element = HTMLElement & { | ||
value: string | number; | ||
}; | ||
export declare type Sides = "START" | "END"; | ||
declare module "types" { | ||
export type Character = { | ||
node: Node | null; | ||
content: string | Node; | ||
}; | ||
export type Options = { | ||
breakLines?: boolean; | ||
cursor?: boolean; | ||
cursorChar?: string; | ||
cursorSpeed?: number; | ||
deleteSpeed?: null | number; | ||
html?: boolean; | ||
lifeLike?: boolean; | ||
loop?: boolean; | ||
loopDelay?: number; | ||
nextStringDelay?: number; | ||
speed?: number; | ||
startDelay?: number; | ||
startDelete?: boolean; | ||
strings?: string[]; | ||
waitUntilVisible?: boolean; | ||
beforeString?: Function; | ||
afterString?: Function; | ||
beforeStep?: Function; | ||
afterStep?: Function; | ||
afterComplete?: Function; | ||
}; | ||
export type ActionOpts = Options & { | ||
to?: "START" | "END"; | ||
instant?: boolean; | ||
delay?: number; | ||
}; | ||
export type QueueItem = [Function?, any?, { | ||
[key: string]: any; | ||
}?]; | ||
export type Element = HTMLElement & { | ||
value: string | number; | ||
}; | ||
export type Sides = "START" | "END"; | ||
} | ||
declare module "helpers/guaranteeThreeKeys" { | ||
import { QueueItem } from "types"; | ||
const _default: (q: QueueItem[]) => QueueItem[]; | ||
/** | ||
* Guarantees that a queue has three | ||
* items with default values. | ||
* | ||
* @param {array} queueItem | ||
* @return {array} | ||
*/ | ||
export default _default; | ||
} | ||
declare module "helpers/merge" { | ||
const _default_1: (originalObj: any, newObj: any) => any; | ||
export default _default_1; | ||
} | ||
declare module "Queue" { | ||
import { QueueItem } from "types"; | ||
const Queue: (initialItems: QueueItem[]) => { | ||
add: (steps: QueueItem[]) => typeof Queue; | ||
set: (index: number, item: QueueItem) => void; | ||
reset: () => void; | ||
getItems: () => QueueItem[]; | ||
setMeta: (index: number, meta: any) => void; | ||
}; | ||
export default Queue; | ||
} | ||
declare module "helpers/toArray" { | ||
const _default_2: (val: any) => any[]; | ||
/** | ||
* Literally just wraps toArray() to save a few bytes | ||
* when it's repeatedly used. | ||
* | ||
* @param {any} | ||
* @return {array} | ||
*/ | ||
export default _default_2; | ||
} | ||
declare module "helpers/getParsedBody" { | ||
const _default_3: (content: any) => HTMLElement; | ||
/** | ||
* Parse a string as HTML and return the body | ||
* of the parsed document. | ||
*/ | ||
export default _default_3; | ||
} | ||
declare module "helpers/isTypeableNode" { | ||
import { Element } from "types"; | ||
const _default_4: (node: Element) => boolean; | ||
/** | ||
* Returns `true` if node is of type `text` or is a <br> element. | ||
* | ||
* @param {object} node | ||
* @return {boolean} | ||
*/ | ||
export default _default_4; | ||
} | ||
declare module "helpers/getAllTypeableNodes" { | ||
/** | ||
* Retrieve all text/BR nodes that exist inside within an element. These | ||
* will be the nodes we're capable of typing onto the screen. | ||
*/ | ||
const getAllTypeableNodes: (element: Element, parentToExclude?: HTMLElement | null, shouldReverse?: boolean) => Node[]; | ||
export default getAllTypeableNodes; | ||
} | ||
declare module "helpers/chunkStrings" { | ||
import { Character } from "types"; | ||
/** | ||
* Given a node, generate an array of split text and nodes. | ||
*/ | ||
export const constructQueueFromNodes: (el: Element) => Character[]; | ||
/** | ||
* Construct a character object to be placed in the queue. | ||
* When a `null` node is passed, it's being used as a quick | ||
* way to add a single text node to the element. | ||
*/ | ||
export const createCharacterObject: (content: string | Node, node?: null | Node) => Character; | ||
/** | ||
* Convert string to array of chunks that will be later | ||
* used to construct a TypeIt queue. | ||
*/ | ||
export function chunkStringAsHtml(string: string): Character[]; | ||
/** | ||
* Given a string, chunk it into array items to be later | ||
* converted to queue items for typing. | ||
* | ||
* @param {string} str | ||
* @param {boolean} asHtml | ||
* @return {array} | ||
*/ | ||
export function maybeChunkStringAsHtml(str: string, asHtml?: boolean): Character[]; | ||
} | ||
declare module "helpers/createElement" { | ||
const _default_5: (el: any) => HTMLElement; | ||
export default _default_5; | ||
} | ||
declare module "helpers/createTextNode" { | ||
const _default_6: (content: string) => Text; | ||
export default _default_6; | ||
} | ||
declare module "helpers/appendStyleBlock" { | ||
const _default_7: (styles: string, id?: string) => void; | ||
export default _default_7; | ||
} | ||
declare module "helpers/isArray" { | ||
const _default_8: (thing: any) => boolean; | ||
export default _default_8; | ||
} | ||
declare module "helpers/asArray" { | ||
const _default_9: <T>(value: any) => T[]; | ||
/** | ||
* Converts value as within array, unless the value itself already is one. | ||
*/ | ||
export default _default_9; | ||
} | ||
declare module "helpers/isNumber" { | ||
const isNumber: (value: any) => boolean; | ||
export default isNumber; | ||
} | ||
declare module "helpers/select" { | ||
const select: (selector: string, element?: Node, all?: boolean) => Node | NodeList | null; | ||
export default select; | ||
} | ||
declare module "contants" { | ||
import { Options } from "types"; | ||
export const DATA_ATTRIBUTE = "data-typeit-id"; | ||
export const CURSOR_CLASS = "ti-cursor"; | ||
export const START = "START"; | ||
export const END = "END"; | ||
export const DEFAULT_STATUSES: { | ||
started: boolean; | ||
completed: boolean; | ||
frozen: boolean; | ||
destroyed: boolean; | ||
}; | ||
export const DEFAULT_OPTIONS: Options; | ||
} | ||
declare module "helpers/calculateStepsToSelector" { | ||
/** | ||
* Calculates the number of steps between the END of an element and a selector. | ||
*/ | ||
const calculateStepsToSelector: (selector: string, element: Element, to?: string) => number; | ||
export default calculateStepsToSelector; | ||
} | ||
declare module "helpers/calculateCursorSteps" { | ||
import { Element } from "types"; | ||
type calculateCursorStepsArgs = { | ||
el: Element; | ||
move: number | string; | ||
cursorPos: number; | ||
to: string; | ||
}; | ||
const _default_10: ({ el, move, cursorPos, to, }: calculateCursorStepsArgs) => number; | ||
export default _default_10; | ||
} | ||
declare module "helpers/calculateDelay" { | ||
const _default_11: (delayArg: number | number[]) => number[]; | ||
/** | ||
* Given a delay value, form it into the type of object | ||
* that will be used by Instance(). | ||
* | ||
* @param {integer | array} | ||
* @return {array} | ||
*/ | ||
export default _default_11; | ||
} | ||
declare module "helpers/randomInRange" { | ||
const _default_12: (value: number, range: number) => number; | ||
export default _default_12; | ||
} | ||
declare module "helpers/calculatePace" { | ||
import { Options } from "types"; | ||
export default function (options: Options): number[]; | ||
} | ||
declare module "helpers/destroyTimeouts" { | ||
const _default_13: (timeouts: number[]) => []; | ||
export default _default_13; | ||
} | ||
declare module "helpers/generateHash" { | ||
const _default_14: () => string; | ||
export default _default_14; | ||
} | ||
declare module "helpers/isInput" { | ||
const _default_15: (el: HTMLElement) => boolean; | ||
export default _default_15; | ||
} | ||
declare module "helpers/getAllChars" { | ||
import { Element } from "types"; | ||
/** | ||
* Get a flattened array of text nodes that have been typed. | ||
* This excludes any cursor character that might exist. | ||
*/ | ||
const getAllChars: (element: Element) => any[]; | ||
export default getAllChars; | ||
} | ||
declare module "helpers/fireWhenVisible" { | ||
const _default_16: (element: HTMLElement, func: Function) => void; | ||
export default _default_16; | ||
} | ||
declare module "helpers/handleFunctionalArg" { | ||
const handleFunctionalArg: <T>(arg: any) => T; | ||
export default handleFunctionalArg; | ||
} | ||
declare module "helpers/isBodyElement" { | ||
const _default_17: (node: any) => boolean; | ||
export default _default_17; | ||
} | ||
declare module "helpers/insertIntoElement" { | ||
import { Character, Element } from "types"; | ||
/** | ||
* Given a node, find the corresponding PRINTED node already in an element. | ||
*/ | ||
export const findPrintedNode: (node: Element, elementToSearch: Element) => Element; | ||
/** | ||
* Determine if a given node is the _last_ child in the element. | ||
* This will allow us to know if we should continue typing into it, | ||
* or if we should create another node to append at the end. | ||
*/ | ||
export const isLastElement: (node: Node, nodeToIgnore: Node | null) => boolean; | ||
/** | ||
* Inserts a set of content into the element. Intended for SINGLE characters. | ||
*/ | ||
const insertIntoElement: (targetElement: Element, character: Character, cursorNode: Element, cursorPosition: number) => void; | ||
export default insertIntoElement; | ||
} | ||
declare module "helpers/updateCursorPosition" { | ||
const updateCursorPosition: (steps: number, cursorPosition: number, printedCharacters: Element[]) => number; | ||
export default updateCursorPosition; | ||
} | ||
declare module "helpers/removeNode" { | ||
import { Element } from "types"; | ||
const _default_18: (node: Element | null) => void; | ||
/** | ||
* @param {object} HTML node | ||
*/ | ||
export default _default_18; | ||
} | ||
declare module "helpers/removeEmptyElements" { | ||
import { Element } from "types"; | ||
const _default_19: (node: Element, nodeToIgnore: Element) => void; | ||
/** | ||
* Given a DOM scope and selector, remove any HTML element remnants, | ||
* EXCEPT for <br> tags, which may be typed but do not have any text content. | ||
*/ | ||
export default _default_19; | ||
} | ||
declare module "helpers/repositionCursor" { | ||
const _default_20: (element: Node, allChars: any[], cursor: Node, newCursorPosition: number) => void; | ||
export default _default_20; | ||
} | ||
declare module "helpers/selectorToElement" { | ||
import { Element } from "types"; | ||
export default function (thing: string | Element): Element; | ||
} | ||
declare module "helpers/wait" { | ||
/** | ||
* Fire a callback after a delay, and add the timeout ID to a referenced array. | ||
*/ | ||
const wait: (callback: Function, delay: number, timeouts: any) => Promise<void>; | ||
export default wait; | ||
} | ||
declare module "helpers/setCursorStyles" { | ||
import { Element, Options } from "types"; | ||
export const cursorFontStyles: { | ||
readonly "font-family": ""; | ||
readonly "font-weight": ""; | ||
readonly "font-size": ""; | ||
readonly "font-style": ""; | ||
readonly "line-height": ""; | ||
readonly color: ""; | ||
readonly "margin-left": "-.125em"; | ||
readonly "margin-right": ".125em"; | ||
}; | ||
export const setCursorStyles: (id: string, options: Options, element: Element) => void; | ||
} | ||
declare module "TypeIt" { | ||
import { Element, Options } from "types"; | ||
export default function TypeIt(element: Element | string, options?: Options): void; | ||
} | ||
declare module "helpers/getComputedStyle" { | ||
const _default_21: (el: any) => CSSStyleDeclaration; | ||
export default _default_21; | ||
} |
{ | ||
"name": "typeit", | ||
"version": "8.0.3", | ||
"version": "8.0.4", | ||
"description": "The most versatile animated typing utility on the planet.", | ||
@@ -12,17 +12,14 @@ "author": "Alex MacArthur <alex@macarthur.me> (https://macarthur.me)", | ||
"main": "dist/index.umd.js", | ||
"module": "dist/index.esm.js", | ||
"module": "dist/index.es.js", | ||
"types": "dist/types.d.ts", | ||
"files": [ | ||
"dist/", | ||
"src/", | ||
"scripts/" | ||
], | ||
"scripts": { | ||
"build": "microbundle -i src/TypeIt.ts -o dist/index.js --name TypeIt --no-sourcemap && scripts/banner", | ||
"watch": "microbundle -i src/TypeIt.ts -o dist/index.js --name TypeIt --format umd --no-sourcemap watch", | ||
"start": "concurrently --kill-others \"npm run watch\" \"serve\"", | ||
"build": "vite build && tsc && scripts/banner", | ||
"start": "vite serve examples", | ||
"prettier": "prettier --write \"**/*.{md,js,ts}\"", | ||
"test": "jest", | ||
"postinstall": "./scripts/notice", | ||
"prepare": "husky install" | ||
"postinstall": "./scripts/notice" | ||
}, | ||
@@ -44,12 +41,12 @@ "keywords": [ | ||
"devDependencies": { | ||
"@babel/preset-env": "^7.15.8", | ||
"@babel/preset-typescript": "^7.15.0", | ||
"concurrently": "^6.2.1", | ||
"husky": "^7.0.2", | ||
"jest": "^27.1.1", | ||
"jest-cli": "^27.1.1", | ||
"lint-staged": "^11.1.2", | ||
"microbundle": "^0.13.3", | ||
"prettier": "^2.4.0", | ||
"husky": "^7.0.4", | ||
"jest": "^27.3.1", | ||
"jest-cli": "^27.3.1", | ||
"lint-staged": "^11.2.4", | ||
"prettier": "^2.4.1", | ||
"serve": "^12.0.1", | ||
"typescript": "^4.4.3" | ||
"typescript": "^4.4.4", | ||
"vite": "^2.6.10" | ||
}, | ||
@@ -65,3 +62,2 @@ "jest": { | ||
}, | ||
"browserslist": "supports es6-module and supports es6-module-dynamic-import, not opera > 0, not samsung > 0, not and_qq > 0", | ||
"lint-staged": { | ||
@@ -68,0 +64,0 @@ "*.{js,md}": "prettier --write" |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
81378
8
1029
1