modern-react-typist
Version:
A modern typist component written in React and Typescript
3 lines • 3.11 kB
JavaScript
'use client';
/*! For license information please see Typist.js.LICENSE.txt */
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r(require("react")):"function"==typeof define&&define.amd?define(["react"],r):"object"==typeof exports?exports.ModernReactTypist=r(require("react")):e.ModernReactTypist=r(e.react)}(this,(e=>(()=>{"use strict";var r={155:r=>{r.exports=e},698:(e,r)=>{var t=Symbol.for("react.transitional.element");Symbol.for("react.fragment"),r.jsx=function(e,r,n){var l=null;if(void 0!==n&&(l=""+n),void 0!==r.key&&(l=""+r.key),"key"in r)for(var o in n={},r)"key"!==o&&(n[o]=r[o]);else n=r;return r=n.ref,{$$typeof:t,type:e,key:l,ref:void 0!==r?r:null,props:n}}},848:(e,r,t)=>{e.exports=t(698)}},t={};function n(e){var l=t[e];if(void 0!==l)return l.exports;var o=t[e]={exports:{}};return r[e](o,o.exports,n),o.exports}n.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return n.d(r,{a:r}),r},n.d=(e,r)=>{for(var t in r)n.o(r,t)&&!n.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},n.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var l={};n.r(l),n.d(l,{default:()=>d});var o=n(848),i=n(155),a=n.n(i);function d(e){var r=e.children,t=e.cursor,n=void 0===t?(0,o.jsx)(i.Fragment,{}):t,l=e.delay,d=void 0===l?100:l,c=e.rootKey,u=void 0===c?"typistRoot":c,h=(0,i.cloneElement)(n,{key:u+"-cursor"}),f=(0,i.useState)(null),s=f[0],p=f[1],v=function(){function e(e){this.value=e,this.children=[]}return e.prototype.addChild=function(e){this.children.push(e)},e}();return(0,i.useEffect)((function(){var e;p(null);var t=new v((0,o.jsx)(i.Fragment,{})),n=((e={})[u]=t,e),l=[];!function e(r,t,o){if((0,i.isValidElement)(t)){var d=o+"/"+r.children.length,c=(0,i.cloneElement)(t,{key:d});r.addChild(new v(c)),n[d]=r.children[r.children.length-1];var u=t.props;if(null!=u.children&&"function"==typeof u.children[Symbol.iterator])for(var h=0,f=a().Children.toArray(u.children);h<f.length;h++){var s=f[h];e(r.children[r.children.length-1],s,d)}else e(r.children[r.children.length-1],u.children,d)}else if(Array.isArray(t))for(var p=0,y=t;p<y.length;p++)e(r,s=y[p],o);else if("string"==typeof t)if(1===t.length)r.addChild(t),d=o+"/"+(r.children.length-1),n[d]=r.children[r.children.length-1],l.push(d);else{var g=new v(t);r.addChild(g),d=o+"/"+(r.children.length-1),n[d]=r.children[r.children.length-1];for(var m=0,b=t;m<b.length;m++)e(g,b[m],d)}}(t,r,u);var c=0,f=setInterval((function(){for(var e=l[c],r=e.split("/").slice(1).map(Number),t=n[e],o=!1;r.length;){for(var a=[],d=1===r.length?u:u+"/"+r.slice(0,r.length-1).join("/"),s=Number(r[r.length-1]),v=0;v<s;v++)"string"==typeof n[d+"/"+v]?a.push(n[d+"/"+v]):a.push(n[d+"/"+v].value);a.push(t),"string"==typeof n[d].value?t=a.join(""):(o||(a.push(h),o=!0),t=(0,i.cloneElement)(n[d].value,{children:a})),r.pop()}p(t),++c>=l.length&&clearInterval(f)}),d);return function(){clearInterval(f)}}),[r,d]),(0,o.jsx)(i.Fragment,{children:s})}return l})()));