textimation 0.1.2 → 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
@@ -12,6 +12,21 @@ bun add textimation
12
12
 
13
13
  First, import the styles and the `AnimatedText` component:
14
14
 
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
+ ```
29
+
15
30
  ```tsx
16
31
  import 'textimation/styles.css';
17
32
  import { AnimatedText } from 'textimation';
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- interface AnimatedTextProps {
1
+ import { ElementType, ReactNode } from "react";
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 AnimatedText({ text, animationSpeed, className, keepCorrectChars, Comp }: AnimatedTextProps): React.ReactNode;
9
- export { AnimatedText };
9
+ declare function Textimation({ text, animationSpeed, className, keepCorrectChars, Comp }: TextimationProps): ReactNode;
10
+ export { Textimation };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{useEffect as b,useMemo as x,useRef as c,useState as y}from"react";import{useIntersectionObserver as N}from"usehooks-ts";function R(){return"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%&*"[Math.floor(Math.random()*69)]}import{jsx as A,jsxs as O}from"react/jsx-runtime";function v({text:e,animationSpeed:r=50,className:u="",keepCorrectChars:n=!1,Comp:M="span"}){let{isIntersecting:h,ref:C}=N({threshold:0}),[l,m]=y("idle"),f=c(e.replace(/\s/g," ").replace(/\S/g," ").split("")),i=c(null),s=c(""),p=c(null),g=x(()=>{return h||l==="animating"},[h,l]);return b(()=>{if(!g)return;if(e===s.current)return;m("animating");let d=s.current,S=Math.max(d.length,e.length),a=Array.from({length:S},(t,o)=>{if(n&&d[o]===e[o])return-1;if(d.length===0&&e[o]===" ")return 1;return Math.max(5,Math.ceil(Math.random()*20))});function T(){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)H(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(T,r)}return T(),()=>{if(m("idle"),s.current=e,p.current)clearTimeout(p.current)}},[e,r,n,g]),O(M,{ref:C,style:{position:"relative"},className:u,children:[l==="idle"&&A("span",{className:"textimation-hiddenText",children:e}),A("span",{ref:i})]})}function H(e,r,u){for(let n=0;n<r.length;n++)switch(r[n]){case-1:break;case 0:e[n]=u[n];break;default:e[n]=R();break}}export{v as AnimatedText};
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.2",
3
+ "version": "0.1.4",
4
4
  "description": "Animated Text",
5
5
  "homepage": "https://github.com/TheeKia/textimation#readme",
6
6
  "bugs": {
package/dist/index.css DELETED
@@ -1 +0,0 @@
1
- .textimation-hiddenText{position:absolute;opacity:0;inset:0}.textimation-incorrectChar{opacity:.2}