textimation 0.1.1 → 0.1.3

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
@@ -1,6 +1,6 @@
1
1
  # textimation
2
2
 
3
- Animated Text
3
+ A simple React component for animating text with typewriter-like effects.
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,12 +10,23 @@ bun add textimation
10
10
 
11
11
  ## Usage
12
12
 
13
+ First, import the styles and the `AnimatedText` component:
14
+
15
+ - You can use `.textimation-incorrectChar` to style the incorrect characters.
16
+
13
17
  ```tsx
14
18
  import 'textimation/styles.css';
15
- import { Button } from 'textimation';
19
+ import { AnimatedText } from 'textimation';
16
20
 
17
21
  function App() {
18
- return <Button>Click me</Button>;
22
+ return (
23
+ <AnimatedText
24
+ text="Hello, world!"
25
+ Comp="p"
26
+ animationSpeed={30}
27
+ keepCorrectChars
28
+ />
29
+ );
19
30
  }
20
31
  ```
21
32
 
@@ -25,4 +36,4 @@ Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for contribution guidelines.
25
36
 
26
37
  ## License
27
38
 
28
- MIT
39
+ MIT License
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- interface AnimatedTextProps {
1
+ interface TextimationProps {
2
2
  text: string;
3
3
  animationSpeed?: number;
4
4
  className?: string;
5
5
  keepCorrectChars?: boolean;
6
6
  Comp?: React.ElementType;
7
7
  }
8
- declare function AnimatedText({ text, animationSpeed, className, keepCorrectChars, Comp }: AnimatedTextProps): React.ReactNode;
9
- export { AnimatedText };
8
+ declare function Textimation({ text, animationSpeed, className, keepCorrectChars, Comp }: TextimationProps): React.ReactNode;
9
+ 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 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};
2
2
  // built with love
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "textimation",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
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}