diff --git a/src/app/(home)/page.tsx b/src/app/(home)/page.tsx index c936084..58fe4f5 100644 --- a/src/app/(home)/page.tsx +++ b/src/app/(home)/page.tsx @@ -1,16 +1,24 @@ -import Link from 'next/link'; +"use client"; + +import MorphText from "@/components/Morph"; +import { useEffect, useState } from "react"; export default function HomePage() { + const [showNext, setShowNext] = useState(false); + + useEffect(() => { + const timer = setTimeout(() => { + setShowNext(true); + }, 1000); + + return () => clearTimeout(timer); + }, []); + + const text = showNext ? "world hello i32(" : "(hello i32 world"; + return (
-

Hello World

-

- You can open{' '} - - /docs - {' '} - and see the documentation. -

+
); } diff --git a/src/components/Morph.tsx b/src/components/Morph.tsx new file mode 100644 index 0000000..ef1d83a --- /dev/null +++ b/src/components/Morph.tsx @@ -0,0 +1,44 @@ +import { motion, AnimatePresence } from "framer-motion"; + +interface MorphTextProps { + text: string; +} + +const tokenize = (str: string) => { + const counts: Record = {}; + return str.split("").map((char) => { + const displayChar = char === " " ? "\u00A0" : char; + counts[char] = (counts[char] || 0) + 1; + return { char: displayChar, id: `${char}-${counts[char]}` }; + }); +}; + +export default function MorphText({ text }: MorphTextProps) { + const activeTokens = tokenize(text); + + return ( +
+ + {activeTokens.map(({ char, id }) => ( + + {char} + + ))} + +
+ ); +}