textimation 0.1.3 → 0.1.4

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.
package/README.md CHANGED
@@ -13,6 +13,19 @@ bun add textimation
13
13
  First, import the styles and the `AnimatedText` component:
14
14
 
15
15
  - You can use `.textimation-incorrectChar` to style the incorrect characters.
16
+ - You can use `.textimation-correctChar` to style the correct characters.
17
+
18
+ ```css
19
+ .textimation-correctChar {
20
+ transition: all 0.2s ease-in-out;
21
+ opacity: 1;
22
+ }
23
+
24
+ .textimation-incorrectChar {
25
+ transition: all 0.2s ease-in-out;
26
+ opacity: 0.2;
27
+ }
28
+ ```
16
29
 
17
30
  ```tsx
18
31
  import 'textimation/styles.css';
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
+ import { ElementType, ReactNode } from "react";
1
2
  interface TextimationProps {
2
3
  text: string;
3
4
  animationSpeed?: number;
4
5
  className?: string;
5
6
  keepCorrectChars?: boolean;
6
- Comp?: React.ElementType;
7
+ Comp?: ElementType;
7
8
  }
8
- declare function Textimation({ text, animationSpeed, className, keepCorrectChars, Comp }: TextimationProps): React.ReactNode;
9
+ declare function Textimation({ text, animationSpeed, className, keepCorrectChars, Comp }: TextimationProps): ReactNode;
9
10
  export { Textimation };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{useEffect as b,useMemo as y,useRef as u,useState as N}from"react";import{useIntersectionObserver as v}from"usehooks-ts";function T(){return"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%&*"[Math.floor(Math.random()*69)]}import{jsx as M,jsxs as k}from"react/jsx-runtime";function H({text:e,animationSpeed:r=50,className:c="",keepCorrectChars:n=!1,Comp:A="span"}){let{isIntersecting:h,ref:C}=v({threshold:0}),[l,m]=N("idle"),f=u(e.replace(/\s/g," ").replace(/\S/g," ").split("")),i=u(null),s=u(""),p=u(null),d=y(()=>{return h||l==="animating"},[h,l]);return b(()=>{if(!d)return;if(e===s.current)return;m("animating");let g=s.current,S=Math.max(g.length,e.length),a=Array.from({length:S},(t,o)=>{if(n&&g[o]===e[o])return-1;if(g.length===0&&e[o]===" ")return 1;return Math.max(5,Math.ceil(Math.random()*20))});function R(){if(a.every((t)=>t<0)){if(f.current=e.split(""),i.current)i.current.textContent=e;s.current=e,m("finished");return}for(let t=0;t<a.length;t++){if(a[t]===-1)continue;a[t]--}if(i.current)O(f.current,a,e),i.current.innerHTML=f.current.map((t,o)=>{if(t===e[o])return`<span>${t}</span>`;else return`<span class="textimation-incorrectChar">${t}</span>`}).join("");p.current=setTimeout(R,r)}return R(),()=>{if(m("idle"),s.current=e,p.current)clearTimeout(p.current)}},[e,r,n,d]),k(A,{ref:C,style:{position:"relative"},className:c,children:[l==="idle"&&M("span",{style:{position:"absolute",inset:0,opacity:0},children:e}),M("span",{ref:i})]})}function O(e,r,c){for(let n=0;n<r.length;n++)switch(r[n]){case-1:break;case 0:e[n]=c[n];break;default:e[n]=T();break}}export{H as Textimation};
1
+ import{useEffect as N,useMemo as b,useRef as u,useState as v}from"react";import{useIntersectionObserver as x}from"usehooks-ts";function M(){return"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%&*"[Math.floor(Math.random()*69)]}import{jsx as y,jsxs as P}from"react/jsx-runtime";var H={position:"relative"},_={position:"absolute",inset:0,opacity:0};function I({text:e,animationSpeed:a=50,className:m="",keepCorrectChars:n=!1,Comp:A="span"}){let{isIntersecting:T,ref:L}=x({threshold:0}),[f,p]=v("idle"),c=u(e.replace(/\s/g," ").replace(/\S/g," ").split("")),o=u(null),l=u(""),h=u(null),C=b(()=>{return T||f==="animating"},[T,f]);return N(()=>{if(!C)return;if(e===l.current)return;p("animating");let d=l.current,E=Math.max(d.length,e.length),s=Array.from({length:E},(t,r)=>{if(n&&d[r]===e[r])return-1;if(d.length===0&&e[r]===" ")return 1;return Math.max(5,Math.ceil(Math.random()*20))}),S=!0;function R(){if(!o.current)return;if(s.every((t)=>t<0)){c.current=e.split(""),o.current.textContent=e,l.current=e,p("finished");return}for(let t=0;t<s.length;t++){if(s[t]===-1)continue;s[t]--}if(O(c.current,s,e),S)S=!1,o.current.innerHTML=c.current.map((t,r)=>{if(t===void 0)return"";else if(t===e[r])return`<span class="textimation-correctChar">${t}</span>`;else return`<span class="textimation-incorrectChar">${t}</span>`}).join("");else{let t=o.current.children;for(let r=0;r<t.length;r++){let i=t[r],g=c.current[r];if(!g){i.remove();continue}if(i.innerText=g,g===e[r])i.classList.add("textimation-correctChar"),i.classList.remove("textimation-incorrectChar");else i.classList.add("textimation-incorrectChar"),i.classList.remove("textimation-correctChar")}}h.current=setTimeout(R,a)}return R(),()=>{if(p("idle"),l.current=e,h.current)clearTimeout(h.current)}},[e,a,n,C]),P(A,{ref:L,style:H,className:m,children:[f==="idle"&&y("span",{style:_,children:e}),y("span",{ref:o})]})}function O(e,a,m){for(let n=0;n<a.length;n++)switch(a[n]){case-1:break;case 0:e[n]=m[n];break;default:e[n]=M();break}}export{I 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.3",
3
+ "version": "0.1.4",
4
4
  "description": "Animated Text",
5
5
  "homepage": "https://github.com/TheeKia/textimation#readme",
6
6
  "bugs": {