textimation 0.1.3 → 0.1.5
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 +13 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1 -1
- package/package.json +7 -7
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,11 @@
|
|
|
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?:
|
|
7
|
+
Comp?: ElementType;
|
|
8
|
+
type: "random" | "incremental";
|
|
7
9
|
}
|
|
8
|
-
declare function Textimation({ text, animationSpeed, className, keepCorrectChars, Comp }: TextimationProps):
|
|
10
|
+
declare function Textimation({ text, animationSpeed, className, keepCorrectChars, Comp, type }: TextimationProps): ReactNode;
|
|
9
11
|
export { Textimation };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useEffect as
|
|
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};
|
|
2
2
|
// built with love
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "textimation",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Animated Text",
|
|
5
5
|
"homepage": "https://github.com/TheeKia/textimation#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -27,13 +27,13 @@
|
|
|
27
27
|
"type-check": "tsc --noEmit"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@biomejs/biome": "^2.3.
|
|
31
|
-
"@types/bun": "^1.3.
|
|
32
|
-
"@types/react": "^19.2.
|
|
33
|
-
"bumpp": "^10.3.
|
|
30
|
+
"@biomejs/biome": "^2.3.8",
|
|
31
|
+
"@types/bun": "^1.3.4",
|
|
32
|
+
"@types/react": "^19.2.7",
|
|
33
|
+
"bumpp": "^10.3.2",
|
|
34
34
|
"bunup": "^0.16.10",
|
|
35
|
-
"react": "^19.2.
|
|
36
|
-
"react-dom": "^19.2.
|
|
35
|
+
"react": "^19.2.3",
|
|
36
|
+
"react-dom": "^19.2.3",
|
|
37
37
|
"simple-git-hooks": "^2.13.1",
|
|
38
38
|
"typescript": "^5.9.3"
|
|
39
39
|
},
|