typeit-react
Advanced tools
Comparing version 2.6.1 to 2.6.2
@@ -861,2 +861,4 @@ import * as React from "react"; | ||
useEffect(() => { | ||
if (!elementRef.current) | ||
return; | ||
calculateOptions(); | ||
@@ -867,2 +869,4 @@ setShouldShowChildren(false); | ||
var _a; | ||
if (!elementRef.current) | ||
return; | ||
if (!instanceOptions) | ||
@@ -869,0 +873,0 @@ return; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).TypeIt=t(e.React)}(this,(function(e){"use strict";function t(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}const n=t(e),r=e=>Array.isArray(e),i=e=>r(e)?e:[e];const a=e=>Array.from(e),o=e=>document.createTextNode(e);let s=e=>([...e.childNodes].forEach((e=>{if(e.nodeValue)return[...e.nodeValue].forEach((t=>{e.parentNode.insertBefore(o(t),e)})),void e.remove();s(e)})),e);const l=e=>{let t=document.implementation.createHTMLDocument();return t.body.innerHTML=e,s(t.body)},u="data-typeit-id",c="ti-cursor",d={started:!1,completed:!1,frozen:!1,destroyed:!1},f={breakLines:!0,cursor:{autoPause:!0,autoPauseDelay:500,animation:{frames:[0,0,1].map((e=>({opacity:e}))),options:{iterations:1/0,easing:"steps(2, start)",fill:"forwards"}}},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:()=>{}},h=`[${u}]:before {content: '.'; display: inline-block; width: 0; visibility: hidden;}`;function p(e,t=!1,n=!1){let r,i=e.querySelector(`.${c}`),a=document.createTreeWalker(e,NodeFilter.SHOW_ALL,{acceptNode:e=>{var t,r;if(i&&n){if(null==(t=e.classList)?void 0:t.contains(c))return NodeFilter.FILTER_ACCEPT;if(i.contains(e))return NodeFilter.FILTER_REJECT}return(null==(r=e.classList)?void 0:r.contains(c))?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),o=[];for(;r=a.nextNode();)r.originalParent||(r.originalParent=r.parentNode),o.push(r);return t?o.reverse():o}function y(e,t=!0){return t?p(l(e)):a(e).map(o)}const m=e=>document.createElement(e),g=(e,t="")=>{let n=m("style");n.id=t,n.appendChild(o(e)),document.head.appendChild(n)},b=e=>(r(e)||(e=[e/2,e/2]),e),v=(e,t)=>Math.abs(Math.random()*(e+t-(e-t))+(e-t));let w=e=>e/2;const T=e=>"value"in e;let E=e=>"function"==typeof e?e():e;const P=e=>Number.isInteger(e);let S=(e,t=document,n=!1)=>t["querySelector"+(n?"All":"")](e);const I=(e,t)=>Object.assign({},e,t);let L={"font-family":"","font-weight":"","font-size":"","font-style":"","line-height":"",color:"",transform:"translateX(-.125em)"};const N=(e,t)=>new Array(t).fill(e),C=({queueItems:e,selector:t,cursorPosition:n,to:r})=>{if(P(t))return-1*t;let i=new RegExp("END","i").test(r),a=t?[...e].reverse().findIndex((({char:e})=>{let n=e.parentElement,r=n.matches(t);return!(!i||!r)||r&&n.firstChild.isSameNode(e)})):-1;return a<0&&(a=i?0:e.length-1),a-n+(i?0:1)};let D=e=>new Promise((t=>{requestAnimationFrame((async()=>{t(await e())}))})),M=e=>null==e?void 0:e.getAnimations().find((t=>t.id===e.dataset.tiAnimationId)),O=({cursor:e,frames:t,options:n})=>{let r=e.animate(t,n);return r.pause(),r.id=e.dataset.tiAnimationId,D((()=>{D((()=>{r.play()}))})),r},A=e=>{var t;return null==(t=e.func)?void 0:t.call(null)},x=async({index:e,queueItems:t,wait:n,cursor:r,cursorOptions:i})=>{let a=t[e][1],o=[],s=e,l=a,u=()=>l&&!l.delay,c=a.shouldPauseCursor()&&i.autoPause;for(;u();)o.push(l),u()&&s++,l=t[s]?t[s][1]:null;if(o.length)return await D((async()=>{for(let e of o)await A(e)})),s-1;let d,f=M(r);return f&&(d={...f.effect.getComputedTiming(),delay:c?i.autoPauseDelay:0}),await n((async()=>{f&&c&&f.cancel(),await D((()=>{A(a)}))}),a.delay),await(({cursor:e,options:t,cursorOptions:n})=>{if(!e||!n)return;let r,i=M(e);i&&(t.delay=i.effect.getComputedTiming().delay,r=i.currentTime,i.cancel());let a=O({cursor:e,frames:n.animation.frames,options:t});return r&&(a.currentTime=r),a})({cursor:r,options:d,cursorOptions:i}),e};const $=function(e,t={}){let n=async(e,t,n=!1)=>{K.frozen&&await new Promise((e=>{this.unfreeze=()=>{K.frozen=!1,e()}})),n||await Y.beforeStep(this),await((e,t,n)=>new Promise((r=>{n.push(setTimeout((async()=>{await e(),r()}),t||0))})))(e,t,W),n||await Y.afterStep(this)},r=(e,t)=>x({index:e,queueItems:t,wait:n,cursor:ne,cursorOptions:Y.cursor}),o=e=>((e,t)=>{if(!e)return;let n=e.parentNode;(n.childNodes.length>1||n.isSameNode(t)?e:n).remove()})(e,J),D=()=>T(J),M=(e=0)=>function(e){let{speed:t,deleteSpeed:n,lifeLike:r}=e;return n=null!==n?n:t/3,r?[v(t,w(t)),v(n,w(n))]:[t,n]}(Y)[e],A=()=>(e=>T(e)?a(e.value):p(e,!0).filter((e=>!(e.childNodes.length>0))))(J),$=(e,t)=>(ee.add(e),((e={})=>{let t=e.delay;t&&ee.add({delay:t})})(t),this),H=()=>G??X,R=(e={})=>[{func:()=>_(e)},{func:()=>_(Y)}],F=e=>{let t=Y.nextStringDelay;ee.add([{delay:t[0]},...e,{delay:t[1]}])},j=async()=>{if(!D()&&ne&&J.appendChild(ne),te){((e,t)=>{let n=`[${u}='${e}'] .${c}`,r=getComputedStyle(t),i=Object.entries(L).reduce(((e,[t,n])=>`${e} ${t}: var(--ti-cursor-${t}, ${n||r[t]});`),"");g(`${n} { display: inline-block; width: 0; ${i} }`,e)})(Z,J),ne.dataset.tiAnimationId=Z;let{animation:e}=Y.cursor,{frames:t,options:n}=e;O({frames:t,cursor:ne,options:{duration:Y.cursorSpeed,...n}})}},k=()=>{let e=Y.strings.filter((e=>!!e));e.forEach(((t,n)=>{if(this.type(t),n+1===e.length)return;let r=Y.breakLines?[{func:()=>B(m("BR")),typeable:!0}]:N({func:Q,delay:M(1)},ee.getTypeable().length);F(r)}))},q=async(e=!0)=>{K.started=!0;let t=t=>{ee.done(t,!e)};try{let i=[...ee.getQueue()];for(let e=0;e<i.length;e++){let[n,a]=i[e];if(!a.done){if(!a.deletable||a.deletable&&A().length){let n=await r(e,i);Array(n-e).fill(e+1).map(((e,t)=>e+t)).forEach((e=>{let[n]=i[e];t(n)})),e=n}t(n)}}if(!e)return this;if(K.completed=!0,await Y.afterComplete(this),!Y.loop)throw"";let a=Y.loopDelay;n((async()=>{await(async e=>{let t=H();t&&await z({value:t});let n=A().map((e=>[Symbol(),{func:Q,delay:M(1),deletable:!0,shouldPauseCursor:()=>!0}]));for(let i=0;i<n.length;i++)await r(i,n);ee.reset(),ee.set(0,{delay:e})})(a[0]),q()}),a[1])}catch(i){}return this},z=async e=>{var t,n,r;t=e,n=X,r=A(),X=Math.min(Math.max(n+t,0),r.length),((e,t,n)=>{let r=t[n-1],i=S(`.${c}`,e);(e=(null==r?void 0:r.parentNode)||e).insertBefore(i,r||null)})(J,A(),X)},B=e=>((e,t)=>{if(T(e))return void(e.value=`${e.value}${t.textContent}`);t.innerHTML="";let n=(r=t.originalParent,/body/i.test(null==r?void 0:r.tagName)?e:t.originalParent||e);var r;n.insertBefore(t,S("."+c,n)||null)})(J,e),_=async e=>Y=I(Y,e),V=async()=>{D()?J.value="":A().forEach(o)},Q=()=>{let e=A();e.length&&(D()?J.value=J.value.slice(0,-1):o(e[X]))};this.break=function(e){return $({func:()=>B(m("BR")),typeable:!0},e)},this.delete=function(e=null,t={}){e=E(e);let n=R(t),r=e,{instant:i,to:a}=t,o=ee.getTypeable(),s=null===r?o.length:P(r)?r:C({queueItems:o,selector:r,cursorPosition:H(),to:a});return $([n[0],...N({func:Q,delay:i?0:M(1),deletable:!0},s),n[1]],t)},this.empty=function(e={}){return $({func:V},e)},this.exec=function(e,t={}){let n=R(t);return $([n[0],{func:()=>e(this)},n[1]],t)},this.move=function(e,t={}){e=E(e);let n=R(t),{instant:r,to:i}=t,a=C({queueItems:ee.getTypeable(),selector:null===e?"":e,to:i,cursorPosition:H()}),o=a<0?-1:1;return G=H()+a,$([n[0],...N({func:()=>z(o),delay:r?0:M(),cursorable:!0},Math.abs(a)),n[1]],t)},this.options=function(e,t={}){return e=E(e),_(e),$({},t)},this.pause=function(e,t={}){return $({delay:E(e)},t)},this.type=function(e,t={}){e=E(e);let{instant:n}=t,r=R(t),i=y(e,Y.html).map((e=>{return{func:()=>B(e),char:e,delay:n||(t=e,/<(.+)>(.*?)<\/(.+)>/.test(t.outerHTML))?0:M(),typeable:e.nodeType===Node.TEXT_NODE};var t})),a=[r[0],{func:async()=>await Y.beforeString(e,this)},...i,{func:async()=>await Y.afterString(e,this)},r[1]];return $(a,t)},this.is=function(e){return K[e]},this.destroy=function(e=!0){W.forEach(clearTimeout),W=[],E(e)&&ne&&o(ne),K.destroyed=!0},this.freeze=function(){K.frozen=!0},this.unfreeze=()=>{},this.reset=function(e){!this.is("destroyed")&&this.destroy(),e?(ee.wipe(),e(this)):ee.reset(),X=0;for(let t in K)K[t]=!1;return J[D()?"value":"innerHTML"]="",this},this.go=function(){return K.started?this:(j(),Y.waitUntilVisible?(((e,t)=>{new IntersectionObserver(((n,r)=>{n.forEach((n=>{n.isIntersecting&&(t(),r.unobserve(e))}))}),{threshold:1}).observe(e)})(J,q.bind(this)),this):(q(),this))},this.flush=function(e=(()=>{})){return j(),q(!1).then(e),this},this.getQueue=()=>ee,this.getOptions=()=>Y,this.updateOptions=e=>_(e),this.getElement=()=>J;let J="string"==typeof(U=e)?S(U):U;var U;let W=[],X=0,G=null,K=I({},d);t.cursor=(e=>{var t,n;if("object"==typeof e){let r={},{frames:i,options:a}=f.cursor.animation;return r.animation=e.animation||{},r.animation.frames=(null==(t=e.animation)?void 0:t.frames)||i,r.animation.options=I(a,(null==(n=e.animation)?void 0:n.options)||{}),r.autoPause=e.autoPause??f.cursor.autoPause,r.autoPauseDelay=e.autoPauseDelay||f.cursor.autoPauseDelay,r}return!0===e?f.cursor:e})(t.cursor??f.cursor);let Y=I(f,t);Y=I(Y,{html:!D()&&Y.html,nextStringDelay:b(Y.nextStringDelay),loopDelay:b(Y.loopDelay)});let Z=Math.random().toString().substring(2,9),ee=function(e){let t=function(e){return i(e).forEach((e=>{var t;return a.set(Symbol(null==(t=e.char)?void 0:t.innerText),n({...e}))})),this},n=e=>(e.shouldPauseCursor=function(){return Boolean(this.typeable||this.cursorable||this.deletable)},e),r=()=>Array.from(a.values()),a=new Map;return t(e),{add:t,set:function(e,t){let r=[...a.keys()];a.set(r[e],n(t))},wipe:function(){a=new Map,t(e)},reset:function(){a.forEach((e=>delete e.done))},destroy:e=>a.delete(e),done:(e,t=!1)=>t?a.delete(e):a.get(e).done=!0,getItems:(e=!1)=>e?r():r().filter((e=>!e.done)),getQueue:()=>a,getTypeable:()=>r().filter((e=>e.typeable))}}([{delay:Y.startDelay}]);J.dataset.typeitId=Z,g(h);let te=!!Y.cursor&&!D(),ne=(()=>{if(D())return;let e=m("span");return e.className=c,te?(e.innerHTML=l(Y.cursorChar).innerHTML,e):(e.style.visibility="hidden",e)})();Y.strings=(e=>{let t=J.innerHTML;return t?(J.innerHTML="",Y.startDelete?(J.innerHTML=t,s(J),F(N({func:Q,delay:M(1),deletable:!0},A().length)),e):t.replace(/<!--(.+?)-->/g,"").trim().split(/<br(?:\s*?)(?:\/)?>/).concat(e)):e})(i(Y.strings)),Y.strings.length&&k()},{useRef:H,useEffect:R,useState:F}=n,j=e.forwardRef(((e,t)=>{const{as:r}=e;return n.createElement(r,{ref:t,...e})})),k=e=>{const t=H(null),r=H(null),{options:i,children:a,getBeforeInit:o,getAfterInit:s,...l}=e,[u,c]=F(!0),[d,f]=F(null);return R((()=>{!function(){const e=Object.assign({},i);a&&t.current&&(e.strings=t.current.innerHTML),f(e)}(),c(!1)}),[i]),R((()=>{var e;d&&((null==(e=r.current)?void 0:e.updateOptions(d))||(r.current=new $(t.current,d),r.current=o(r.current),r.current.go(),r.current=s(r.current)))}),[d]),R((()=>()=>{var e;return null==(e=r.current)?void 0:e.destroy()}),[]),n.createElement(j,{ref:t,children:u?a:null,style:{opacity:u?0:1},...l})};return k.defaultProps={as:"span",options:{},getBeforeInit:e=>e,getAfterInit:e=>e},k})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).TypeIt=t(e.React)}(this,(function(e){"use strict";function t(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}const n=t(e),r=e=>Array.isArray(e),i=e=>r(e)?e:[e];const a=e=>Array.from(e),o=e=>document.createTextNode(e);let s=e=>([...e.childNodes].forEach((e=>{if(e.nodeValue)return[...e.nodeValue].forEach((t=>{e.parentNode.insertBefore(o(t),e)})),void e.remove();s(e)})),e);const l=e=>{let t=document.implementation.createHTMLDocument();return t.body.innerHTML=e,s(t.body)},u="data-typeit-id",c="ti-cursor",d={started:!1,completed:!1,frozen:!1,destroyed:!1},f={breakLines:!0,cursor:{autoPause:!0,autoPauseDelay:500,animation:{frames:[0,0,1].map((e=>({opacity:e}))),options:{iterations:1/0,easing:"steps(2, start)",fill:"forwards"}}},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:()=>{}},h=`[${u}]:before {content: '.'; display: inline-block; width: 0; visibility: hidden;}`;function p(e,t=!1,n=!1){let r,i=e.querySelector(`.${c}`),a=document.createTreeWalker(e,NodeFilter.SHOW_ALL,{acceptNode:e=>{var t,r;if(i&&n){if(null==(t=e.classList)?void 0:t.contains(c))return NodeFilter.FILTER_ACCEPT;if(i.contains(e))return NodeFilter.FILTER_REJECT}return(null==(r=e.classList)?void 0:r.contains(c))?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),o=[];for(;r=a.nextNode();)r.originalParent||(r.originalParent=r.parentNode),o.push(r);return t?o.reverse():o}function y(e,t=!0){return t?p(l(e)):a(e).map(o)}const m=e=>document.createElement(e),g=(e,t="")=>{let n=m("style");n.id=t,n.appendChild(o(e)),document.head.appendChild(n)},b=e=>(r(e)||(e=[e/2,e/2]),e),v=(e,t)=>Math.abs(Math.random()*(e+t-(e-t))+(e-t));let w=e=>e/2;const T=e=>"value"in e;let E=e=>"function"==typeof e?e():e;const P=e=>Number.isInteger(e);let S=(e,t=document,n=!1)=>t["querySelector"+(n?"All":"")](e);const I=(e,t)=>Object.assign({},e,t);let L={"font-family":"","font-weight":"","font-size":"","font-style":"","line-height":"",color:"",transform:"translateX(-.125em)"};const N=(e,t)=>new Array(t).fill(e),C=({queueItems:e,selector:t,cursorPosition:n,to:r})=>{if(P(t))return-1*t;let i=new RegExp("END","i").test(r),a=t?[...e].reverse().findIndex((({char:e})=>{let n=e.parentElement,r=n.matches(t);return!(!i||!r)||r&&n.firstChild.isSameNode(e)})):-1;return a<0&&(a=i?0:e.length-1),a-n+(i?0:1)};let D=e=>new Promise((t=>{requestAnimationFrame((async()=>{t(await e())}))})),M=e=>null==e?void 0:e.getAnimations().find((t=>t.id===e.dataset.tiAnimationId)),O=({cursor:e,frames:t,options:n})=>{let r=e.animate(t,n);return r.pause(),r.id=e.dataset.tiAnimationId,D((()=>{D((()=>{r.play()}))})),r},A=e=>{var t;return null==(t=e.func)?void 0:t.call(null)},x=async({index:e,queueItems:t,wait:n,cursor:r,cursorOptions:i})=>{let a=t[e][1],o=[],s=e,l=a,u=()=>l&&!l.delay,c=a.shouldPauseCursor()&&i.autoPause;for(;u();)o.push(l),u()&&s++,l=t[s]?t[s][1]:null;if(o.length)return await D((async()=>{for(let e of o)await A(e)})),s-1;let d,f=M(r);return f&&(d={...f.effect.getComputedTiming(),delay:c?i.autoPauseDelay:0}),await n((async()=>{f&&c&&f.cancel(),await D((()=>{A(a)}))}),a.delay),await(({cursor:e,options:t,cursorOptions:n})=>{if(!e||!n)return;let r,i=M(e);i&&(t.delay=i.effect.getComputedTiming().delay,r=i.currentTime,i.cancel());let a=O({cursor:e,frames:n.animation.frames,options:t});return r&&(a.currentTime=r),a})({cursor:r,options:d,cursorOptions:i}),e};const $=function(e,t={}){let n=async(e,t,n=!1)=>{K.frozen&&await new Promise((e=>{this.unfreeze=()=>{K.frozen=!1,e()}})),n||await Y.beforeStep(this),await((e,t,n)=>new Promise((r=>{n.push(setTimeout((async()=>{await e(),r()}),t||0))})))(e,t,W),n||await Y.afterStep(this)},r=(e,t)=>x({index:e,queueItems:t,wait:n,cursor:ne,cursorOptions:Y.cursor}),o=e=>((e,t)=>{if(!e)return;let n=e.parentNode;(n.childNodes.length>1||n.isSameNode(t)?e:n).remove()})(e,J),D=()=>T(J),M=(e=0)=>function(e){let{speed:t,deleteSpeed:n,lifeLike:r}=e;return n=null!==n?n:t/3,r?[v(t,w(t)),v(n,w(n))]:[t,n]}(Y)[e],A=()=>(e=>T(e)?a(e.value):p(e,!0).filter((e=>!(e.childNodes.length>0))))(J),$=(e,t)=>(ee.add(e),((e={})=>{let t=e.delay;t&&ee.add({delay:t})})(t),this),H=()=>G??X,R=(e={})=>[{func:()=>_(e)},{func:()=>_(Y)}],F=e=>{let t=Y.nextStringDelay;ee.add([{delay:t[0]},...e,{delay:t[1]}])},j=async()=>{if(!D()&&ne&&J.appendChild(ne),te){((e,t)=>{let n=`[${u}='${e}'] .${c}`,r=getComputedStyle(t),i=Object.entries(L).reduce(((e,[t,n])=>`${e} ${t}: var(--ti-cursor-${t}, ${n||r[t]});`),"");g(`${n} { display: inline-block; width: 0; ${i} }`,e)})(Z,J),ne.dataset.tiAnimationId=Z;let{animation:e}=Y.cursor,{frames:t,options:n}=e;O({frames:t,cursor:ne,options:{duration:Y.cursorSpeed,...n}})}},k=()=>{let e=Y.strings.filter((e=>!!e));e.forEach(((t,n)=>{if(this.type(t),n+1===e.length)return;let r=Y.breakLines?[{func:()=>B(m("BR")),typeable:!0}]:N({func:Q,delay:M(1)},ee.getTypeable().length);F(r)}))},q=async(e=!0)=>{K.started=!0;let t=t=>{ee.done(t,!e)};try{let i=[...ee.getQueue()];for(let e=0;e<i.length;e++){let[n,a]=i[e];if(!a.done){if(!a.deletable||a.deletable&&A().length){let n=await r(e,i);Array(n-e).fill(e+1).map(((e,t)=>e+t)).forEach((e=>{let[n]=i[e];t(n)})),e=n}t(n)}}if(!e)return this;if(K.completed=!0,await Y.afterComplete(this),!Y.loop)throw"";let a=Y.loopDelay;n((async()=>{await(async e=>{let t=H();t&&await z({value:t});let n=A().map((e=>[Symbol(),{func:Q,delay:M(1),deletable:!0,shouldPauseCursor:()=>!0}]));for(let i=0;i<n.length;i++)await r(i,n);ee.reset(),ee.set(0,{delay:e})})(a[0]),q()}),a[1])}catch(i){}return this},z=async e=>{var t,n,r;t=e,n=X,r=A(),X=Math.min(Math.max(n+t,0),r.length),((e,t,n)=>{let r=t[n-1],i=S(`.${c}`,e);(e=(null==r?void 0:r.parentNode)||e).insertBefore(i,r||null)})(J,A(),X)},B=e=>((e,t)=>{if(T(e))return void(e.value=`${e.value}${t.textContent}`);t.innerHTML="";let n=(r=t.originalParent,/body/i.test(null==r?void 0:r.tagName)?e:t.originalParent||e);var r;n.insertBefore(t,S("."+c,n)||null)})(J,e),_=async e=>Y=I(Y,e),V=async()=>{D()?J.value="":A().forEach(o)},Q=()=>{let e=A();e.length&&(D()?J.value=J.value.slice(0,-1):o(e[X]))};this.break=function(e){return $({func:()=>B(m("BR")),typeable:!0},e)},this.delete=function(e=null,t={}){e=E(e);let n=R(t),r=e,{instant:i,to:a}=t,o=ee.getTypeable(),s=null===r?o.length:P(r)?r:C({queueItems:o,selector:r,cursorPosition:H(),to:a});return $([n[0],...N({func:Q,delay:i?0:M(1),deletable:!0},s),n[1]],t)},this.empty=function(e={}){return $({func:V},e)},this.exec=function(e,t={}){let n=R(t);return $([n[0],{func:()=>e(this)},n[1]],t)},this.move=function(e,t={}){e=E(e);let n=R(t),{instant:r,to:i}=t,a=C({queueItems:ee.getTypeable(),selector:null===e?"":e,to:i,cursorPosition:H()}),o=a<0?-1:1;return G=H()+a,$([n[0],...N({func:()=>z(o),delay:r?0:M(),cursorable:!0},Math.abs(a)),n[1]],t)},this.options=function(e,t={}){return e=E(e),_(e),$({},t)},this.pause=function(e,t={}){return $({delay:E(e)},t)},this.type=function(e,t={}){e=E(e);let{instant:n}=t,r=R(t),i=y(e,Y.html).map((e=>{return{func:()=>B(e),char:e,delay:n||(t=e,/<(.+)>(.*?)<\/(.+)>/.test(t.outerHTML))?0:M(),typeable:e.nodeType===Node.TEXT_NODE};var t})),a=[r[0],{func:async()=>await Y.beforeString(e,this)},...i,{func:async()=>await Y.afterString(e,this)},r[1]];return $(a,t)},this.is=function(e){return K[e]},this.destroy=function(e=!0){W.forEach(clearTimeout),W=[],E(e)&&ne&&o(ne),K.destroyed=!0},this.freeze=function(){K.frozen=!0},this.unfreeze=()=>{},this.reset=function(e){!this.is("destroyed")&&this.destroy(),e?(ee.wipe(),e(this)):ee.reset(),X=0;for(let t in K)K[t]=!1;return J[D()?"value":"innerHTML"]="",this},this.go=function(){return K.started?this:(j(),Y.waitUntilVisible?(((e,t)=>{new IntersectionObserver(((n,r)=>{n.forEach((n=>{n.isIntersecting&&(t(),r.unobserve(e))}))}),{threshold:1}).observe(e)})(J,q.bind(this)),this):(q(),this))},this.flush=function(e=(()=>{})){return j(),q(!1).then(e),this},this.getQueue=()=>ee,this.getOptions=()=>Y,this.updateOptions=e=>_(e),this.getElement=()=>J;let J="string"==typeof(U=e)?S(U):U;var U;let W=[],X=0,G=null,K=I({},d);t.cursor=(e=>{var t,n;if("object"==typeof e){let r={},{frames:i,options:a}=f.cursor.animation;return r.animation=e.animation||{},r.animation.frames=(null==(t=e.animation)?void 0:t.frames)||i,r.animation.options=I(a,(null==(n=e.animation)?void 0:n.options)||{}),r.autoPause=e.autoPause??f.cursor.autoPause,r.autoPauseDelay=e.autoPauseDelay||f.cursor.autoPauseDelay,r}return!0===e?f.cursor:e})(t.cursor??f.cursor);let Y=I(f,t);Y=I(Y,{html:!D()&&Y.html,nextStringDelay:b(Y.nextStringDelay),loopDelay:b(Y.loopDelay)});let Z=Math.random().toString().substring(2,9),ee=function(e){let t=function(e){return i(e).forEach((e=>{var t;return a.set(Symbol(null==(t=e.char)?void 0:t.innerText),n({...e}))})),this},n=e=>(e.shouldPauseCursor=function(){return Boolean(this.typeable||this.cursorable||this.deletable)},e),r=()=>Array.from(a.values()),a=new Map;return t(e),{add:t,set:function(e,t){let r=[...a.keys()];a.set(r[e],n(t))},wipe:function(){a=new Map,t(e)},reset:function(){a.forEach((e=>delete e.done))},destroy:e=>a.delete(e),done:(e,t=!1)=>t?a.delete(e):a.get(e).done=!0,getItems:(e=!1)=>e?r():r().filter((e=>!e.done)),getQueue:()=>a,getTypeable:()=>r().filter((e=>e.typeable))}}([{delay:Y.startDelay}]);J.dataset.typeitId=Z,g(h);let te=!!Y.cursor&&!D(),ne=(()=>{if(D())return;let e=m("span");return e.className=c,te?(e.innerHTML=l(Y.cursorChar).innerHTML,e):(e.style.visibility="hidden",e)})();Y.strings=(e=>{let t=J.innerHTML;return t?(J.innerHTML="",Y.startDelete?(J.innerHTML=t,s(J),F(N({func:Q,delay:M(1),deletable:!0},A().length)),e):t.replace(/<!--(.+?)-->/g,"").trim().split(/<br(?:\s*?)(?:\/)?>/).concat(e)):e})(i(Y.strings)),Y.strings.length&&k()},{useRef:H,useEffect:R,useState:F}=n,j=e.forwardRef(((e,t)=>{const{as:r}=e;return n.createElement(r,{ref:t,...e})})),k=e=>{const t=H(null),r=H(null),{options:i,children:a,getBeforeInit:o,getAfterInit:s,...l}=e,[u,c]=F(!0),[d,f]=F(null);return R((()=>{t.current&&(!function(){const e=Object.assign({},i);a&&t.current&&(e.strings=t.current.innerHTML),f(e)}(),c(!1))}),[i]),R((()=>{var e;t.current&&d&&((null==(e=r.current)?void 0:e.updateOptions(d))||(r.current=new $(t.current,d),r.current=o(r.current),r.current.go(),r.current=s(r.current)))}),[d]),R((()=>()=>{var e;return null==(e=r.current)?void 0:e.destroy()}),[]),n.createElement(j,{ref:t,children:u?a:null,style:{opacity:u?0:1},...l})};return k.defaultProps={as:"span",options:{},getBeforeInit:e=>e,getAfterInit:e=>e},k})); |
{ | ||
"name": "typeit-react", | ||
"version": "2.6.1", | ||
"version": "2.6.2", | ||
"description": "React component for the most versatile JavaScript animated typing utility on the planet.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://typeitjs.com", |
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
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
47174
1037