typeit-react
Advanced tools
Comparing version 2.7.2 to 2.7.3
@@ -490,3 +490,3 @@ var __defProp = Object.defineProperty; | ||
__privateAdd(this, _buildOptions, (options) => { | ||
options.cursor = processCursorOptions( | ||
this.opts.cursor = processCursorOptions( | ||
options.cursor ?? DEFAULT_OPTIONS.cursor | ||
@@ -493,0 +493,0 @@ ); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).TypeIt=e(t.React)}(this,(function(t){"use strict";var e,s,i,n,r,o,a,l,u,h,c,d,f,p,m,y,g,b,v,w,T,P,E,S,C,q,I,L=Object.defineProperty,N=t=>{throw TypeError(t)},x=(t,e,s)=>((t,e,s)=>e in t?L(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s)(t,"symbol"!=typeof e?e+"":e,s),D=(t,e,s)=>e.has(t)||N("Cannot "+s),M=(t,e,s)=>(D(t,e,"read from private field"),s?s.call(t):e.get(t)),A=(t,e,s)=>e.has(t)?N("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,s),O=(t,e,s)=>(D(t,e,"access private method"),s);const $=t=>Array.isArray(t),R=t=>$(t)?t:[t];const k="data-typeit-id",H="ti-cursor",z={started:!1,completed:!1,frozen:!1,destroyed:!1},F={breakLines:!0,cursor:{autoPause:!0,autoPauseDelay:500,animation:{frames:[0,0,1].map((t=>({opacity:t}))),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:()=>{}},B=`[${k}]:before {content: '.'; display: inline-block; width: 0; visibility: hidden;}`,j=t=>document.createElement(t),_=t=>document.createTextNode(t),W=(t,e="")=>{let s=j("style");s.id=e,s.appendChild(_(t)),document.head.appendChild(s)},U=t=>($(t)||(t=[t/2,t/2]),t),V=(t,e)=>Math.abs(Math.random()*(t+e-(t-e))+(t-e));let Q=t=>t/2;const J=t=>Array.from(t);let X=t=>([...t.childNodes].forEach((t=>{if(t.nodeValue)return[...t.nodeValue].forEach((e=>{t.parentNode.insertBefore(_(e),t)})),void t.remove();X(t)})),t);const G=t=>{let e=document.implementation.createHTMLDocument();return e.body.innerHTML=t,X(e.body)};function K(t,e=!1,s=!1){let i,n=t.querySelector(`.${H}`),r=document.createTreeWalker(t,NodeFilter.SHOW_ALL,{acceptNode:t=>{var e,i;if(n&&s){if(null==(e=t.classList)?void 0:e.contains(H))return NodeFilter.FILTER_ACCEPT;if(n.contains(t))return NodeFilter.FILTER_REJECT}return(null==(i=t.classList)?void 0:i.contains(H))?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),o=[];for(;i=r.nextNode();)i.originalParent||(i.originalParent=i.parentNode),o.push(i);return e?o.reverse():o}function Y(t,e=!0){return e?K(G(t)):J(t).map(_)}const Z=({index:t,newIndex:e,queueItems:s,cleanUp:i})=>{for(let n=t+1;n<e+1;n++)i(s[n][0])},tt=t=>Number.isInteger(t),et=({queueItems:t,selector:e,cursorPosition:s,to:i})=>{if(tt(e))return-1*e;let n=new RegExp("END","i").test(i),r=e?[...t].reverse().findIndex((({char:t})=>{let s=t.parentElement,i=s.matches(e);return!(!n||!i)||i&&s.firstChild.isSameNode(t)})):-1;return r<0&&(r=n?0:t.length-1),r-s+(n?0:1)},st=(t,e)=>new Array(e).fill(t);let it=t=>new Promise((e=>{requestAnimationFrame((async()=>{e(await t())}))})),nt=t=>null==t?void 0:t.getAnimations().find((e=>e.id===t.dataset.tiAnimationId)),rt=({cursor:t,frames:e,options:s})=>{let i=t.animate(e,s);return i.pause(),i.id=t.dataset.tiAnimationId,it((()=>{it((()=>{i.play()}))})),i},ot=t=>{var e;return null==(e=t.func)?void 0:e.call(null)},at=async({index:t,queueItems:e,wait:s,cursor:i,cursorOptions:n})=>{let r=e[t][1],o=[],a=t,l=r,u=()=>l&&!l.delay,h=r.shouldPauseCursor()&&n.autoPause;for(;u();)o.push(l),u()&&a++,l=e[a]?e[a][1]:null;if(o.length)return await it((async()=>{for(let t of o)await ot(t)})),a-1;let c,d=nt(i);return d&&(c={...d.effect.getComputedTiming(),delay:h?n.autoPauseDelay:0}),await s((async()=>{d&&h&&d.cancel(),await it((()=>{ot(r)}))}),r.delay),await(({cursor:t,options:e,cursorOptions:s})=>{if(!t||!s)return;let i,n=nt(t);n&&(e.delay=n.effect.getComputedTiming().delay,i=n.currentTime,n.cancel());let r=rt({cursor:t,frames:s.animation.frames,options:e});return i&&(r.currentTime=i),r})({cursor:i,options:c,cursorOptions:n}),t};const lt=t=>"value"in t;let ut=t=>"function"==typeof t?t():t,ht=(t,e=document,s=!1)=>e["querySelector"+(s?"All":"")](t);const ct=(t,e)=>Object.assign({},t,e);let dt={"font-family":"","font-weight":"","font-size":"","font-style":"","line-height":"",color:"",transform:"translateX(-.125em)"};let ft=(I=class{constructor(t,s={}){var i;A(this,e),x(this,"element"),x(this,"timeouts"),x(this,"cursorPosition"),x(this,"predictedCursorPosition"),x(this,"statuses",{started:!1,completed:!1,frozen:!1,destroyed:!1}),x(this,"opts"),x(this,"id"),x(this,"queue"),x(this,"cursor"),x(this,"unfreeze",(()=>{})),x(this,"is",(function(t){return this.statuses[t]})),A(this,m,(t=>{t.cursor=(t=>{var e,s;if("object"==typeof t){let i={},{frames:n,options:r}=F.cursor.animation;return i.animation=t.animation||{},i.animation.frames=(null==(e=t.animation)?void 0:e.frames)||n,i.animation.options=ct(r,(null==(s=t.animation)?void 0:s.options)||{}),i.autoPause=t.autoPause??F.cursor.autoPause,i.autoPauseDelay=t.autoPauseDelay||F.cursor.autoPauseDelay,i}return!0===t?F.cursor:t})(t.cursor??F.cursor),this.opts.strings=O(this,e,y).call(this,R(this.opts.strings)),this.opts=ct(this.opts,{html:!M(this,e,S)&&this.opts.html,nextStringDelay:U(this.opts.nextStringDelay),loopDelay:U(this.opts.loopDelay)})})),this.opts=ct(F,s),this.element="string"==typeof(i=t)?ht(i):i,this.timeouts=[],this.cursorPosition=0,this.unfreeze=()=>{},this.predictedCursorPosition=null,this.statuses=ct({},z),this.id=Math.random().toString().substring(2,9),this.queue=function(t){let e=function(t){return R(t).forEach((t=>{var e;return n.set(Symbol(null==(e=t.char)?void 0:e.innerText),s({...t}))})),this},s=t=>(t.shouldPauseCursor=function(){return Boolean(this.typeable||this.cursorable||this.deletable)},t),i=()=>Array.from(n.values()),n=new Map;return e(t),{add:e,set:function(t,e){let i=[...n.keys()];n.set(i[t],s(e))},wipe:function(){n=new Map,e(t)},done:(t,e=!1)=>e?n.delete(t):n.get(t).done=!0,reset:function(){n.forEach((t=>delete t.done))},destroy:t=>n.delete(t),getItems:(t=!1)=>t?i():i().filter((t=>!t.done)),getQueue:()=>n,getTypeable:()=>i().filter((t=>t.typeable))}}([{delay:this.opts.startDelay}]),M(this,m).call(this,s),this.cursor=O(this,e,g).call(this),this.element.dataset.typeitId=this.id,W(B),this.opts.strings.length&&O(this,e,p).call(this)}go(){return this.statuses.started?this:(O(this,e,l).call(this),this.opts.waitUntilVisible?(t=this.element,s=O(this,e,i).bind(this),new IntersectionObserver(((e,i)=>{e.forEach((e=>{e.isIntersecting&&(s(),i.unobserve(t))}))}),{threshold:1}).observe(t),this):(O(this,e,i).call(this),this));var t,s}destroy(t=!0){this.timeouts=(this.timeouts.forEach(clearTimeout),[]),ut(t)&&this.cursor&&O(this,e,T).call(this,this.cursor),this.statuses.destroyed=!0}reset(t){!this.is("destroyed")&&this.destroy(),t?(this.queue.wipe(),t(this)):this.queue.reset(),this.cursorPosition=0;for(let e in this.statuses)this.statuses[e]=!1;return this.element[O(this,e,u).call(this)?"value":"innerHTML"]="",this}type(t,s={}){t=ut(t);let{instant:i}=s,n=O(this,e,d).call(this,s),r=Y(t,this.opts.html).map((t=>{return{func:()=>O(this,e,v).call(this,t),char:t,delay:i||(s=t,/<(.+)>(.*?)<\/(.+)>/.test(s.outerHTML))?0:O(this,e,P).call(this),typeable:t.nodeType===Node.TEXT_NODE};var s})),o=[n[0],{func:async()=>await this.opts.beforeString(t,this)},...r,{func:async()=>await this.opts.afterString(t,this)},n[1]];return O(this,e,h).call(this,o,s)}break(t={}){return O(this,e,h).call(this,{func:()=>O(this,e,v).call(this,j("BR")),typeable:!0},t)}move(t,s={}){t=ut(t);let i=O(this,e,d).call(this,s),{instant:r,to:o}=s,a=et({queueItems:this.queue.getTypeable(),selector:null===t?"":t,to:o,cursorPosition:M(this,e,E)}),l=a<0?-1:1;return this.predictedCursorPosition=M(this,e,E)+a,O(this,e,h).call(this,[i[0],...st({func:()=>O(this,e,n).call(this,l),delay:r?0:O(this,e,P).call(this),cursorable:!0},Math.abs(a)),i[1]],s)}exec(t,s={}){let i=O(this,e,d).call(this,s);return O(this,e,h).call(this,[i[0],{func:()=>t(this)},i[1]],s)}options(t,s={}){return t=ut(t),O(this,e,f).call(this,t),O(this,e,h).call(this,{},s)}pause(t,s={}){return O(this,e,h).call(this,{delay:ut(t)},s)}delete(t=null,s={}){t=ut(t);let i=O(this,e,d).call(this,s),n=t,{instant:r,to:o}=s,a=this.queue.getTypeable(),l=(()=>null===n?a.length:tt(n)?n:et({queueItems:a,selector:n,cursorPosition:M(this,e,E),to:o}))();return O(this,e,h).call(this,[i[0],...st({func:O(this,e,w).bind(this),delay:r?0:O(this,e,P).call(this,1),deletable:!0},l),i[1]],s)}freeze(){this.statuses.frozen=!0}flush(t=()=>{}){return O(this,e,l).call(this),O(this,e,i).call(this,!1).then(t),this}getQueue(){return this.queue}getOptions(){return this.opts}updateOptions(t){return O(this,e,f).call(this,t)}getElement(){return this.element}empty(t={}){return O(this,e,h).call(this,{func:O(this,e,s).bind(this)},t)}},e=new WeakSet,s=async function(){O(this,e,u).call(this)?this.element.value="":M(this,e,q).forEach(O(this,e,T).bind(this))},i=async function(t=!0){this.statuses.started=!0;let s=e=>{this.queue.done(e,!t)};try{let n=[...this.queue.getQueue()];for(let t=0;t<n.length;t++){let[i,r]=n[t];if(!r.done){if(!r.deletable||r.deletable&&M(this,e,q).length){let i=await O(this,e,o).call(this,t,n);Z({index:t,newIndex:i,queueItems:n,cleanUp:s}),t=i}s(i)}}if(!t)return this;if(this.statuses.completed=!0,await this.opts.afterComplete(this),!this.opts.loop)throw"";let l=this.opts.loopDelay;O(this,e,a).call(this,(async()=>{await O(this,e,r).call(this,l[0]),O(this,e,i).call(this)}),l[1])}catch(n){}return this},n=async function(t){var s,i,n;this.cursorPosition=(s=t,i=this.cursorPosition,n=M(this,e,q),Math.min(Math.max(i+s,0),n.length)),((t,e,s)=>{let i=e[s-1],n=ht(`.${H}`,t);(t=(null==i?void 0:i.parentNode)||t).insertBefore(n,i||null)})(this.element,M(this,e,q),this.cursorPosition)},r=async function(t){let s=M(this,e,E);s&&await O(this,e,n).call(this,{value:s});let i=M(this,e,q).map((t=>[Symbol(),{func:O(this,e,w).bind(this),delay:O(this,e,P).call(this,1),deletable:!0,shouldPauseCursor:()=>!0}]));for(let n=0;n<i.length;n++)await O(this,e,o).call(this,n,i);this.queue.reset(),this.queue.set(0,{delay:t})},o=function(t,s){return at({index:t,queueItems:s,wait:O(this,e,a).bind(this),cursor:this.cursor,cursorOptions:this.opts.cursor})},a=async function(t,e,s=!1){this.statuses.frozen&&await new Promise((t=>{this.unfreeze=()=>{this.statuses.frozen=!1,t()}})),s||await this.opts.beforeStep(this),await((t,e,s)=>new Promise((i=>{s.push(setTimeout((async()=>{await t(),i()}),e||0))})))(t,e,this.timeouts),s||await this.opts.afterStep(this)},l=async function(){if(!O(this,e,u).call(this)&&this.cursor&&this.element.appendChild(this.cursor),M(this,e,C)){((t,e)=>{let s=`[${k}='${t}'] .${H}`,i=getComputedStyle(e),n=Object.entries(dt).reduce(((t,[e,s])=>`${t} ${e}: var(--ti-cursor-${e}, ${s||i[e]});`),"");W(`${s} { display: inline-block; width: 0; ${n} }`,t)})(this.id,this.element),this.cursor.dataset.tiAnimationId=this.id;let{animation:t}=this.opts.cursor,{frames:e,options:s}=t;rt({frames:e,cursor:this.cursor,options:{duration:this.opts.cursorSpeed,...s}})}},u=function(){return lt(this.element)},h=function(t,s){return this.queue.add(t),O(this,e,c).call(this,s),this},c=function(t={}){let e=t.delay;e&&this.queue.add({delay:e})},d=function(t={}){return[{func:()=>O(this,e,f).call(this,t)},{func:()=>O(this,e,f).call(this,this.opts)}]},f=async function(t){this.opts=ct(this.opts,t)},p=function(){let t=this.opts.strings.filter((t=>!!t));t.forEach(((s,i)=>{if(this.type(s),i+1===t.length)return;let n=this.opts.breakLines?[{func:()=>O(this,e,v).call(this,j("BR")),typeable:!0}]:st({func:O(this,e,w).bind(this),delay:O(this,e,P).call(this,1)},this.queue.getTypeable().length);O(this,e,b).call(this,n)}))},m=new WeakMap,y=function(t){let s=this.element.innerHTML;return s?(this.element.innerHTML="",this.opts.startDelete?(this.element.innerHTML=s,X(this.element),O(this,e,b).call(this,st({func:O(this,e,w).bind(this),delay:O(this,e,P).call(this,1),deletable:!0},M(this,e,q).length)),t):(i=s,i.replace(/<!--(.+?)-->/g,"").trim().split(/<br(?:\s*?)(?:\/)?>/)).concat(t)):t;var i},g=function(){if(M(this,e,S))return null;let t=j("span");return t.className=H,M(this,e,C)?(t.innerHTML=G(this.opts.cursorChar).innerHTML,t):(t.style.visibility="hidden",t)},b=function(t){let e=this.opts.nextStringDelay;this.queue.add([{delay:e[0]},...t,{delay:e[1]}])},v=function(t){((t,e)=>{if(lt(t))return void(t.value=`${t.value}${e.textContent}`);e.innerHTML="";let s=(i=e.originalParent,/body/i.test(null==i?void 0:i.tagName)?t:e.originalParent||t);var i;s.insertBefore(e,ht("."+H,s)||null)})(this.element,t)},w=function(){M(this,e,q).length&&(M(this,e,S)?this.element.value=this.element.value.slice(0,-1):O(this,e,T).call(this,M(this,e,q)[this.cursorPosition]))},T=function(t){((t,e)=>{if(!t)return;let s=t.parentNode;(s.childNodes.length>1||s.isSameNode(e)?t:s).remove()})(t,this.element)},P=function(t=0){return function(t){let{speed:e,deleteSpeed:s,lifeLike:i}=t;return s=null!==s?s:e/3,i?[V(e,Q(e)),V(s,Q(s))]:[e,s]}(this.opts)[t]},E=function(){return this.predictedCursorPosition??this.cursorPosition},S=function(){return lt(this.element)},C=function(){return!!this.opts.cursor&&!M(this,e,S)},q=function(){return t=this.element,lt(t)?J(t.value):K(t,!0).filter((t=>!(t.childNodes.length>0)));var t},I);const pt=t.forwardRef(((e,s)=>{const{as:i}=e;return t.createElement(i,{ref:s,...e})})),mt={};return({as:e="span",options:s=mt,children:i=null,getBeforeInit:n=t=>t,getAfterInit:r=t=>t,...o})=>{const a=t.useRef(null),l=t.useRef(null),[u,h]=t.useState(!0),[c,d]=t.useState(null);return t.useEffect((()=>{!function(){const t=Object.assign({},s);i&&a.current&&(t.strings=a.current.innerHTML),d(t)}(),h(!1)}),[s]),t.useEffect((()=>{var t;c&&((null==(t=l.current)?void 0:t.updateOptions(c))||(l.current=new ft(a.current,c),l.current=n(l.current),l.current.go(),l.current=r(l.current)))}),[c]),t.useEffect((()=>()=>{var t;return null==(t=l.current)?void 0:t.destroy()}),[]),t.createElement(pt,{ref:a,as:e,children:u?i:null,style:{opacity:u?0:1},...o})}})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).TypeIt=e(t.React)}(this,(function(t){"use strict";var e,s,i,n,r,o,a,l,u,h,c,d,f,p,m,y,g,b,v,w,T,P,E,S,C,q,I,L=Object.defineProperty,N=t=>{throw TypeError(t)},x=(t,e,s)=>((t,e,s)=>e in t?L(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s)(t,"symbol"!=typeof e?e+"":e,s),D=(t,e,s)=>e.has(t)||N("Cannot "+s),M=(t,e,s)=>(D(t,e,"read from private field"),s?s.call(t):e.get(t)),A=(t,e,s)=>e.has(t)?N("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,s),O=(t,e,s)=>(D(t,e,"access private method"),s);const $=t=>Array.isArray(t),R=t=>$(t)?t:[t];const k="data-typeit-id",H="ti-cursor",z={started:!1,completed:!1,frozen:!1,destroyed:!1},F={breakLines:!0,cursor:{autoPause:!0,autoPauseDelay:500,animation:{frames:[0,0,1].map((t=>({opacity:t}))),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:()=>{}},B=`[${k}]:before {content: '.'; display: inline-block; width: 0; visibility: hidden;}`,j=t=>document.createElement(t),_=t=>document.createTextNode(t),W=(t,e="")=>{let s=j("style");s.id=e,s.appendChild(_(t)),document.head.appendChild(s)},U=t=>($(t)||(t=[t/2,t/2]),t),V=(t,e)=>Math.abs(Math.random()*(t+e-(t-e))+(t-e));let Q=t=>t/2;const J=t=>Array.from(t);let X=t=>([...t.childNodes].forEach((t=>{if(t.nodeValue)return[...t.nodeValue].forEach((e=>{t.parentNode.insertBefore(_(e),t)})),void t.remove();X(t)})),t);const G=t=>{let e=document.implementation.createHTMLDocument();return e.body.innerHTML=t,X(e.body)};function K(t,e=!1,s=!1){let i,n=t.querySelector(`.${H}`),r=document.createTreeWalker(t,NodeFilter.SHOW_ALL,{acceptNode:t=>{var e,i;if(n&&s){if(null==(e=t.classList)?void 0:e.contains(H))return NodeFilter.FILTER_ACCEPT;if(n.contains(t))return NodeFilter.FILTER_REJECT}return(null==(i=t.classList)?void 0:i.contains(H))?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),o=[];for(;i=r.nextNode();)i.originalParent||(i.originalParent=i.parentNode),o.push(i);return e?o.reverse():o}function Y(t,e=!0){return e?K(G(t)):J(t).map(_)}const Z=({index:t,newIndex:e,queueItems:s,cleanUp:i})=>{for(let n=t+1;n<e+1;n++)i(s[n][0])},tt=t=>Number.isInteger(t),et=({queueItems:t,selector:e,cursorPosition:s,to:i})=>{if(tt(e))return-1*e;let n=new RegExp("END","i").test(i),r=e?[...t].reverse().findIndex((({char:t})=>{let s=t.parentElement,i=s.matches(e);return!(!n||!i)||i&&s.firstChild.isSameNode(t)})):-1;return r<0&&(r=n?0:t.length-1),r-s+(n?0:1)},st=(t,e)=>new Array(e).fill(t);let it=t=>new Promise((e=>{requestAnimationFrame((async()=>{e(await t())}))})),nt=t=>null==t?void 0:t.getAnimations().find((e=>e.id===t.dataset.tiAnimationId)),rt=({cursor:t,frames:e,options:s})=>{let i=t.animate(e,s);return i.pause(),i.id=t.dataset.tiAnimationId,it((()=>{it((()=>{i.play()}))})),i},ot=t=>{var e;return null==(e=t.func)?void 0:e.call(null)},at=async({index:t,queueItems:e,wait:s,cursor:i,cursorOptions:n})=>{let r=e[t][1],o=[],a=t,l=r,u=()=>l&&!l.delay,h=r.shouldPauseCursor()&&n.autoPause;for(;u();)o.push(l),u()&&a++,l=e[a]?e[a][1]:null;if(o.length)return await it((async()=>{for(let t of o)await ot(t)})),a-1;let c,d=nt(i);return d&&(c={...d.effect.getComputedTiming(),delay:h?n.autoPauseDelay:0}),await s((async()=>{d&&h&&d.cancel(),await it((()=>{ot(r)}))}),r.delay),await(({cursor:t,options:e,cursorOptions:s})=>{if(!t||!s)return;let i,n=nt(t);n&&(e.delay=n.effect.getComputedTiming().delay,i=n.currentTime,n.cancel());let r=rt({cursor:t,frames:s.animation.frames,options:e});return i&&(r.currentTime=i),r})({cursor:i,options:c,cursorOptions:n}),t};const lt=t=>"value"in t;let ut=t=>"function"==typeof t?t():t,ht=(t,e=document,s=!1)=>e["querySelector"+(s?"All":"")](t);const ct=(t,e)=>Object.assign({},t,e);let dt={"font-family":"","font-weight":"","font-size":"","font-style":"","line-height":"",color:"",transform:"translateX(-.125em)"};let ft=(I=class{constructor(t,s={}){var i;A(this,e),x(this,"element"),x(this,"timeouts"),x(this,"cursorPosition"),x(this,"predictedCursorPosition"),x(this,"statuses",{started:!1,completed:!1,frozen:!1,destroyed:!1}),x(this,"opts"),x(this,"id"),x(this,"queue"),x(this,"cursor"),x(this,"unfreeze",(()=>{})),x(this,"is",(function(t){return this.statuses[t]})),A(this,m,(t=>{this.opts.cursor=(t=>{var e,s;if("object"==typeof t){let i={},{frames:n,options:r}=F.cursor.animation;return i.animation=t.animation||{},i.animation.frames=(null==(e=t.animation)?void 0:e.frames)||n,i.animation.options=ct(r,(null==(s=t.animation)?void 0:s.options)||{}),i.autoPause=t.autoPause??F.cursor.autoPause,i.autoPauseDelay=t.autoPauseDelay||F.cursor.autoPauseDelay,i}return!0===t?F.cursor:t})(t.cursor??F.cursor),this.opts.strings=O(this,e,y).call(this,R(this.opts.strings)),this.opts=ct(this.opts,{html:!M(this,e,S)&&this.opts.html,nextStringDelay:U(this.opts.nextStringDelay),loopDelay:U(this.opts.loopDelay)})})),this.opts=ct(F,s),this.element="string"==typeof(i=t)?ht(i):i,this.timeouts=[],this.cursorPosition=0,this.unfreeze=()=>{},this.predictedCursorPosition=null,this.statuses=ct({},z),this.id=Math.random().toString().substring(2,9),this.queue=function(t){let e=function(t){return R(t).forEach((t=>{var e;return n.set(Symbol(null==(e=t.char)?void 0:e.innerText),s({...t}))})),this},s=t=>(t.shouldPauseCursor=function(){return Boolean(this.typeable||this.cursorable||this.deletable)},t),i=()=>Array.from(n.values()),n=new Map;return e(t),{add:e,set:function(t,e){let i=[...n.keys()];n.set(i[t],s(e))},wipe:function(){n=new Map,e(t)},done:(t,e=!1)=>e?n.delete(t):n.get(t).done=!0,reset:function(){n.forEach((t=>delete t.done))},destroy:t=>n.delete(t),getItems:(t=!1)=>t?i():i().filter((t=>!t.done)),getQueue:()=>n,getTypeable:()=>i().filter((t=>t.typeable))}}([{delay:this.opts.startDelay}]),M(this,m).call(this,s),this.cursor=O(this,e,g).call(this),this.element.dataset.typeitId=this.id,W(B),this.opts.strings.length&&O(this,e,p).call(this)}go(){return this.statuses.started?this:(O(this,e,l).call(this),this.opts.waitUntilVisible?(t=this.element,s=O(this,e,i).bind(this),new IntersectionObserver(((e,i)=>{e.forEach((e=>{e.isIntersecting&&(s(),i.unobserve(t))}))}),{threshold:1}).observe(t),this):(O(this,e,i).call(this),this));var t,s}destroy(t=!0){this.timeouts=(this.timeouts.forEach(clearTimeout),[]),ut(t)&&this.cursor&&O(this,e,T).call(this,this.cursor),this.statuses.destroyed=!0}reset(t){!this.is("destroyed")&&this.destroy(),t?(this.queue.wipe(),t(this)):this.queue.reset(),this.cursorPosition=0;for(let e in this.statuses)this.statuses[e]=!1;return this.element[O(this,e,u).call(this)?"value":"innerHTML"]="",this}type(t,s={}){t=ut(t);let{instant:i}=s,n=O(this,e,d).call(this,s),r=Y(t,this.opts.html).map((t=>{return{func:()=>O(this,e,v).call(this,t),char:t,delay:i||(s=t,/<(.+)>(.*?)<\/(.+)>/.test(s.outerHTML))?0:O(this,e,P).call(this),typeable:t.nodeType===Node.TEXT_NODE};var s})),o=[n[0],{func:async()=>await this.opts.beforeString(t,this)},...r,{func:async()=>await this.opts.afterString(t,this)},n[1]];return O(this,e,h).call(this,o,s)}break(t={}){return O(this,e,h).call(this,{func:()=>O(this,e,v).call(this,j("BR")),typeable:!0},t)}move(t,s={}){t=ut(t);let i=O(this,e,d).call(this,s),{instant:r,to:o}=s,a=et({queueItems:this.queue.getTypeable(),selector:null===t?"":t,to:o,cursorPosition:M(this,e,E)}),l=a<0?-1:1;return this.predictedCursorPosition=M(this,e,E)+a,O(this,e,h).call(this,[i[0],...st({func:()=>O(this,e,n).call(this,l),delay:r?0:O(this,e,P).call(this),cursorable:!0},Math.abs(a)),i[1]],s)}exec(t,s={}){let i=O(this,e,d).call(this,s);return O(this,e,h).call(this,[i[0],{func:()=>t(this)},i[1]],s)}options(t,s={}){return t=ut(t),O(this,e,f).call(this,t),O(this,e,h).call(this,{},s)}pause(t,s={}){return O(this,e,h).call(this,{delay:ut(t)},s)}delete(t=null,s={}){t=ut(t);let i=O(this,e,d).call(this,s),n=t,{instant:r,to:o}=s,a=this.queue.getTypeable(),l=(()=>null===n?a.length:tt(n)?n:et({queueItems:a,selector:n,cursorPosition:M(this,e,E),to:o}))();return O(this,e,h).call(this,[i[0],...st({func:O(this,e,w).bind(this),delay:r?0:O(this,e,P).call(this,1),deletable:!0},l),i[1]],s)}freeze(){this.statuses.frozen=!0}flush(t=()=>{}){return O(this,e,l).call(this),O(this,e,i).call(this,!1).then(t),this}getQueue(){return this.queue}getOptions(){return this.opts}updateOptions(t){return O(this,e,f).call(this,t)}getElement(){return this.element}empty(t={}){return O(this,e,h).call(this,{func:O(this,e,s).bind(this)},t)}},e=new WeakSet,s=async function(){O(this,e,u).call(this)?this.element.value="":M(this,e,q).forEach(O(this,e,T).bind(this))},i=async function(t=!0){this.statuses.started=!0;let s=e=>{this.queue.done(e,!t)};try{let n=[...this.queue.getQueue()];for(let t=0;t<n.length;t++){let[i,r]=n[t];if(!r.done){if(!r.deletable||r.deletable&&M(this,e,q).length){let i=await O(this,e,o).call(this,t,n);Z({index:t,newIndex:i,queueItems:n,cleanUp:s}),t=i}s(i)}}if(!t)return this;if(this.statuses.completed=!0,await this.opts.afterComplete(this),!this.opts.loop)throw"";let l=this.opts.loopDelay;O(this,e,a).call(this,(async()=>{await O(this,e,r).call(this,l[0]),O(this,e,i).call(this)}),l[1])}catch(n){}return this},n=async function(t){var s,i,n;this.cursorPosition=(s=t,i=this.cursorPosition,n=M(this,e,q),Math.min(Math.max(i+s,0),n.length)),((t,e,s)=>{let i=e[s-1],n=ht(`.${H}`,t);(t=(null==i?void 0:i.parentNode)||t).insertBefore(n,i||null)})(this.element,M(this,e,q),this.cursorPosition)},r=async function(t){let s=M(this,e,E);s&&await O(this,e,n).call(this,{value:s});let i=M(this,e,q).map((t=>[Symbol(),{func:O(this,e,w).bind(this),delay:O(this,e,P).call(this,1),deletable:!0,shouldPauseCursor:()=>!0}]));for(let n=0;n<i.length;n++)await O(this,e,o).call(this,n,i);this.queue.reset(),this.queue.set(0,{delay:t})},o=function(t,s){return at({index:t,queueItems:s,wait:O(this,e,a).bind(this),cursor:this.cursor,cursorOptions:this.opts.cursor})},a=async function(t,e,s=!1){this.statuses.frozen&&await new Promise((t=>{this.unfreeze=()=>{this.statuses.frozen=!1,t()}})),s||await this.opts.beforeStep(this),await((t,e,s)=>new Promise((i=>{s.push(setTimeout((async()=>{await t(),i()}),e||0))})))(t,e,this.timeouts),s||await this.opts.afterStep(this)},l=async function(){if(!O(this,e,u).call(this)&&this.cursor&&this.element.appendChild(this.cursor),M(this,e,C)){((t,e)=>{let s=`[${k}='${t}'] .${H}`,i=getComputedStyle(e),n=Object.entries(dt).reduce(((t,[e,s])=>`${t} ${e}: var(--ti-cursor-${e}, ${s||i[e]});`),"");W(`${s} { display: inline-block; width: 0; ${n} }`,t)})(this.id,this.element),this.cursor.dataset.tiAnimationId=this.id;let{animation:t}=this.opts.cursor,{frames:e,options:s}=t;rt({frames:e,cursor:this.cursor,options:{duration:this.opts.cursorSpeed,...s}})}},u=function(){return lt(this.element)},h=function(t,s){return this.queue.add(t),O(this,e,c).call(this,s),this},c=function(t={}){let e=t.delay;e&&this.queue.add({delay:e})},d=function(t={}){return[{func:()=>O(this,e,f).call(this,t)},{func:()=>O(this,e,f).call(this,this.opts)}]},f=async function(t){this.opts=ct(this.opts,t)},p=function(){let t=this.opts.strings.filter((t=>!!t));t.forEach(((s,i)=>{if(this.type(s),i+1===t.length)return;let n=this.opts.breakLines?[{func:()=>O(this,e,v).call(this,j("BR")),typeable:!0}]:st({func:O(this,e,w).bind(this),delay:O(this,e,P).call(this,1)},this.queue.getTypeable().length);O(this,e,b).call(this,n)}))},m=new WeakMap,y=function(t){let s=this.element.innerHTML;return s?(this.element.innerHTML="",this.opts.startDelete?(this.element.innerHTML=s,X(this.element),O(this,e,b).call(this,st({func:O(this,e,w).bind(this),delay:O(this,e,P).call(this,1),deletable:!0},M(this,e,q).length)),t):(i=s,i.replace(/<!--(.+?)-->/g,"").trim().split(/<br(?:\s*?)(?:\/)?>/)).concat(t)):t;var i},g=function(){if(M(this,e,S))return null;let t=j("span");return t.className=H,M(this,e,C)?(t.innerHTML=G(this.opts.cursorChar).innerHTML,t):(t.style.visibility="hidden",t)},b=function(t){let e=this.opts.nextStringDelay;this.queue.add([{delay:e[0]},...t,{delay:e[1]}])},v=function(t){((t,e)=>{if(lt(t))return void(t.value=`${t.value}${e.textContent}`);e.innerHTML="";let s=(i=e.originalParent,/body/i.test(null==i?void 0:i.tagName)?t:e.originalParent||t);var i;s.insertBefore(e,ht("."+H,s)||null)})(this.element,t)},w=function(){M(this,e,q).length&&(M(this,e,S)?this.element.value=this.element.value.slice(0,-1):O(this,e,T).call(this,M(this,e,q)[this.cursorPosition]))},T=function(t){((t,e)=>{if(!t)return;let s=t.parentNode;(s.childNodes.length>1||s.isSameNode(e)?t:s).remove()})(t,this.element)},P=function(t=0){return function(t){let{speed:e,deleteSpeed:s,lifeLike:i}=t;return s=null!==s?s:e/3,i?[V(e,Q(e)),V(s,Q(s))]:[e,s]}(this.opts)[t]},E=function(){return this.predictedCursorPosition??this.cursorPosition},S=function(){return lt(this.element)},C=function(){return!!this.opts.cursor&&!M(this,e,S)},q=function(){return t=this.element,lt(t)?J(t.value):K(t,!0).filter((t=>!(t.childNodes.length>0)));var t},I);const pt=t.forwardRef(((e,s)=>{const{as:i}=e;return t.createElement(i,{ref:s,...e})})),mt={};return({as:e="span",options:s=mt,children:i=null,getBeforeInit:n=t=>t,getAfterInit:r=t=>t,...o})=>{const a=t.useRef(null),l=t.useRef(null),[u,h]=t.useState(!0),[c,d]=t.useState(null);return t.useEffect((()=>{!function(){const t=Object.assign({},s);i&&a.current&&(t.strings=a.current.innerHTML),d(t)}(),h(!1)}),[s]),t.useEffect((()=>{var t;c&&((null==(t=l.current)?void 0:t.updateOptions(c))||(l.current=new ft(a.current,c),l.current=n(l.current),l.current.go(),l.current=r(l.current)))}),[c]),t.useEffect((()=>()=>{var t;return null==(t=l.current)?void 0:t.destroy()}),[]),t.createElement(pt,{ref:a,as:e,children:u?i:null,style:{opacity:u?0:1},...o})}})); |
{ | ||
"name": "typeit-react", | ||
"version": "2.7.2", | ||
"version": "2.7.3", | ||
"description": "React component for the most versatile JavaScript animated typing utility on the planet.", | ||
@@ -43,16 +43,16 @@ "homepage": "https://typeitjs.com", | ||
"react-dom": ">=18.3.1", | ||
"typeit": "^8.8.4" | ||
"typeit": "^8.8.5" | ||
}, | ||
"devDependencies": { | ||
"@babel/preset-typescript": "^7.24.7", | ||
"@testing-library/jest-dom": "^6.4.8", | ||
"@testing-library/react": "^16.0.0", | ||
"@types/react": "^18.3.3", | ||
"jsdom": "^24.1.1", | ||
"terser": "^5.31.3", | ||
"typescript": "^5.5.4", | ||
"vite": "^5.3.4", | ||
"vitest": "^2.0.4", | ||
"@testing-library/jest-dom": "^6.5.0", | ||
"@testing-library/react": "^16.0.1", | ||
"@types/react": "^18.3.5", | ||
"jsdom": "^25.0.0", | ||
"terser": "^5.32.0", | ||
"typescript": "^5.6.2", | ||
"vite": "^5.4.5", | ||
"vitest": "^2.1.1", | ||
"vitest-dom": "^0.1.1" | ||
} | ||
} |
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
58434
1167
Updatedtypeit@^8.8.5