typeit-react
Version:
React component for the most versatile JavaScript animated typing utility on the planet.
11 lines (10 loc) • 24.7 kB
JavaScript
!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";var t,r,n,i,s,o,a,l,u,c,h,f,p,d,y,m,g,b,v,w,S,k,P,C,T,E,j,x,O=Object.defineProperty,N=e=>{throw TypeError(e)},R=(e,t,r)=>((e,t,r)=>t in e?O(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r),_=(e,t,r)=>t.has(e)||N("Cannot "+r),$=(e,t,r)=>(_(e,t,"read from private field"),r?r.call(e):t.get(e)),D=(e,t,r)=>t.has(e)?N("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),I=(e,t,r)=>(_(e,t,"access private method"),r),q={exports:{}},L={};var M,F,A={};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/function z(){return M||(M=1,"production"!==process.env.NODE_ENV&&function(){function t(e){if(null==e)return null;if("function"==typeof e)return e.$$typeof===q?null:e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case C:return"Fragment";case P:return"Portal";case E:return"Profiler";case T:return"StrictMode";case N:return"Suspense";case R:return"SuspenseList"}if("object"==typeof e)switch("number"==typeof e.tag&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case x:return(e.displayName||"Context")+".Provider";case j:return(e._context.displayName||"Context")+".Consumer";case O:var r=e.render;return(e=e.displayName)||(e=""!==(e=r.displayName||r.name||"")?"ForwardRef("+e+")":"ForwardRef"),e;case _:return null!==(r=e.displayName||null)?r:t(e.type)||"Memo";case $:r=e._payload,e=e._init;try{return t(e(r))}catch(n){}}return null}function r(e){return""+e}function n(e){try{r(e);var t=!1}catch(s){t=!0}if(t){var n=(t=console).error,i="function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",i),r(e)}}function i(){}function s(e){if(void 0===W)try{throw Error()}catch(r){var t=r.stack.trim().match(/\n( *(at )?)/);W=t&&t[1]||"",B=-1<r.stack.indexOf("\n at")?" (<anonymous>)":-1<r.stack.indexOf("@")?"@unknown:0:0":""}return"\n"+W+e+B}function o(e,t){if(!e||J)return"";var r=X.get(e);if(void 0!==r)return r;J=!0,r=Error.prepareStackTrace,Error.prepareStackTrace=void 0;var n;n=L.H,L.H=null,function(){if(0===U){d=console.log,y=console.info,m=console.warn,g=console.error,b=console.group,v=console.groupCollapsed,w=console.groupEnd;var e={configurable:!0,enumerable:!0,value:i,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}U++}();try{var o={DetermineComponentFrameRoot:function(){try{if(t){var r=function(){throw Error()};if(Object.defineProperty(r.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(r,[])}catch(i){var n=i}Reflect.construct(e,[],r)}else{try{r.call()}catch(s){n=s}e.call(r.prototype)}}else{try{throw Error()}catch(o){n=o}(r=e())&&"function"==typeof r.catch&&r.catch((function(){}))}}catch(a){if(a&&n&&"string"==typeof a.stack)return[a.stack,n.stack]}return[null,null]}};o.DetermineComponentFrameRoot.displayName="DetermineComponentFrameRoot";var a=Object.getOwnPropertyDescriptor(o.DetermineComponentFrameRoot,"name");a&&a.configurable&&Object.defineProperty(o.DetermineComponentFrameRoot,"name",{value:"DetermineComponentFrameRoot"});var l=o.DetermineComponentFrameRoot(),u=l[0],c=l[1];if(u&&c){var h=u.split("\n"),f=c.split("\n");for(l=a=0;a<h.length&&!h[a].includes("DetermineComponentFrameRoot");)a++;for(;l<f.length&&!f[l].includes("DetermineComponentFrameRoot");)l++;if(a===h.length||l===f.length)for(a=h.length-1,l=f.length-1;1<=a&&0<=l&&h[a]!==f[l];)l--;for(;1<=a&&0<=l;a--,l--)if(h[a]!==f[l]){if(1!==a||1!==l)do{if(a--,0>--l||h[a]!==f[l]){var p="\n"+h[a].replace(" at new "," at ");return e.displayName&&p.includes("<anonymous>")&&(p=p.replace("<anonymous>",e.displayName)),"function"==typeof e&&X.set(e,p),p}}while(1<=a&&0<=l);break}}}finally{J=!1,L.H=n,function(){if(0==--U){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:F({},e,{value:d}),info:F({},e,{value:y}),warn:F({},e,{value:m}),error:F({},e,{value:g}),group:F({},e,{value:b}),groupCollapsed:F({},e,{value:v}),groupEnd:F({},e,{value:w})})}0>U&&console.error("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=r}return h=(h=e?e.displayName||e.name:"")?s(h):"","function"==typeof e&&X.set(e,h),h}function a(e){if(null==e)return"";if("function"==typeof e){var t=e.prototype;return o(e,!(!t||!t.isReactComponent))}if("string"==typeof e)return s(e);switch(e){case N:return s("Suspense");case R:return s("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case O:return e=o(e.render,!1);case _:return a(e.type);case $:t=e._payload,e=e._init;try{return a(e(t))}catch(r){}}return""}function l(){var e=L.A;return null===e?null:e.getOwner()}function u(){var e=t(this.type);return K[e]||(K[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),void 0!==(e=this.props.ref)?e:null}function c(e,r,i,s,o,a){if("string"==typeof e||"function"==typeof e||e===C||e===E||e===T||e===N||e===R||e===D||"object"==typeof e&&null!==e&&(e.$$typeof===$||e.$$typeof===_||e.$$typeof===x||e.$$typeof===j||e.$$typeof===O||e.$$typeof===z||void 0!==e.getModuleId)){var c=r.children;if(void 0!==c)if(s)if(H(c)){for(s=0;s<c.length;s++)h(c[s],e);Object.freeze&&Object.freeze(c)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else h(c,e)}else c="",(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(c+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."),null===e?s="null":H(e)?s="array":void 0!==e&&e.$$typeof===k?(s="<"+(t(e.type)||"Unknown")+" />",c=" Did you accidentally export a JSX literal instead of a component?"):s=typeof e,console.error("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",s,c);if(M.call(r,"key")){c=t(e);var f=Object.keys(r).filter((function(e){return"key"!==e}));s=0<f.length?"{key: someKey, "+f.join(": ..., ")+": ...}":"{key: someKey}",Y[c+s]||(f=0<f.length?"{"+f.join(": ..., ")+": ...}":"{}",console.error('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',s,c,f,c),Y[c+s]=!0)}if(c=null,void 0!==i&&(n(i),c=""+i),function(e){if(M.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(r)&&(n(r.key),c=""+r.key),"key"in r)for(var p in i={},r)"key"!==p&&(i[p]=r[p]);else i=r;return c&&function(e,t){function r(){V||(V=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}r.isReactWarning=!0,Object.defineProperty(e,"key",{get:r,configurable:!0})}(i,"function"==typeof e?e.displayName||e.name||"Unknown":e),function(e,t,r,n,i,s){return r=s.ref,e={$$typeof:k,type:e,key:t,props:s,_owner:i},null!==(void 0!==r?r:null)?Object.defineProperty(e,"ref",{enumerable:!1,get:u}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}(e,c,a,0,l(),i)}function h(e,t){if("object"==typeof e&&e&&e.$$typeof!==Q)if(H(e))for(var r=0;r<e.length;r++){var n=e[r];f(n)&&p(n,t)}else if(f(e))e._store&&(e._store.validated=1);else if(null===e||"object"!=typeof e?r=null:r="function"==typeof(r=I&&e[I]||e["@@iterator"])?r:null,"function"==typeof r&&r!==e.entries&&(r=r.call(e))!==e)for(;!(e=r.next()).done;)f(e.value)&&p(e.value,t)}function f(e){return"object"==typeof e&&null!==e&&e.$$typeof===k}function p(e,r){if(e._store&&!e._store.validated&&null==e.key&&(e._store.validated=1,r=function(e){var r="",n=l();return n&&(n=t(n.type))&&(r="\n\nCheck the render method of `"+n+"`."),r||(e=t(e))&&(r="\n\nCheck the top-level render call using <"+e+">."),r}(r),!G[r])){G[r]=!0;var n="";e&&null!=e._owner&&e._owner!==l()&&(n=null,"number"==typeof e._owner.tag?n=t(e._owner.type):"string"==typeof e._owner.name&&(n=e._owner.name),n=" It was passed a child from "+n+".");var i=L.getCurrentStack;L.getCurrentStack=function(){var t=a(e.type);return i&&(t+=i()||""),t},console.error('Each child in a list should have a unique "key" prop.%s%s See https://react.dev/link/warning-keys for more information.',r,n),L.getCurrentStack=i}}var d,y,m,g,b,v,w,S=e,k=Symbol.for("react.transitional.element"),P=Symbol.for("react.portal"),C=Symbol.for("react.fragment"),T=Symbol.for("react.strict_mode"),E=Symbol.for("react.profiler"),j=Symbol.for("react.consumer"),x=Symbol.for("react.context"),O=Symbol.for("react.forward_ref"),N=Symbol.for("react.suspense"),R=Symbol.for("react.suspense_list"),_=Symbol.for("react.memo"),$=Symbol.for("react.lazy"),D=Symbol.for("react.offscreen"),I=Symbol.iterator,q=Symbol.for("react.client.reference"),L=S.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,M=Object.prototype.hasOwnProperty,F=Object.assign,z=Symbol.for("react.client.reference"),H=Array.isArray,U=0;i.__reactDisabledLog=!0;var W,B,V,J=!1,X=new("function"==typeof WeakMap?WeakMap:Map),Q=Symbol.for("react.client.reference"),K={},Y={},G={};A.Fragment=C,A.jsx=function(e,t,r,n,i){return c(e,t,r,!1,0,i)},A.jsxs=function(e,t,r,n,i){return c(e,t,r,!0,0,i)}}()),A}var H=(F||(F=1,"production"===process.env.NODE_ENV?q.exports=function(){if(x)return L;x=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function r(t,r,n){var i=null;if(void 0!==n&&(i=""+n),void 0!==r.key&&(i=""+r.key),"key"in r)for(var s in n={},r)"key"!==s&&(n[s]=r[s]);else n=r;return r=n.ref,{$$typeof:e,type:t,key:i,ref:void 0!==r?r:null,props:n}}return L.Fragment=t,L.jsx=r,L.jsxs=r,L}():q.exports=z()),q.exports);const U=e=>Array.isArray(e),W=e=>U(e)?e:[e];const B="data-typeit-id",V="ti-cursor",J={started:!1,completed:!1,frozen:!1,destroyed:!1},X={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:()=>{}},Q=`[${B}]:before {content: '.'; display: inline-block; width: 0; visibility: hidden;}`,K=e=>document.createElement(e),Y=e=>document.createTextNode(e),G=(e,t="")=>{let r=K("style");r.id=t,r.appendChild(Y(e)),document.head.appendChild(r)},Z=e=>(U(e)||(e=[e/2,e/2]),e),ee=(e,t)=>Math.abs(Math.random()*(e+t-(e-t))+(e-t));let te=e=>e/2;const re=e=>Array.from(e);let ne=e=>([...e.childNodes].forEach((e=>{if(e.nodeValue)return[...e.nodeValue].forEach((t=>{e.parentNode.insertBefore(Y(t),e)})),void e.remove();ne(e)})),e);const ie=e=>{let t=document.implementation.createHTMLDocument();return t.body.innerHTML=e,ne(t.body)};function se(e,t=!1,r=!1){let n,i=e.querySelector(`.${V}`),s=document.createTreeWalker(e,NodeFilter.SHOW_ALL,{acceptNode:e=>{var t,n;if(i&&r){if(null==(t=e.classList)?void 0:t.contains(V))return NodeFilter.FILTER_ACCEPT;if(i.contains(e))return NodeFilter.FILTER_REJECT}return(null==(n=e.classList)?void 0:n.contains(V))?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),o=[];for(;n=s.nextNode();)n.originalParent||(n.originalParent=n.parentNode),o.push(n);return t?o.reverse():o}function oe(e,t=!0){return t?se(ie(e)):re(e).map(Y)}const ae=({index:e,newIndex:t,queueItems:r,cleanUp:n})=>{for(let i=e+1;i<t+1;i++)n(r[i][0])},le=e=>Number.isInteger(e),ue=({queueItems:e,selector:t,cursorPosition:r,to:n})=>{if(le(t))return-1*t;let i=new RegExp("END","i").test(n),s=t?[...e].reverse().findIndex((({char:e})=>{let r=e.parentElement,n=r.matches(t);return!(!i||!n)||n&&r.firstChild.isSameNode(e)})):-1;return s<0&&(s=i?0:e.length-1),s-r+(i?0:1)},ce=(e,t)=>new Array(t).fill(e);let he=e=>new Promise((t=>{requestAnimationFrame((async()=>{t(await e())}))})),fe=e=>null==e?void 0:e.getAnimations().find((t=>t.id===e.dataset.tiAnimationId)),pe=({cursor:e,frames:t,options:r})=>{let n=e.animate(t,r);return n.pause(),n.id=e.dataset.tiAnimationId,he((()=>{he((()=>{n.play()}))})),n},de=e=>{var t;return null==(t=e.func)?void 0:t.call(null)},ye=async({index:e,queueItems:t,wait:r,cursor:n,cursorOptions:i})=>{let s=t[e][1],o=[],a=e,l=s,u=()=>l&&!l.delay,c=s.shouldPauseCursor()&&i.autoPause;for(;u();)o.push(l),u()&&a++,l=t[a]?t[a][1]:null;if(o.length)return await he((async()=>{for(let e of o)await de(e)})),a-1;let h,f=fe(n);return f&&(h={...f.effect.getComputedTiming(),delay:c?i.autoPauseDelay:0}),await r((async()=>{f&&c&&f.cancel(),await he((()=>{de(s)}))}),s.delay),await(({cursor:e,options:t,cursorOptions:r})=>{if(!e||!r)return;let n,i=fe(e);i&&(t.delay=i.effect.getComputedTiming().delay,n=i.currentTime,i.cancel());let s=pe({cursor:e,frames:r.animation.frames,options:t});return n&&(s.currentTime=n),s})({cursor:n,options:h,cursorOptions:i}),e};const me=e=>"value"in e;let ge=e=>"function"==typeof e?e():e,be=(e,t=document,r=!1)=>t["querySelector"+(r?"All":"")](e);const ve=(e,t)=>Object.assign({},e,t);let we={"font-family":"","font-weight":"","font-size":"","font-style":"","line-height":"",color:"",transform:"translateX(-.125em)"};let Se=(j=class{constructor(e,r={}){var n;D(this,t),R(this,"element"),R(this,"timeouts"),R(this,"cursorPosition"),R(this,"predictedCursorPosition"),R(this,"statuses",{started:!1,completed:!1,frozen:!1,destroyed:!1,firing:!1}),R(this,"opts"),R(this,"id"),R(this,"queue"),R(this,"cursor"),R(this,"flushCallback",null),R(this,"unfreeze",(()=>{})),R(this,"is",(function(e){return this.statuses[e]})),D(this,y,(e=>{this.opts.cursor=(e=>{var t,r;if("object"==typeof e){let n={},{frames:i,options:s}=X.cursor.animation;return n.animation=e.animation||{},n.animation.frames=(null==(t=e.animation)?void 0:t.frames)||i,n.animation.options=ve(s,(null==(r=e.animation)?void 0:r.options)||{}),n.autoPause=e.autoPause??X.cursor.autoPause,n.autoPauseDelay=e.autoPauseDelay||X.cursor.autoPauseDelay,n}return!0===e?X.cursor:e})(e.cursor??X.cursor),this.opts.strings=I(this,t,m).call(this,W(this.opts.strings)),this.opts=ve(this.opts,{html:!$(this,t,C)&&this.opts.html,nextStringDelay:Z(this.opts.nextStringDelay),loopDelay:Z(this.opts.loopDelay)})})),this.opts=ve(X,r),this.element="string"==typeof(n=e)?be(n):n,this.timeouts=[],this.cursorPosition=0,this.unfreeze=()=>{},this.predictedCursorPosition=null,this.statuses=ve({},J),this.id=Math.random().toString().substring(2,9),this.queue=function(e){let t=function(e){return W(e).forEach((e=>{var t;return s.set(Symbol(null==(t=e.char)?void 0:t.innerText),r({...e}))})),this},r=e=>(e.shouldPauseCursor=function(){return Boolean(this.typeable||this.cursorable||this.deletable)},e),n=()=>s,i=()=>Array.from(s.values()),s=new Map;return t(e),{add:t,set:function(e,t){let n=[...s.keys()];s.set(n[e],r(t))},wipe:function(){s=new Map,t(e)},done:(e,t=!1)=>t?s.delete(e):s.get(e).done=!0,reset:function(){s.forEach((e=>delete e.done))},destroy:e=>s.delete(e),getItems:(e=!1)=>e?i():i().filter((e=>!e.done)),getQueue:n,getTypeable:()=>i().filter((e=>e.typeable)),getPendingQueueItems:()=>{const e=[];for(let[,t]of n())t.done||e.push(t);return e}}}([{delay:this.opts.startDelay}]),$(this,y).call(this,r),this.cursor=I(this,t,g).call(this),this.element.dataset.typeitId=this.id,G(Q),this.opts.strings.length&&I(this,t,d).call(this)}go(){return this.statuses.started?this:(I(this,t,l).call(this),this.opts.waitUntilVisible?(e=this.element,r=I(this,t,n).bind(this),new IntersectionObserver(((t,n)=>{t.forEach((t=>{t.isIntersecting&&(r(),n.unobserve(e))}))}),{threshold:1}).observe(e),this):(I(this,t,n).call(this),this));var e,r}destroy(e=!0){this.timeouts=(this.timeouts.forEach(clearTimeout),[]),ge(e)&&this.cursor&&I(this,t,S).call(this,this.cursor),this.statuses.destroyed=!0}reset(e){!this.is("destroyed")&&this.destroy(),e?(this.queue.wipe(),e(this)):this.queue.reset(),this.cursorPosition=0;for(let t in this.statuses)this.statuses[t]=!1;return this.element[I(this,t,u).call(this)?"value":"innerHTML"]="",this}type(e,r={}){e=ge(e);let{instant:n}=r,i=I(this,t,f).call(this,r),s=oe(e,this.opts.html).map((e=>{return{func:()=>I(this,t,v).call(this,e),char:e,delay:n||(r=e,/<(.+)>(.*?)<\/(.+)>/.test(r.outerHTML))?0:I(this,t,k).call(this),typeable:e.nodeType===Node.TEXT_NODE};var r})),o=[i[0],{func:async()=>await this.opts.beforeString(e,this)},...s,{func:async()=>await this.opts.afterString(e,this)},i[1]];return I(this,t,c).call(this,o,r)}break(e={}){return I(this,t,c).call(this,{func:()=>I(this,t,v).call(this,K("BR")),typeable:!0},e)}move(e,r={}){e=ge(e);let n=I(this,t,f).call(this,r),{instant:s,to:o}=r,a=ue({queueItems:this.queue.getTypeable(),selector:null===e?"":e,to:o,cursorPosition:$(this,t,P)}),l=a<0?-1:1;return this.predictedCursorPosition=$(this,t,P)+a,I(this,t,c).call(this,[n[0],...ce({func:()=>I(this,t,i).call(this,l),delay:s?0:I(this,t,k).call(this),cursorable:!0},Math.abs(a)),n[1]],r)}exec(e,r={}){let n=I(this,t,f).call(this,r);return I(this,t,c).call(this,[n[0],{func:()=>e(this)},n[1]],r)}options(e,r={}){return e=ge(e),I(this,t,p).call(this,e),I(this,t,c).call(this,{},r)}pause(e,r={}){return I(this,t,c).call(this,{delay:ge(e)},r)}delete(e=null,r={}){e=ge(e);let n=I(this,t,f).call(this,r),i=e,{instant:s,to:o}=r,a=this.queue.getTypeable(),l=(()=>null===i?a.length:le(i)?i:ue({queueItems:a,selector:i,cursorPosition:$(this,t,P),to:o}))();return I(this,t,c).call(this,[n[0],...ce({func:I(this,t,w).bind(this),delay:s?0:I(this,t,k).call(this,1),deletable:!0},l),n[1]],r)}freeze(){this.statuses.frozen=!0}flush(e=null){return this.flushCallback=e||this.flushCallback,this.statuses.firing||(I(this,t,l).call(this),I(this,t,n).call(this,!1).then((()=>{if(this.queue.getPendingQueueItems().length>0)return this.flush();this.flushCallback(),this.flushCallback=null}))),this}getQueue(){return this.queue}getOptions(){return this.opts}updateOptions(e){return I(this,t,p).call(this,e)}getElement(){return this.element}empty(e={}){return I(this,t,c).call(this,{func:I(this,t,r).bind(this)},e)}},t=new WeakSet,r=async function(){I(this,t,u).call(this)?this.element.value="":$(this,t,E).forEach(I(this,t,S).bind(this))},n=async function(e=!0){this.statuses.started=!0,this.statuses.firing=!0;let r=t=>{this.queue.done(t,!e)};try{let i=[...this.queue.getQueue()];for(let e=0;e<i.length;e++){let[n,s]=i[e];if(!s.done){if(!s.deletable||s.deletable&&$(this,t,E).length){let n=await I(this,t,o).call(this,e,i);ae({index:e,newIndex:n,queueItems:i,cleanUp:r}),e=n}r(n)}}if(!e)return this.statuses.firing=!1,this;if(this.statuses.completed=!0,this.statuses.firing=!1,await this.opts.afterComplete(this),!this.opts.loop)throw"";let l=this.opts.loopDelay;I(this,t,a).call(this,(async()=>{await I(this,t,s).call(this,l[0]),I(this,t,n).call(this)}),l[1])}catch(i){}return this.statuses.firing=!1,this},i=async function(e){var r,n,i;this.cursorPosition=(r=e,n=this.cursorPosition,i=$(this,t,E),Math.min(Math.max(n+r,0),i.length)),((e,t,r)=>{let n=t[r-1],i=be(`.${V}`,e);(e=(null==n?void 0:n.parentNode)||e).insertBefore(i,n||null)})(this.element,$(this,t,E),this.cursorPosition)},s=async function(e){let r=$(this,t,P);r&&await I(this,t,i).call(this,{value:r});let n=$(this,t,E).map((e=>[Symbol(),{func:I(this,t,w).bind(this),delay:I(this,t,k).call(this,1),deletable:!0,shouldPauseCursor:()=>!0}]));for(let i=0;i<n.length;i++)await I(this,t,o).call(this,i,n);this.queue.reset(),this.queue.set(0,{delay:e})},o=function(e,r){return ye({index:e,queueItems:r,wait:I(this,t,a).bind(this),cursor:this.cursor,cursorOptions:this.opts.cursor})},a=async function(e,t,r=!1){this.statuses.frozen&&await new Promise((e=>{this.unfreeze=()=>{this.statuses.frozen=!1,e()}})),r||await this.opts.beforeStep(this),await((e,t,r)=>new Promise((n=>{r.push(setTimeout((async()=>{await e(),n()}),t||0))})))(e,t,this.timeouts),r||await this.opts.afterStep(this)},l=async function(){if(!I(this,t,u).call(this)&&this.cursor&&this.element.appendChild(this.cursor),$(this,t,T)){((e,t)=>{let r=`[${B}='${e}'] .${V}`,n=getComputedStyle(t),i=Object.entries(we).reduce(((e,[t,r])=>`${e} ${t}: var(--ti-cursor-${t}, ${r||n[t]});`),"");G(`${r} { display: inline-block; width: 0; ${i} }`,e)})(this.id,this.element),this.cursor.dataset.tiAnimationId=this.id;let{animation:e}=this.opts.cursor,{frames:t,options:r}=e;pe({frames:t,cursor:this.cursor,options:{duration:this.opts.cursorSpeed,...r}})}},u=function(){return me(this.element)},c=function(e,r){return this.queue.add(e),I(this,t,h).call(this,r),this},h=function(e={}){let t=e.delay;t&&this.queue.add({delay:t})},f=function(e={}){return[{func:()=>I(this,t,p).call(this,e)},{func:()=>I(this,t,p).call(this,this.opts)}]},p=async function(e){this.opts=ve(this.opts,e)},d=function(){let e=this.opts.strings.filter((e=>!!e));e.forEach(((r,n)=>{if(this.type(r),n+1===e.length)return;let i=this.opts.breakLines?[{func:()=>I(this,t,v).call(this,K("BR")),typeable:!0}]:ce({func:I(this,t,w).bind(this),delay:I(this,t,k).call(this,1)},this.queue.getTypeable().length);I(this,t,b).call(this,i)}))},y=new WeakMap,m=function(e){let r=this.element.innerHTML;return r?(this.element.innerHTML="",this.opts.startDelete?(this.element.innerHTML=r,ne(this.element),I(this,t,b).call(this,ce({func:I(this,t,w).bind(this),delay:I(this,t,k).call(this,1),deletable:!0},$(this,t,E).length)),e):(n=r,n.replace(/<!--(.+?)-->/g,"").trim().split(/<br(?:\s*?)(?:\/)?>/)).concat(e)):e;var n},g=function(){if($(this,t,C))return null;let e=K("span");return e.className=V,$(this,t,T)?(e.innerHTML=ie(this.opts.cursorChar).innerHTML,e):(e.style.visibility="hidden",e)},b=function(e){let t=this.opts.nextStringDelay;this.queue.add([{delay:t[0]},...e,{delay:t[1]}])},v=function(e){((e,t)=>{if(me(e))return void(e.value=`${e.value}${t.textContent}`);t.innerHTML="";let r=(n=t.originalParent,/body/i.test(null==n?void 0:n.tagName)?e:t.originalParent||e);var n;let i=be("."+V,r)||null;i&&i.parentElement!==r&&(r=i.parentElement),r.insertBefore(t,i)})(this.element,e)},w=function(){$(this,t,E).length&&($(this,t,C)?this.element.value=this.element.value.slice(0,-1):I(this,t,S).call(this,$(this,t,E)[this.cursorPosition]))},S=function(e){((e,t)=>{if(!e)return;let r=e.parentNode;(r.childNodes.length>1||r.isSameNode(t)?e:r).remove()})(e,this.element)},k=function(e=0){return function(e){let{speed:t,deleteSpeed:r,lifeLike:n}=e;return r=null!==r?r:t/3,n?[ee(t,te(t)),ee(r,te(r))]:[t,r]}(this.opts)[e]},P=function(){return this.predictedCursorPosition??this.cursorPosition},C=function(){return me(this.element)},T=function(){return!!this.opts.cursor&&!$(this,t,C)},E=function(){return e=this.element,me(e)?re(e.value):se(e,!0).filter((e=>!(e.childNodes.length>0)));var e},j);const ke=e.forwardRef(((e,t)=>{const{as:r}=e;return H.jsx(r,{ref:t,...e})})),Pe={};return({as:t="span",options:r=Pe,children:n=null,getBeforeInit:i=e=>e,getAfterInit:s=e=>e,...o})=>{const a=e.useRef(null),l=e.useRef(null),[u,c]=e.useState(!0),[h,f]=e.useState(null);return e.useEffect((()=>{!function(){const e=Object.assign({},r);n&&a.current&&(e.strings=a.current.innerHTML),f(e)}(),c(!1)}),[r]),e.useEffect((()=>{var e;h&&((null==(e=l.current)?void 0:e.updateOptions(h))||(l.current=new Se(a.current,h),l.current=i(l.current),l.current.go(),l.current=s(l.current)))}),[h]),e.useEffect((()=>()=>{var e;return null==(e=l.current)?void 0:e.destroy()}),[]),H.jsx(ke,{ref:a,as:t,children:u?n:null,style:{opacity:u?0:1},...o})}}));