textimation 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{useEffect as N,useMemo as b,useRef as p,useState as v}from"react";import{useIntersectionObserver as _}from"usehooks-ts";function y(){return"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%&*"[Math.floor(Math.random()*69)]}import{jsx as A}from"react/jsx-runtime";var H={position:"relative"},P={opacity:0};function I(e,n,o,i){let u=Math.max(n.length,e.length);switch(i){case"incremental":return Array.from({length:u},(m,r)=>{if(o&&n[r]===e[r])return-1;if(n.length===0&&e[r]===" ")return 1;if(n.length>0&&e[r]===void 0)return Math.max(8,Math.ceil(Math.random()*20));return Math.ceil(Math.random()*3+r/2)});default:return Array.from({length:u},(m,r)=>{if(o&&n[r]===e[r])return-1;if(n.length===0&&e[r]===" ")return 1;return Math.max(8,Math.ceil(Math.random()*20))})}}function O({text:e,animationSpeed:n=50,className:o="",keepCorrectChars:i=!1,Comp:u="span",type:m="random"}){let{isIntersecting:r,ref:L}=_({threshold:0}),[d,g]=v("idle"),f=p(e.replace(/\s/g," ").replace(/\S/g," ").split("")),c=p(null),h=p(""),S=p(null),M=b(()=>{return r||d==="animating"},[r,d]);return N(()=>{if(!M)return;if(e===h.current)return;g("animating");let E=h.current,l=I(e,E,i,m),T=!0;function R(){if(!c.current)return;if(l.every((t)=>t<0)){f.current=e.split(""),c.current.textContent=e,h.current=e,g("finished");return}for(let t=0;t<l.length;t++){if(l[t]===-1)continue;l[t]--}if(D(f.current,l,e),T)T=!1,c.current.innerHTML=f.current.map((t,a)=>{if(t===void 0)return"";else if(t===e[a])return`<span class="textimation-correctChar">${t}</span>`;else return`<span class="textimation-incorrectChar">${t}</span>`}).join("");else{let t=c.current.children;for(let a=0;a<t.length;a++){let s=t[a],C=f.current[a];if(!C){s.remove();continue}if(s.innerText=C,C===e[a])s.classList.add("textimation-correctChar"),s.classList.remove("textimation-incorrectChar");else s.classList.add("textimation-incorrectChar"),s.classList.remove("textimation-correctChar")}}S.current=setTimeout(R,n)}return R(),()=>{if(g("idle"),h.current=e,S.current)clearTimeout(S.current)}},[m,e,n,i,M]),A(u,{ref:L,style:H,className:o,children:A("span",{ref:c,style:d==="idle"?P:void 0,children:e})})}function D(e,n,o){for(let i=0;i<n.length;i++)switch(n[i]){case-1:break;case 0:e[i]=o[i];break;default:e[i]=y();break}}export{O as Textimation};
1
+ import{useEffect as N,useMemo as b,useRef as p,useState as v}from"react";import{useIntersectionObserver as _}from"usehooks-ts";function y(){return"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%&*"[Math.floor(Math.random()*69)]}import{jsx as A}from"react/jsx-runtime";var H={position:"relative"},P={opacity:0};function I(e,n,o,i){let l=Math.max(n.length,e.length);switch(i){case"incremental":return Array.from({length:l},(m,r)=>{if(o&&n[r]===e[r])return-1;if(n.length===0&&e[r]===" ")return 1;if(n.length>0&&e[r]===void 0)return Math.max(8,Math.ceil(Math.random()*20));return Math.ceil(Math.random()*3+r/2)});default:return Array.from({length:l},(m,r)=>{if(o&&n[r]===e[r])return-1;if(n.length===0&&e[r]===" ")return 1;return Math.max(8,Math.ceil(Math.random()*20))})}}function O({text:e,animationSpeed:n=50,className:o="",keepCorrectChars:i=!1,Comp:l="span",type:m="random"}){let{isIntersecting:r,ref:L}=_({threshold:0}),[d,C]=v("idle"),f=p(e.replace(/\s/g," ").replace(/\S/g," ").split("")),c=p(null),h=p(""),g=p(null),M=b(()=>{return r||d==="animating"},[r,d]);return N(()=>{if(!M)return;if(e===h.current)return;C("animating");let E=h.current,u=I(e,E,i,m),T=!0;function R(){if(!c.current)return;if(u.every((t)=>t<0)){f.current=e.split(""),c.current.textContent=e,h.current=e,C("finished");return}for(let t=0;t<u.length;t++){if(u[t]===-1)continue;u[t]--}if(D(f.current,u,e),T)T=!1,c.current.innerHTML=f.current.map((t,a)=>{if(t===void 0)return"";else if(t===e[a])return`<span class="textimation-correctChar">${t}</span>`;else return`<span class="textimation-incorrectChar">${t}</span>`}).join("");else{let t=c.current.children;for(let a=0;a<t.length;a++){let s=t[a],S=f.current[a];if(!S){s.remove();continue}if(s.innerText=S,S===e[a])s.classList.add("textimation-correctChar"),s.classList.remove("textimation-incorrectChar");else s.classList.add("textimation-incorrectChar"),s.classList.remove("textimation-correctChar")}}g.current=setTimeout(R,n)}return R(),()=>{if(h.current=e,g.current)clearTimeout(g.current)}},[m,e,n,i,M]),A(l,{ref:L,style:H,className:o,children:A("span",{ref:c,style:d==="idle"?P:void 0,children:e})})}function D(e,n,o){for(let i=0;i<n.length;i++)switch(n[i]){case-1:break;case 0:e[i]=o[i];break;default:e[i]=y();break}}export{O as Textimation};
2
2
  // built with love
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "textimation",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Animated Text",
5
5
  "homepage": "https://github.com/TheeKia/textimation#readme",
6
6
  "bugs": {
@@ -27,11 +27,11 @@
27
27
  "type-check": "tsc --noEmit"
28
28
  },
29
29
  "devDependencies": {
30
- "@biomejs/biome": "^2.3.8",
31
- "@types/bun": "^1.3.4",
30
+ "@biomejs/biome": "^2.3.10",
31
+ "@types/bun": "^1.3.5",
32
32
  "@types/react": "^19.2.7",
33
33
  "bumpp": "^10.3.2",
34
- "bunup": "^0.16.10",
34
+ "bunup": "^0.16.11",
35
35
  "react": "^19.2.3",
36
36
  "react-dom": "^19.2.3",
37
37
  "simple-git-hooks": "^2.13.1",