UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
refactor: use static motion elements and remove motionComponent prop (#905)
Yeom-JinHoa07ad9e416b8
diff --git a/apps/www/content/docs/components/hyper-text.mdx b/apps/www/content/docs/components/hyper-text.mdxindex a32178ec..2b6eb4ea 100644--- a/apps/www/content/docs/components/hyper-text.mdx+++ b/apps/www/content/docs/components/hyper-text.mdx@@ -58,13 +58,13 @@ import { HyperText } from "@/components/ui/hyper-text"## Props-| Prop | Type | Default | Description |-| ---------------- | ------------------- | ------- | --------------------------------------------- |-| `children` | `string` | `-` | Text content to animate |-| `className` | `string` | `-` | The class name to be applied to the component |-| `duration` | `number` | `800` | Duration of the animation in milliseconds |-| `delay` | `number` | `0` | Delay before animation starts (in ms) |-| `as` | `React.ElementType` | `"div"` | Component to render as |-| `startOnView` | `boolean` | `false` | Start animation when component is in view |-| `animateOnHover` | `boolean` | `true` | Enable hover animation |-| `characterSet` | `string[]` | `A-Z` | Custom character set for scramble effect |+| Prop | Type | Default | Description |+| ---------------- | ---------------------------------------------------------------------------------------------------------- | ------- | --------------------------------------------- |+| `children` | `string` | `-` | Text content to animate |+| `className` | `string` | `-` | The class name to be applied to the component |+| `duration` | `number` | `800` | Duration of the animation in milliseconds |+| `delay` | `number` | `0` | Delay before animation starts (in ms) |+| `as` | `"article" \| "div" \| "h1" \| "h2" \| "h3" \| "h4" \| "h5" \| "h6" \| "li" \| "p" \| "section" \| "span"` | `"div"` | Component to render as |+| `startOnView` | `boolean` | `false` | Start animation when component is in view |+| `animateOnHover` | `boolean` | `true` | Enable hover animation |+| `characterSet` | `string[]` | `A-Z` | Custom character set for scramble effect |diff --git a/apps/www/content/docs/components/line-shadow-text.mdx b/apps/www/content/docs/components/line-shadow-text.mdxindex ddde7f03..215bda0a 100644--- a/apps/www/content/docs/components/line-shadow-text.mdx+++ b/apps/www/content/docs/components/line-shadow-text.mdx@@ -71,8 +71,8 @@ import { LineShadowText } from "@/components/ui/line-shadow-text"## Props-| Prop | Type | Default | Description |-| ------------- | -------- | --------- | -------------------------------------- |-| `shadowColor` | `string` | `"black"` | The color of the shadow effect |-| `children` | `string` | `-` | The text to display with shadow effect |-| `as` | `string` | `"span"` | The HTML element to render the text as |+| Prop | Type | Default | Description |+| ------------- | ---------------------------------------------------------------------------------------------------------- | --------- | -------------------------------------- |+| `shadowColor` | `string` | `"black"` | The color of the shadow effect |+| `children` | `string` | `-` | The text to display with shadow effect |+| `as` | `"article" \| "div" \| "h1" \| "h2" \| "h3" \| "h4" \| "h5" \| "h6" \| "li" \| "p" \| "section" \| "span"` | `"span"` | The HTML element to render the text as |diff --git a/apps/www/content/docs/components/terminal.mdx b/apps/www/content/docs/components/terminal.mdxindex 5a9cadae..acb7c8c0 100644--- a/apps/www/content/docs/components/terminal.mdx+++ b/apps/www/content/docs/components/terminal.mdx@@ -87,11 +87,11 @@ The terminal sequences its children automatically. Each `TypingAnimation` or `An### TypingAnimation-| Prop | Type | Default | Description |-| ------------- | ------------------- | -------- | ------------------------------------------------------------------------ |-| `children` | `string` | `-` | Text to be typed. |-| `className` | `string` | `-` | Custom CSS class for styling. |-| `duration` | `number` | `60` | Milliseconds per character. |-| `delay` | `number` | `0` | Delay in ms before typing starts (used when `sequence` is `false`). |-| `as` | `React.ElementType` | `"span"` | The component type to render. |-| `startOnView` | `boolean` | `true` | If `true`, waits for viewport visibility before typing when unsequenced. |+| Prop | Type | Default | Description |+| ------------- | ---------------------------------------------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------ |+| `children` | `string` | `-` | Text to be typed. |+| `className` | `string` | `-` | Custom CSS class for styling. |+| `duration` | `number` | `60` | Milliseconds per character. |+| `delay` | `number` | `0` | Delay in ms before typing starts (used when `sequence` is `false`). |+| `as` | `"article" \| "div" \| "h1" \| "h2" \| "h3" \| "h4" \| "h5" \| "h6" \| "li" \| "p" \| "section" \| "span"` | `"span"` | The component type to render. |+| `startOnView` | `boolean` | `true` | If `true`, waits for viewport visibility before typing when unsequenced. |diff --git a/apps/www/content/docs/components/text-animate.mdx b/apps/www/content/docs/components/text-animate.mdxindex 5049979c..e907732f 100644--- a/apps/www/content/docs/components/text-animate.mdx+++ b/apps/www/content/docs/components/text-animate.mdx@@ -88,15 +88,17 @@ import { TextAnimate } from "@/components/ui/text-animate"## Props-| Prop | Type | Default | Description |-| ------------- | ------------------------------------------- | ---------- | --------------------------------------------------------- |-| `children` | `string` | `-` | The text content to animate |-| `className` | `string` | `-` | The class name to be applied to the component |-| `delay` | `number` | `0` | Delay before animation starts |-| `duration` | `number` | `0.3` | Duration of the animation |-| `variants` | `Variants` | `-` | Custom motion variants for the animation |-| `as` | `ElementType` | `"p"` | The element type to render |-| `by` | `"text" \| "word" \| "character" \| "line"` | `"word"` | How to split the text ("text", "word", "character") |-| `startOnView` | `boolean` | `true` | Whether to start animation when component enters viewport |-| `once` | `boolean` | `false` | Whether to animate only once |-| `animation` | `AnimationVariant` | `"fadeIn"` | The animation preset to use |+| Prop | Type | Default | Description |+| ------------------ | ---------------------------------------------------------------------------------------------------------- | ---------- | --------------------------------------------------------- |+| `children` | `string` | `-` | The text content to animate |+| `className` | `string` | `-` | The class name to be applied to the component |+| `segmentClassName` | `string` | `-` | The class name to be applied to each segment |+| `delay` | `number` | `0` | Delay before animation starts |+| `duration` | `number` | `0.3` | Duration of the animation |+| `variants` | `Variants` | `-` | Custom motion variants for the animation |+| `as` | `"article" \| "div" \| "h1" \| "h2" \| "h3" \| "h4" \| "h5" \| "h6" \| "li" \| "p" \| "section" \| "span"` | `"p"` | The element type to render |+| `by` | `"text" \| "word" \| "character" \| "line"` | `"word"` | How to split the text ("text", "word", "character") |+| `startOnView` | `boolean` | `true` | Whether to start animation when component enters viewport |+| `once` | `boolean` | `false` | Whether to animate only once |+| `animation` | `AnimationVariant` | `"fadeIn"` | The animation preset to use |+| `accessible` | `boolean` | `true` | Whether to render an accessible screen-reader label |diff --git a/apps/www/content/docs/components/typing-animation.mdx b/apps/www/content/docs/components/typing-animation.mdxindex 10850603..104a6eb2 100644--- a/apps/www/content/docs/components/typing-animation.mdx+++ b/apps/www/content/docs/components/typing-animation.mdx@@ -86,19 +86,19 @@ import { TypingAnimation } from "@/components/ui/typing-animation"## Props-| Prop | Type | Default | Description |-| ------------- | ----------------------------------- | -------- | ----------------------------------------------- |-| `children` | `string` | `-` | Single string to animate |-| `words` | `string[]` | `-` | Array of strings to type and delete in sequence |-| `className` | `string` | `-` | The class name to be applied to the component |-| `duration` | `number` | `100` | Duration for each character |-| `typeSpeed` | `number` | `100` | Speed of typing animation (ms per character) |-| `deleteSpeed` | `number` | `50` | Speed of deleting animation (ms per character) |-| `delay` | `number` | `0` | Delay before animation starts (in ms) |-| `pauseDelay` | `number` | `1000` | Pause duration between words (in ms) |-| `loop` | `boolean` | `false` | Whether to loop the animation |-| `as` | `React.ElementType` | `"span"` | Component to render as |-| `startOnView` | `boolean` | `true` | Start animation when component is in view |-| `showCursor` | `boolean` | `true` | Whether to show the typing cursor |-| `blinkCursor` | `boolean` | `true` | Whether the cursor should blink |-| `cursorStyle` | `"line" \| "block" \| "underscore"` | `"line"` | Style of the cursor (like VSCode) |+| Prop | Type | Default | Description |+| ------------- | ---------------------------------------------------------------------------------------------------------- | -------- | ----------------------------------------------- |+| `children` | `string` | `-` | Single string to animate |+| `words` | `string[]` | `-` | Array of strings to type and delete in sequence |+| `className` | `string` | `-` | The class name to be applied to the component |+| `duration` | `number` | `100` | Duration for each character |+| `typeSpeed` | `number` | `100` | Speed of typing animation (ms per character) |+| `deleteSpeed` | `number` | `50` | Speed of deleting animation (ms per character) |+| `delay` | `number` | `0` | Delay before animation starts (in ms) |+| `pauseDelay` | `number` | `1000` | Pause duration between words (in ms) |+| `loop` | `boolean` | `false` | Whether to loop the animation |+| `as` | `"article" \| "div" \| "h1" \| "h2" \| "h3" \| "h4" \| "h5" \| "h6" \| "li" \| "p" \| "section" \| "span"` | `"span"` | Component to render as |+| `startOnView` | `boolean` | `true` | Start animation when component is in view |+| `showCursor` | `boolean` | `true` | Whether to show the typing cursor |+| `blinkCursor` | `boolean` | `true` | Whether the cursor should blink |+| `cursorStyle` | `"line" \| "block" \| "underscore"` | `"line"` | Style of the cursor (like VSCode) |diff --git a/apps/www/public/llms-full.txt b/apps/www/public/llms-full.txtindex 5e1939f6..e88c68d7 100644--- a/apps/www/public/llms-full.txt+++ b/apps/www/public/llms-full.txt@@ -7647,14 +7647,49 @@ Description: A text animation that scrambles letters before revealing the final--- file: magicui/hyper-text.tsx ---"use client"-import { useEffect, useRef, useState } from "react"-import { AnimatePresence, motion, type MotionProps } from "motion/react"+import {+ useEffect,+ useRef,+ useState,+ type ComponentType,+ type RefAttributes,+} from "react"+import {+ AnimatePresence,+ motion,+ type DOMMotionComponents,+ type HTMLMotionProps,+ type MotionProps,+} from "motion/react"import { cn } from "@/lib/utils"type CharacterSet = string[] | readonly string[]-interface HyperTextProps extends MotionProps {+const motionElements = {+ article: motion.article,+ div: motion.div,+ h1: motion.h1,+ h2: motion.h2,+ h3: motion.h3,+ h4: motion.h4,+ h5: motion.h5,+ h6: motion.h6,+ li: motion.li,+ p: motion.p,+ section: motion.section,+ span: motion.span,+} as const++type MotionElementType = Extract<+ keyof DOMMotionComponents,+ keyof typeof motionElements+>+type HyperTextMotionComponent = ComponentType<+ Omit<HTMLMotionProps<"div">, "ref"> & RefAttributes<HTMLElement>+>++interface HyperTextProps extends Omit<MotionProps, "children"> {/** The text content to be animated */children: string/** Optional className for styling */@@ -7664,7 +7699,7 @@ interface HyperTextProps extends MotionProps {/** Delay before animation starts in milliseconds */delay?: number/** Component to render as - defaults to div */- as?: React.ElementType+ as?: MotionElementType/** Whether to start animation when element comes into view */startOnView?: boolean/** Whether to trigger animation on hover */@@ -7690,16 +7725,14 @@ export function HyperText({characterSet = DEFAULT_CHARACTER_SET,...props}: HyperTextProps) {- const MotionComponent = motion.create(Component, {- forwardMotionProps: true,- })+ const MotionComponent = motionElements[Component] as HyperTextMotionComponentconst [displayText, setDisplayText] = useState<string[]>(() =>children.split(""))const [isAnimating, setIsAnimating] = useState(false)const iterationCount = useRef(0)- const elementRef = useRef<HTMLElement>(null)+ const elementRef = useRef<HTMLElement | null>(null)const handleAnimationTrigger = () => {if (animateOnHover && !isAnimating) {@@ -9276,16 +9309,40 @@ Description: A text component with a moving line shadow.--- file: magicui/line-shadow-text.tsx ---"use client"-import { motion, type MotionProps } from "motion/react"+import { type CSSProperties, type HTMLAttributes } from "react"+import {+ motion,+ type DOMMotionComponents,+ type MotionProps,+} from "motion/react"import { cn } from "@/lib/utils"+const motionElements = {+ article: motion.article,+ div: motion.div,+ h1: motion.h1,+ h2: motion.h2,+ h3: motion.h3,+ h4: motion.h4,+ h5: motion.h5,+ h6: motion.h6,+ li: motion.li,+ p: motion.p,+ section: motion.section,+ span: motion.span,+} as const++type MotionElementType = Extract<+ keyof DOMMotionComponents,+ keyof typeof motionElements+>+interface LineShadowTextProps- extends- Omit<React.HTMLAttributes<HTMLElement>, keyof MotionProps>,- MotionProps {+ extends Omit<HTMLAttributes<HTMLElement>, keyof MotionProps>, MotionProps {+ children: stringshadowColor?: string- as?: React.ElementType+ as?: MotionElementType}export function LineShadowText({@@ -9295,16 +9352,11 @@ export function LineShadowText({as: Component = "span",...props}: LineShadowTextProps) {- const MotionComponent = motion.create(Component)- const content = typeof children === "string" ? children : null-- if (!content) {- throw new Error("LineShadowText only accepts string content")- }+ const MotionComponent = motionElements[Component]return (<MotionComponent- style={{ "--shadow-color": shadowColor } as React.CSSProperties}+ style={{ "--shadow-color": shadowColor } as CSSProperties}className={cn("relative z-0 inline-flex","after:absolute after:top-[0.04em] after:left-[0.04em] after:content-[attr(data-text)]",@@ -9313,10 +9365,10 @@ export function LineShadowText({"after:animate-line-shadow",className)}- data-text={content}+ data-text={children}{...props}>- {content}+ {children}</MotionComponent>)}@@ -13944,8 +13996,16 @@ import {useMemo,useRef,useState,+ type ComponentType,+ type RefAttributes,} from "react"-import { motion, useInView, type MotionProps } from "motion/react"+import {+ motion,+ useInView,+ type DOMMotionComponents,+ type HTMLMotionProps,+ type MotionProps,+} from "motion/react"import { cn } from "@/lib/utils"@@ -13962,6 +14022,29 @@ const useSequence = () => useContext(SequenceContext)const ItemIndexContext = createContext<number | null>(null)const useItemIndex = () => useContext(ItemIndexContext)+const motionElements = {+ article: motion.article,+ div: motion.div,+ h1: motion.h1,+ h2: motion.h2,+ h3: motion.h3,+ h4: motion.h4,+ h5: motion.h5,+ h6: motion.h6,+ li: motion.li,+ p: motion.p,+ section: motion.section,+ span: motion.span,+} as const++type MotionElementType = Extract<+ keyof DOMMotionComponents,+ keyof typeof motionElements+>+type TerminalTypingMotionComponent = ComponentType<+ Omit<HTMLMotionProps<"span">, "ref"> & RefAttributes<HTMLElement>+>+interface AnimatedSpanProps extends MotionProps {children: React.ReactNodedelay?: number@@ -14015,12 +14098,12 @@ export const AnimatedSpan = ({)}-interface TypingAnimationProps extends MotionProps {+interface TypingAnimationProps extends Omit<MotionProps, "children"> {children: stringclassName?: stringduration?: numberdelay?: number- as?: React.ElementType+ as?: MotionElementTypestartOnView?: boolean}@@ -14037,13 +14120,9 @@ export const TypingAnimation = ({throw new Error("TypingAnimation: children must be a string. Received:")}- const MotionComponent = useMemo(- () =>- motion.create(Component, {- forwardMotionProps: true,- }),- [Component]- )+ const MotionComponent = motionElements[+ Component+ ] as TerminalTypingMotionComponentconst [displayedText, setDisplayedText] = useState<string>("")const [started, setStarted] = useState(false)@@ -14298,11 +14377,12 @@ Description: A text animation component that animates text using a variety of di--- file: magicui/text-animate.tsx ---"use client"-import { ElementType, memo } from "react"+import { memo } from "react"import {AnimatePresence,motion,Variants,+ type DOMMotionComponents,type MotionProps,} from "motion/react"@@ -14321,7 +14401,27 @@ type AnimationVariant =| "scaleUp"| "scaleDown"-interface TextAnimateProps extends MotionProps {+const motionElements = {+ article: motion.article,+ div: motion.div,+ h1: motion.h1,+ h2: motion.h2,+ h3: motion.h3,+ h4: motion.h4,+ h5: motion.h5,+ h6: motion.h6,+ li: motion.li,+ p: motion.p,+ section: motion.section,+ span: motion.span,+} as const++type MotionElementType = Extract<+ keyof DOMMotionComponents,+ keyof typeof motionElements+>++interface TextAnimateProps extends Omit<MotionProps, "children"> {/*** The text content to animate*/@@ -14349,7 +14449,7 @@ interface TextAnimateProps extends MotionProps {/*** The element type to render*/- as?: ElementType+ as?: MotionElementType/*** How to split the text ("text", "word", "character")*/@@ -14620,7 +14720,7 @@ const TextAnimateBase = ({accessible = true,...props}: TextAnimateProps) => {- const MotionComponent = motion.create(Component)+ const MotionComponent = motionElements[Component]let segments: string[] = []switch (by) {@@ -15340,12 +15440,49 @@ Description: Characters appearing in typed animation--- file: magicui/typing-animation.tsx ---"use client"-import { useEffect, useMemo, useRef, useState } from "react"-import { motion, useInView, type MotionProps } from "motion/react"+import {+ useEffect,+ useMemo,+ useRef,+ useState,+ type ComponentType,+ type RefAttributes,+ type RefObject,+} from "react"+import {+ motion,+ useInView,+ type DOMMotionComponents,+ type HTMLMotionProps,+ type MotionProps,+} from "motion/react"import { cn } from "@/lib/utils"-interface TypingAnimationProps extends MotionProps {+const motionElements = {+ article: motion.article,+ div: motion.div,+ h1: motion.h1,+ h2: motion.h2,+ h3: motion.h3,+ h4: motion.h4,+ h5: motion.h5,+ h6: motion.h6,+ li: motion.li,+ p: motion.p,+ section: motion.section,+ span: motion.span,+} as const++type MotionElementType = Extract<+ keyof DOMMotionComponents,+ keyof typeof motionElements+>+type TypingAnimationMotionComponent = ComponentType<+ Omit<HTMLMotionProps<"span">, "ref"> & RefAttributes<HTMLElement>+>++interface TypingAnimationProps extends Omit<MotionProps, "children"> {children?: stringwords?: string[]className?: string@@ -15355,7 +15492,7 @@ interface TypingAnimationProps extends MotionProps {delay?: numberpauseDelay?: numberloop?: boolean- as?: React.ElementType+ as?: MotionElementTypestartOnView?: booleanshowCursor?: booleanblinkCursor?: boolean@@ -15379,16 +15516,16 @@ export function TypingAnimation({cursorStyle = "line",...props}: TypingAnimationProps) {- const MotionComponent = motion.create(Component, {- forwardMotionProps: true,- })+ const MotionComponent = motionElements[+ Component+ ] as TypingAnimationMotionComponentconst [displayedText, setDisplayedText] = useState<string>("")const [currentWordIndex, setCurrentWordIndex] = useState(0)const [currentCharIndex, setCurrentCharIndex] = useState(0)const [phase, setPhase] = useState<"typing" | "pause" | "deleting">("typing")const elementRef = useRef<HTMLElement | null>(null)- const isInView = useInView(elementRef as React.RefObject<Element>, {+ const isInView = useInView(elementRef as RefObject<Element>, {amount: 0.3,once: true,})@@ -15403,6 +15540,17 @@ export function TypingAnimation({const deletingSpeed = deleteSpeed ?? typingSpeed / 2const shouldStart = startOnView ? isInView : true+ const animationSourceKey = useMemo(+ () => (words ? words.join("\u0000") : (children ?? "")),+ [words, children]+ )++ useEffect(() => {+ setDisplayedText("")+ setCurrentWordIndex(0)+ setCurrentCharIndex(0)+ setPhase("typing")+ }, [animationSourceKey])useEffect(() => {if (!shouldStart || wordsToAnimate.length === 0) return@@ -15497,7 +15645,11 @@ export function TypingAnimation({return (<MotionComponentref={elementRef}- className={cn("leading-20 tracking-[-0.02em]", className)}+ className={cn(+ "leading-20 tracking-[-0.02em]",+ Component === "span" && "inline-block",+ className+ )}{...props}>{displayedText}diff --git a/apps/www/public/r/hyper-text.json b/apps/www/public/r/hyper-text.jsonindex 7073d51e..99afbe19 100644--- a/apps/www/public/r/hyper-text.json+++ b/apps/www/public/r/hyper-text.json@@ -10,7 +10,7 @@"files": [{"path": "registry/magicui/hyper-text.tsx",- "content": "\"use client\"\n\nimport { useEffect, useRef, useState } from \"react\"\nimport { AnimatePresence, motion, type MotionProps } from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\ntype CharacterSet = string[] | readonly string[]\n\ninterface HyperTextProps extends MotionProps {\n /** The text content to be animated */\n children: string\n /** Optional className for styling */\n className?: string\n /** Duration of the animation in milliseconds */\n duration?: number\n /** Delay before animation starts in milliseconds */\n delay?: number\n /** Component to render as - defaults to div */\n as?: React.ElementType\n /** Whether to start animation when element comes into view */\n startOnView?: boolean\n /** Whether to trigger animation on hover */\n animateOnHover?: boolean\n /** Custom character set for scramble effect. Defaults to uppercase alphabet */\n characterSet?: CharacterSet\n}\n\nconst DEFAULT_CHARACTER_SET = Object.freeze(\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\".split(\"\")\n) as readonly string[]\n\nconst getRandomInt = (max: number): number => Math.floor(Math.random() * max)\n\nexport function HyperText({\n children,\n className,\n duration = 800,\n delay = 0,\n as: Component = \"div\",\n startOnView = false,\n animateOnHover = true,\n characterSet = DEFAULT_CHARACTER_SET,\n ...props\n}: HyperTextProps) {\n const MotionComponent = motion.create(Component, {\n forwardMotionProps: true,\n })\n\n const [displayText, setDisplayText] = useState<string[]>(() =>\n children.split(\"\")\n )\n const [isAnimating, setIsAnimating] = useState(false)\n const iterationCount = useRef(0)\n const elementRef = useRef<HTMLElement>(null)\n\n const handleAnimationTrigger = () => {\n if (animateOnHover && !isAnimating) {\n iterationCount.current = 0\n setIsAnimating(true)\n }\n }\n\n // Handle animation start based on view or delay\n useEffect(() => {\n if (!startOnView) {\n const startTimeout = setTimeout(() => {\n setIsAnimating(true)\n }, delay)\n return () => clearTimeout(startTimeout)\n }\n\n const observer = new IntersectionObserver(\n ([entry]) => {\n if (entry.isIntersecting) {\n setTimeout(() => {\n setIsAnimating(true)\n }, delay)\n observer.disconnect()\n }\n },\n { threshold: 0.1, rootMargin: \"-30% 0px -30% 0px\" }\n )\n\n if (elementRef.current) {\n observer.observe(elementRef.current)\n }\n\n return () => observer.disconnect()\n }, [delay, startOnView])\n\n // Handle scramble animation\n useEffect(() => {\n if (!isAnimating) return\n\n const maxIterations = children.length\n const startTime = performance.now()\n let animationFrameId: number\n\n const animate = (currentTime: number) => {\n const elapsed = currentTime - startTime\n const progress = Math.min(elapsed / duration, 1)\n\n iterationCount.current = progress * maxIterations\n\n setDisplayText((currentText) =>\n currentText.map((letter, index) =>\n letter === \" \"\n ? letter\n : index <= iterationCount.current\n ? children[index]\n : characterSet[getRandomInt(characterSet.length)]\n )\n )\n\n if (progress < 1) {\n animationFrameId = requestAnimationFrame(animate)\n } else {\n setIsAnimating(false)\n }\n }\n\n animationFrameId = requestAnimationFrame(animate)\n\n return () => cancelAnimationFrame(animationFrameId)\n }, [children, duration, isAnimating, characterSet])\n\n return (\n <MotionComponent\n ref={elementRef}\n className={cn(\"overflow-hidden py-2 text-4xl font-bold\", className)}\n onMouseEnter={handleAnimationTrigger}\n {...props}\n >\n <AnimatePresence>\n {displayText.map((letter, index) => (\n <motion.span\n key={index}\n className={cn(\"font-mono\", letter === \" \" ? \"w-3\" : \"\")}\n >\n {letter.toUpperCase()}\n </motion.span>\n ))}\n </AnimatePresence>\n </MotionComponent>\n )\n}\n",+ "content": "\"use client\"\n\nimport {\n useEffect,\n useRef,\n useState,\n type ComponentType,\n type RefAttributes,\n} from \"react\"\nimport {\n AnimatePresence,\n motion,\n type DOMMotionComponents,\n type HTMLMotionProps,\n type MotionProps,\n} from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\ntype CharacterSet = string[] | readonly string[]\n\nconst motionElements = {\n article: motion.article,\n div: motion.div,\n h1: motion.h1,\n h2: motion.h2,\n h3: motion.h3,\n h4: motion.h4,\n h5: motion.h5,\n h6: motion.h6,\n li: motion.li,\n p: motion.p,\n section: motion.section,\n span: motion.span,\n} as const\n\ntype MotionElementType = Extract<\n keyof DOMMotionComponents,\n keyof typeof motionElements\n>\ntype HyperTextMotionComponent = ComponentType<\n Omit<HTMLMotionProps<\"div\">, \"ref\"> & RefAttributes<HTMLElement>\n>\n\ninterface HyperTextProps extends Omit<MotionProps, \"children\"> {\n /** The text content to be animated */\n children: string\n /** Optional className for styling */\n className?: string\n /** Duration of the animation in milliseconds */\n duration?: number\n /** Delay before animation starts in milliseconds */\n delay?: number\n /** Component to render as - defaults to div */\n as?: MotionElementType\n /** Whether to start animation when element comes into view */\n startOnView?: boolean\n /** Whether to trigger animation on hover */\n animateOnHover?: boolean\n /** Custom character set for scramble effect. Defaults to uppercase alphabet */\n characterSet?: CharacterSet\n}\n\nconst DEFAULT_CHARACTER_SET = Object.freeze(\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\".split(\"\")\n) as readonly string[]\n\nconst getRandomInt = (max: number): number => Math.floor(Math.random() * max)\n\nexport function HyperText({\n children,\n className,\n duration = 800,\n delay = 0,\n as: Component = \"div\",\n startOnView = false,\n animateOnHover = true,\n characterSet = DEFAULT_CHARACTER_SET,\n ...props\n}: HyperTextProps) {\n const MotionComponent = motionElements[Component] as HyperTextMotionComponent\n\n const [displayText, setDisplayText] = useState<string[]>(() =>\n children.split(\"\")\n )\n const [isAnimating, setIsAnimating] = useState(false)\n const iterationCount = useRef(0)\n const elementRef = useRef<HTMLElement | null>(null)\n\n const handleAnimationTrigger = () => {\n if (animateOnHover && !isAnimating) {\n iterationCount.current = 0\n setIsAnimating(true)\n }\n }\n\n // Handle animation start based on view or delay\n useEffect(() => {\n if (!startOnView) {\n const startTimeout = setTimeout(() => {\n setIsAnimating(true)\n }, delay)\n return () => clearTimeout(startTimeout)\n }\n\n const observer = new IntersectionObserver(\n ([entry]) => {\n if (entry.isIntersecting) {\n setTimeout(() => {\n setIsAnimating(true)\n }, delay)\n observer.disconnect()\n }\n },\n { threshold: 0.1, rootMargin: \"-30% 0px -30% 0px\" }\n )\n\n if (elementRef.current) {\n observer.observe(elementRef.current)\n }\n\n return () => observer.disconnect()\n }, [delay, startOnView])\n\n // Handle scramble animation\n useEffect(() => {\n if (!isAnimating) return\n\n const maxIterations = children.length\n const startTime = performance.now()\n let animationFrameId: number\n\n const animate = (currentTime: number) => {\n const elapsed = currentTime - startTime\n const progress = Math.min(elapsed / duration, 1)\n\n iterationCount.current = progress * maxIterations\n\n setDisplayText((currentText) =>\n currentText.map((letter, index) =>\n letter === \" \"\n ? letter\n : index <= iterationCount.current\n ? children[index]\n : characterSet[getRandomInt(characterSet.length)]\n )\n )\n\n if (progress < 1) {\n animationFrameId = requestAnimationFrame(animate)\n } else {\n setIsAnimating(false)\n }\n }\n\n animationFrameId = requestAnimationFrame(animate)\n\n return () => cancelAnimationFrame(animationFrameId)\n }, [children, duration, isAnimating, characterSet])\n\n return (\n <MotionComponent\n ref={elementRef}\n className={cn(\"overflow-hidden py-2 text-4xl font-bold\", className)}\n onMouseEnter={handleAnimationTrigger}\n {...props}\n >\n <AnimatePresence>\n {displayText.map((letter, index) => (\n <motion.span\n key={index}\n className={cn(\"font-mono\", letter === \" \" ? \"w-3\" : \"\")}\n >\n {letter.toUpperCase()}\n </motion.span>\n ))}\n </AnimatePresence>\n </MotionComponent>\n )\n}\n","type": "registry:ui"}]diff --git a/apps/www/public/r/line-shadow-text.json b/apps/www/public/r/line-shadow-text.jsonindex ba404d2b..d77a4137 100644--- a/apps/www/public/r/line-shadow-text.json+++ b/apps/www/public/r/line-shadow-text.json@@ -10,7 +10,7 @@"files": [{"path": "registry/magicui/line-shadow-text.tsx",- "content": "\"use client\"\n\nimport { motion, type MotionProps } from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface LineShadowTextProps\n extends\n Omit<React.HTMLAttributes<HTMLElement>, keyof MotionProps>,\n MotionProps {\n shadowColor?: string\n as?: React.ElementType\n}\n\nexport function LineShadowText({\n children,\n shadowColor = \"black\",\n className,\n as: Component = \"span\",\n ...props\n}: LineShadowTextProps) {\n const MotionComponent = motion.create(Component)\n const content = typeof children === \"string\" ? children : null\n\n if (!content) {\n throw new Error(\"LineShadowText only accepts string content\")\n }\n\n return (\n <MotionComponent\n style={{ \"--shadow-color\": shadowColor } as React.CSSProperties}\n className={cn(\n \"relative z-0 inline-flex\",\n \"after:absolute after:top-[0.04em] after:left-[0.04em] after:content-[attr(data-text)]\",\n \"after:bg-[linear-gradient(45deg,transparent_45%,var(--shadow-color)_45%,var(--shadow-color)_55%,transparent_0)]\",\n \"after:-z-10 after:bg-[length:0.06em_0.06em] after:bg-clip-text after:text-transparent\",\n \"after:animate-line-shadow\",\n className\n )}\n data-text={content}\n {...props}\n >\n {content}\n </MotionComponent>\n )\n}\n",+ "content": "\"use client\"\n\nimport { type CSSProperties, type HTMLAttributes } from \"react\"\nimport {\n motion,\n type DOMMotionComponents,\n type MotionProps,\n} from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\nconst motionElements = {\n article: motion.article,\n div: motion.div,\n h1: motion.h1,\n h2: motion.h2,\n h3: motion.h3,\n h4: motion.h4,\n h5: motion.h5,\n h6: motion.h6,\n li: motion.li,\n p: motion.p,\n section: motion.section,\n span: motion.span,\n} as const\n\ntype MotionElementType = Extract<\n keyof DOMMotionComponents,\n keyof typeof motionElements\n>\n\ninterface LineShadowTextProps\n extends Omit<HTMLAttributes<HTMLElement>, keyof MotionProps>, MotionProps {\n children: string\n shadowColor?: string\n as?: MotionElementType\n}\n\nexport function LineShadowText({\n children,\n shadowColor = \"black\",\n className,\n as: Component = \"span\",\n ...props\n}: LineShadowTextProps) {\n const MotionComponent = motionElements[Component]\n\n return (\n <MotionComponent\n style={{ \"--shadow-color\": shadowColor } as CSSProperties}\n className={cn(\n \"relative z-0 inline-flex\",\n \"after:absolute after:top-[0.04em] after:left-[0.04em] after:content-[attr(data-text)]\",\n \"after:bg-[linear-gradient(45deg,transparent_45%,var(--shadow-color)_45%,var(--shadow-color)_55%,transparent_0)]\",\n \"after:-z-10 after:bg-[length:0.06em_0.06em] after:bg-clip-text after:text-transparent\",\n \"after:animate-line-shadow\",\n className\n )}\n data-text={children}\n {...props}\n >\n {children}\n </MotionComponent>\n )\n}\n","type": "registry:ui"}],diff --git a/apps/www/public/r/terminal.json b/apps/www/public/r/terminal.jsonindex d3333b9d..d679cdcf 100644--- a/apps/www/public/r/terminal.json+++ b/apps/www/public/r/terminal.json@@ -7,7 +7,7 @@"files": [{"path": "registry/magicui/terminal.tsx",- "content": "\"use client\"\n\nimport {\n Children,\n createContext,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\"\nimport { motion, useInView, type MotionProps } from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface SequenceContextValue {\n completeItem: (index: number) => void\n activeIndex: number\n sequenceStarted: boolean\n}\n\nconst SequenceContext = createContext<SequenceContextValue | null>(null)\n\nconst useSequence = () => useContext(SequenceContext)\n\nconst ItemIndexContext = createContext<number | null>(null)\nconst useItemIndex = () => useContext(ItemIndexContext)\n\ninterface AnimatedSpanProps extends MotionProps {\n children: React.ReactNode\n delay?: number\n className?: string\n startOnView?: boolean\n}\n\nexport const AnimatedSpan = ({\n children,\n delay = 0,\n className,\n startOnView = false,\n ...props\n}: AnimatedSpanProps) => {\n const elementRef = useRef<HTMLDivElement | null>(null)\n const isInView = useInView(elementRef as React.RefObject<Element>, {\n amount: 0.3,\n once: true,\n })\n\n const sequence = useSequence()\n const itemIndex = useItemIndex()\n const [hasStarted, setHasStarted] = useState(false)\n useEffect(() => {\n if (!sequence || itemIndex === null) return\n if (!sequence.sequenceStarted) return\n if (hasStarted) return\n if (sequence.activeIndex === itemIndex) {\n setHasStarted(true)\n }\n }, [sequence?.activeIndex, sequence?.sequenceStarted, hasStarted, itemIndex])\n\n const shouldAnimate = sequence ? hasStarted : startOnView ? isInView : true\n\n return (\n <motion.div\n ref={elementRef}\n initial={{ opacity: 0, y: -5 }}\n animate={shouldAnimate ? { opacity: 1, y: 0 } : { opacity: 0, y: -5 }}\n transition={{ duration: 0.3, delay: sequence ? 0 : delay / 1000 }}\n className={cn(\"grid text-sm font-normal tracking-tight\", className)}\n onAnimationComplete={() => {\n if (!sequence) return\n if (itemIndex === null) return\n sequence.completeItem(itemIndex)\n }}\n {...props}\n >\n {children}\n </motion.div>\n )\n}\n\ninterface TypingAnimationProps extends MotionProps {\n children: string\n className?: string\n duration?: number\n delay?: number\n as?: React.ElementType\n startOnView?: boolean\n}\n\nexport const TypingAnimation = ({\n children,\n className,\n duration = 60,\n delay = 0,\n as: Component = \"span\",\n startOnView = true,\n ...props\n}: TypingAnimationProps) => {\n if (typeof children !== \"string\") {\n throw new Error(\"TypingAnimation: children must be a string. Received:\")\n }\n\n const MotionComponent = useMemo(\n () =>\n motion.create(Component, {\n forwardMotionProps: true,\n }),\n [Component]\n )\n\n const [displayedText, setDisplayedText] = useState<string>(\"\")\n const [started, setStarted] = useState(false)\n const elementRef = useRef<HTMLElement | null>(null)\n const isInView = useInView(elementRef as React.RefObject<Element>, {\n amount: 0.3,\n once: true,\n })\n\n const sequence = useSequence()\n const itemIndex = useItemIndex()\n\n useEffect(() => {\n if (sequence && itemIndex !== null) {\n if (!sequence.sequenceStarted) return\n if (started) return\n if (sequence.activeIndex === itemIndex) {\n setStarted(true)\n }\n return\n }\n\n if (!startOnView) {\n const startTimeout = setTimeout(() => setStarted(true), delay)\n return () => clearTimeout(startTimeout)\n }\n\n if (!isInView) return\n\n const startTimeout = setTimeout(() => setStarted(true), delay)\n return () => clearTimeout(startTimeout)\n }, [\n delay,\n startOnView,\n isInView,\n started,\n sequence?.activeIndex,\n sequence?.sequenceStarted,\n itemIndex,\n ])\n\n useEffect(() => {\n if (!started) return\n\n let i = 0\n const typingEffect = setInterval(() => {\n if (i < children.length) {\n setDisplayedText(children.substring(0, i + 1))\n i++\n } else {\n clearInterval(typingEffect)\n if (sequence && itemIndex !== null) {\n sequence.completeItem(itemIndex)\n }\n }\n }, duration)\n\n return () => {\n clearInterval(typingEffect)\n }\n }, [children, duration, started])\n\n return (\n <MotionComponent\n ref={elementRef}\n className={cn(\"text-sm font-normal tracking-tight\", className)}\n {...props}\n >\n {displayedText}\n </MotionComponent>\n )\n}\n\ninterface TerminalProps {\n children: React.ReactNode\n className?: string\n sequence?: boolean\n startOnView?: boolean\n}\n\nexport const Terminal = ({\n children,\n className,\n sequence = true,\n startOnView = true,\n}: TerminalProps) => {\n const containerRef = useRef<HTMLDivElement | null>(null)\n const isInView = useInView(containerRef as React.RefObject<Element>, {\n amount: 0.3,\n once: true,\n })\n\n const [activeIndex, setActiveIndex] = useState(0)\n const sequenceHasStarted = sequence ? !startOnView || isInView : false\n\n const contextValue = useMemo<SequenceContextValue | null>(() => {\n if (!sequence) return null\n return {\n completeItem: (index: number) => {\n setActiveIndex((current) => (index === current ? current + 1 : current))\n },\n activeIndex,\n sequenceStarted: sequenceHasStarted,\n }\n }, [sequence, activeIndex, sequenceHasStarted])\n\n const wrappedChildren = useMemo(() => {\n if (!sequence) return children\n const array = Children.toArray(children)\n return array.map((child, index) => (\n <ItemIndexContext.Provider key={index} value={index}>\n {child as React.ReactNode}\n </ItemIndexContext.Provider>\n ))\n }, [children, sequence])\n\n const content = (\n <div\n ref={containerRef}\n className={cn(\n \"border-border bg-background z-0 h-full max-h-[400px] w-full max-w-lg rounded-xl border\",\n className\n )}\n >\n <div className=\"border-border flex flex-col gap-y-2 border-b p-4\">\n <div className=\"flex flex-row gap-x-2\">\n <div className=\"h-2 w-2 rounded-full bg-red-500\"></div>\n <div className=\"h-2 w-2 rounded-full bg-yellow-500\"></div>\n <div className=\"h-2 w-2 rounded-full bg-green-500\"></div>\n </div>\n </div>\n <pre className=\"p-4\">\n <code className=\"grid gap-y-1 overflow-auto\">{wrappedChildren}</code>\n </pre>\n </div>\n )\n\n if (!sequence) return content\n\n return (\n <SequenceContext.Provider value={contextValue}>\n {content}\n </SequenceContext.Provider>\n )\n}\n",+ "content": "\"use client\"\n\nimport {\n Children,\n createContext,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ComponentType,\n type RefAttributes,\n} from \"react\"\nimport {\n motion,\n useInView,\n type DOMMotionComponents,\n type HTMLMotionProps,\n type MotionProps,\n} from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface SequenceContextValue {\n completeItem: (index: number) => void\n activeIndex: number\n sequenceStarted: boolean\n}\n\nconst SequenceContext = createContext<SequenceContextValue | null>(null)\n\nconst useSequence = () => useContext(SequenceContext)\n\nconst ItemIndexContext = createContext<number | null>(null)\nconst useItemIndex = () => useContext(ItemIndexContext)\n\nconst motionElements = {\n article: motion.article,\n div: motion.div,\n h1: motion.h1,\n h2: motion.h2,\n h3: motion.h3,\n h4: motion.h4,\n h5: motion.h5,\n h6: motion.h6,\n li: motion.li,\n p: motion.p,\n section: motion.section,\n span: motion.span,\n} as const\n\ntype MotionElementType = Extract<\n keyof DOMMotionComponents,\n keyof typeof motionElements\n>\ntype TerminalTypingMotionComponent = ComponentType<\n Omit<HTMLMotionProps<\"span\">, \"ref\"> & RefAttributes<HTMLElement>\n>\n\ninterface AnimatedSpanProps extends MotionProps {\n children: React.ReactNode\n delay?: number\n className?: string\n startOnView?: boolean\n}\n\nexport const AnimatedSpan = ({\n children,\n delay = 0,\n className,\n startOnView = false,\n ...props\n}: AnimatedSpanProps) => {\n const elementRef = useRef<HTMLDivElement | null>(null)\n const isInView = useInView(elementRef as React.RefObject<Element>, {\n amount: 0.3,\n once: true,\n })\n\n const sequence = useSequence()\n const itemIndex = useItemIndex()\n const [hasStarted, setHasStarted] = useState(false)\n useEffect(() => {\n if (!sequence || itemIndex === null) return\n if (!sequence.sequenceStarted) return\n if (hasStarted) return\n if (sequence.activeIndex === itemIndex) {\n setHasStarted(true)\n }\n }, [sequence?.activeIndex, sequence?.sequenceStarted, hasStarted, itemIndex])\n\n const shouldAnimate = sequence ? hasStarted : startOnView ? isInView : true\n\n return (\n <motion.div\n ref={elementRef}\n initial={{ opacity: 0, y: -5 }}\n animate={shouldAnimate ? { opacity: 1, y: 0 } : { opacity: 0, y: -5 }}\n transition={{ duration: 0.3, delay: sequence ? 0 : delay / 1000 }}\n className={cn(\"grid text-sm font-normal tracking-tight\", className)}\n onAnimationComplete={() => {\n if (!sequence) return\n if (itemIndex === null) return\n sequence.completeItem(itemIndex)\n }}\n {...props}\n >\n {children}\n </motion.div>\n )\n}\n\ninterface TypingAnimationProps extends Omit<MotionProps, \"children\"> {\n children: string\n className?: string\n duration?: number\n delay?: number\n as?: MotionElementType\n startOnView?: boolean\n}\n\nexport const TypingAnimation = ({\n children,\n className,\n duration = 60,\n delay = 0,\n as: Component = \"span\",\n startOnView = true,\n ...props\n}: TypingAnimationProps) => {\n if (typeof children !== \"string\") {\n throw new Error(\"TypingAnimation: children must be a string. Received:\")\n }\n\n const MotionComponent = motionElements[\n Component\n ] as TerminalTypingMotionComponent\n\n const [displayedText, setDisplayedText] = useState<string>(\"\")\n const [started, setStarted] = useState(false)\n const elementRef = useRef<HTMLElement | null>(null)\n const isInView = useInView(elementRef as React.RefObject<Element>, {\n amount: 0.3,\n once: true,\n })\n\n const sequence = useSequence()\n const itemIndex = useItemIndex()\n\n useEffect(() => {\n if (sequence && itemIndex !== null) {\n if (!sequence.sequenceStarted) return\n if (started) return\n if (sequence.activeIndex === itemIndex) {\n setStarted(true)\n }\n return\n }\n\n if (!startOnView) {\n const startTimeout = setTimeout(() => setStarted(true), delay)\n return () => clearTimeout(startTimeout)\n }\n\n if (!isInView) return\n\n const startTimeout = setTimeout(() => setStarted(true), delay)\n return () => clearTimeout(startTimeout)\n }, [\n delay,\n startOnView,\n isInView,\n started,\n sequence?.activeIndex,\n sequence?.sequenceStarted,\n itemIndex,\n ])\n\n useEffect(() => {\n if (!started) return\n\n let i = 0\n const typingEffect = setInterval(() => {\n if (i < children.length) {\n setDisplayedText(children.substring(0, i + 1))\n i++\n } else {\n clearInterval(typingEffect)\n if (sequence && itemIndex !== null) {\n sequence.completeItem(itemIndex)\n }\n }\n }, duration)\n\n return () => {\n clearInterval(typingEffect)\n }\n }, [children, duration, started])\n\n return (\n <MotionComponent\n ref={elementRef}\n className={cn(\"text-sm font-normal tracking-tight\", className)}\n {...props}\n >\n {displayedText}\n </MotionComponent>\n )\n}\n\ninterface TerminalProps {\n children: React.ReactNode\n className?: string\n sequence?: boolean\n startOnView?: boolean\n}\n\nexport const Terminal = ({\n children,\n className,\n sequence = true,\n startOnView = true,\n}: TerminalProps) => {\n const containerRef = useRef<HTMLDivElement | null>(null)\n const isInView = useInView(containerRef as React.RefObject<Element>, {\n amount: 0.3,\n once: true,\n })\n\n const [activeIndex, setActiveIndex] = useState(0)\n const sequenceHasStarted = sequence ? !startOnView || isInView : false\n\n const contextValue = useMemo<SequenceContextValue | null>(() => {\n if (!sequence) return null\n return {\n completeItem: (index: number) => {\n setActiveIndex((current) => (index === current ? current + 1 : current))\n },\n activeIndex,\n sequenceStarted: sequenceHasStarted,\n }\n }, [sequence, activeIndex, sequenceHasStarted])\n\n const wrappedChildren = useMemo(() => {\n if (!sequence) return children\n const array = Children.toArray(children)\n return array.map((child, index) => (\n <ItemIndexContext.Provider key={index} value={index}>\n {child as React.ReactNode}\n </ItemIndexContext.Provider>\n ))\n }, [children, sequence])\n\n const content = (\n <div\n ref={containerRef}\n className={cn(\n \"border-border bg-background z-0 h-full max-h-[400px] w-full max-w-lg rounded-xl border\",\n className\n )}\n >\n <div className=\"border-border flex flex-col gap-y-2 border-b p-4\">\n <div className=\"flex flex-row gap-x-2\">\n <div className=\"h-2 w-2 rounded-full bg-red-500\"></div>\n <div className=\"h-2 w-2 rounded-full bg-yellow-500\"></div>\n <div className=\"h-2 w-2 rounded-full bg-green-500\"></div>\n </div>\n </div>\n <pre className=\"p-4\">\n <code className=\"grid gap-y-1 overflow-auto\">{wrappedChildren}</code>\n </pre>\n </div>\n )\n\n if (!sequence) return content\n\n return (\n <SequenceContext.Provider value={contextValue}>\n {content}\n </SequenceContext.Provider>\n )\n}\n","type": "registry:ui"}]diff --git a/apps/www/public/r/text-animate.json b/apps/www/public/r/text-animate.jsonindex 5fa91cb8..5ad60f8c 100644--- a/apps/www/public/r/text-animate.json+++ b/apps/www/public/r/text-animate.json@@ -10,7 +10,7 @@"files": [{"path": "registry/magicui/text-animate.tsx",- "content": "\"use client\"\n\nimport { ElementType, memo } from \"react\"\nimport {\n AnimatePresence,\n motion,\n Variants,\n type MotionProps,\n} from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\ntype AnimationType = \"text\" | \"word\" | \"character\" | \"line\"\ntype AnimationVariant =\n | \"fadeIn\"\n | \"blurIn\"\n | \"blurInUp\"\n | \"blurInDown\"\n | \"slideUp\"\n | \"slideDown\"\n | \"slideLeft\"\n | \"slideRight\"\n | \"scaleUp\"\n | \"scaleDown\"\n\ninterface TextAnimateProps extends MotionProps {\n /**\n * The text content to animate\n */\n children: string\n /**\n * The class name to be applied to the component\n */\n className?: string\n /**\n * The class name to be applied to each segment\n */\n segmentClassName?: string\n /**\n * The delay before the animation starts\n */\n delay?: number\n /**\n * The duration of the animation\n */\n duration?: number\n /**\n * Custom motion variants for the animation\n */\n variants?: Variants\n /**\n * The element type to render\n */\n as?: ElementType\n /**\n * How to split the text (\"text\", \"word\", \"character\")\n */\n by?: AnimationType\n /**\n * Whether to start animation when component enters viewport\n */\n startOnView?: boolean\n /**\n * Whether to animate only once\n */\n once?: boolean\n /**\n * The animation preset to use\n */\n animation?: AnimationVariant\n /**\n * Whether to enable accessibility features (default: true)\n */\n accessible?: boolean\n}\n\nconst staggerTimings: Record<AnimationType, number> = {\n text: 0.06,\n word: 0.05,\n character: 0.03,\n line: 0.06,\n}\n\nconst defaultContainerVariants = {\n hidden: { opacity: 1 },\n show: {\n opacity: 1,\n transition: {\n delayChildren: 0,\n staggerChildren: 0.05,\n },\n },\n exit: {\n opacity: 0,\n transition: {\n staggerChildren: 0.05,\n staggerDirection: -1,\n },\n },\n}\n\nconst defaultItemVariants: Variants = {\n hidden: { opacity: 0 },\n show: {\n opacity: 1,\n },\n exit: {\n opacity: 0,\n },\n}\n\nconst defaultItemAnimationVariants: Record<\n AnimationVariant,\n { container: Variants; item: Variants }\n> = {\n fadeIn: {\n container: defaultContainerVariants,\n item: {\n hidden: { opacity: 0, y: 20 },\n show: {\n opacity: 1,\n y: 0,\n transition: {\n duration: 0.3,\n },\n },\n exit: {\n opacity: 0,\n y: 20,\n transition: { duration: 0.3 },\n },\n },\n },\n blurIn: {\n container: defaultContainerVariants,\n item: {\n hidden: { opacity: 0, filter: \"blur(10px)\" },\n show: {\n opacity: 1,\n filter: \"blur(0px)\",\n transition: {\n duration: 0.3,\n },\n },\n exit: {\n opacity: 0,\n filter: \"blur(10px)\",\n transition: { duration: 0.3 },\n },\n },\n },\n blurInUp: {\n container: defaultContainerVariants,\n item: {\n hidden: { opacity: 0, filter: \"blur(10px)\", y: 20 },\n show: {\n opacity: 1,\n filter: \"blur(0px)\",\n y: 0,\n transition: {\n y: { duration: 0.3 },\n opacity: { duration: 0.4 },\n filter: { duration: 0.3 },\n },\n },\n exit: {\n opacity: 0,\n filter: \"blur(10px)\",\n y: 20,\n transition: {\n y: { duration: 0.3 },\n opacity: { duration: 0.4 },\n filter: { duration: 0.3 },\n },\n },\n },\n },\n blurInDown: {\n container: defaultContainerVariants,\n item: {\n hidden: { opacity: 0, filter: \"blur(10px)\", y: -20 },\n show: {\n opacity: 1,\n filter: \"blur(0px)\",\n y: 0,\n transition: {\n y: { duration: 0.3 },\n opacity: { duration: 0.4 },\n filter: { duration: 0.3 },\n },\n },\n },\n },\n slideUp: {\n container: defaultContainerVariants,\n item: {\n hidden: { y: 20, opacity: 0 },\n show: {\n y: 0,\n opacity: 1,\n transition: {\n duration: 0.3,\n },\n },\n exit: {\n y: -20,\n opacity: 0,\n transition: {\n duration: 0.3,\n },\n },\n },\n },\n slideDown: {\n container: defaultContainerVariants,\n item: {\n hidden: { y: -20, opacity: 0 },\n show: {\n y: 0,\n opacity: 1,\n transition: { duration: 0.3 },\n },\n exit: {\n y: 20,\n opacity: 0,\n transition: { duration: 0.3 },\n },\n },\n },\n slideLeft: {\n container: defaultContainerVariants,\n item: {\n hidden: { x: 20, opacity: 0 },\n show: {\n x: 0,\n opacity: 1,\n transition: { duration: 0.3 },\n },\n exit: {\n x: -20,\n opacity: 0,\n transition: { duration: 0.3 },\n },\n },\n },\n slideRight: {\n container: defaultContainerVariants,\n item: {\n hidden: { x: -20, opacity: 0 },\n show: {\n x: 0,\n opacity: 1,\n transition: { duration: 0.3 },\n },\n exit: {\n x: 20,\n opacity: 0,\n transition: { duration: 0.3 },\n },\n },\n },\n scaleUp: {\n container: defaultContainerVariants,\n item: {\n hidden: { scale: 0.5, opacity: 0 },\n show: {\n scale: 1,\n opacity: 1,\n transition: {\n duration: 0.3,\n scale: {\n type: \"spring\",\n damping: 15,\n stiffness: 300,\n },\n },\n },\n exit: {\n scale: 0.5,\n opacity: 0,\n transition: { duration: 0.3 },\n },\n },\n },\n scaleDown: {\n container: defaultContainerVariants,\n item: {\n hidden: { scale: 1.5, opacity: 0 },\n show: {\n scale: 1,\n opacity: 1,\n transition: {\n duration: 0.3,\n scale: {\n type: \"spring\",\n damping: 15,\n stiffness: 300,\n },\n },\n },\n exit: {\n scale: 1.5,\n opacity: 0,\n transition: { duration: 0.3 },\n },\n },\n },\n}\n\nconst TextAnimateBase = ({\n children,\n delay = 0,\n duration = 0.3,\n variants,\n className,\n segmentClassName,\n as: Component = \"p\",\n startOnView = true,\n once = false,\n by = \"word\",\n animation = \"fadeIn\",\n accessible = true,\n ...props\n}: TextAnimateProps) => {\n const MotionComponent = motion.create(Component)\n\n let segments: string[] = []\n switch (by) {\n case \"word\":\n segments = children.split(/(\\s+)/)\n break\n case \"character\":\n segments = children.split(\"\")\n break\n case \"line\":\n segments = children.split(\"\\n\")\n break\n case \"text\":\n default:\n segments = [children]\n break\n }\n\n const finalVariants = variants\n ? {\n container: {\n hidden: { opacity: 0 },\n show: {\n opacity: 1,\n transition: {\n opacity: { duration: 0.01, delay },\n delayChildren: delay,\n staggerChildren: duration / segments.length,\n },\n },\n exit: {\n opacity: 0,\n transition: {\n staggerChildren: duration / segments.length,\n staggerDirection: -1,\n },\n },\n },\n item: variants,\n }\n : animation\n ? {\n container: {\n ...defaultItemAnimationVariants[animation].container,\n show: {\n ...defaultItemAnimationVariants[animation].container.show,\n transition: {\n delayChildren: delay,\n staggerChildren: duration / segments.length,\n },\n },\n exit: {\n ...defaultItemAnimationVariants[animation].container.exit,\n transition: {\n staggerChildren: duration / segments.length,\n staggerDirection: -1,\n },\n },\n },\n item: defaultItemAnimationVariants[animation].item,\n }\n : { container: defaultContainerVariants, item: defaultItemVariants }\n\n return (\n <AnimatePresence mode=\"popLayout\">\n <MotionComponent\n variants={finalVariants.container as Variants}\n initial=\"hidden\"\n whileInView={startOnView ? \"show\" : undefined}\n animate={startOnView ? undefined : \"show\"}\n exit=\"exit\"\n className={cn(\"whitespace-pre-wrap\", className)}\n viewport={{ once }}\n aria-label={accessible ? children : undefined}\n {...props}\n >\n {accessible && <span className=\"sr-only\">{children}</span>}\n {segments.map((segment, i) => (\n <motion.span\n key={`${by}-${segment}-${i}`}\n variants={finalVariants.item}\n custom={i * staggerTimings[by]}\n className={cn(\n by === \"line\" ? \"block\" : \"inline-block whitespace-pre\",\n by === \"character\" && \"\",\n segmentClassName\n )}\n aria-hidden={accessible ? true : undefined}\n >\n {segment}\n </motion.span>\n ))}\n </MotionComponent>\n </AnimatePresence>\n )\n}\n\n// Export the memoized version\nexport const TextAnimate = memo(TextAnimateBase)\n",+ "content": "\"use client\"\n\nimport { memo } from \"react\"\nimport {\n AnimatePresence,\n motion,\n Variants,\n type DOMMotionComponents,\n type MotionProps,\n} from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\ntype AnimationType = \"text\" | \"word\" | \"character\" | \"line\"\ntype AnimationVariant =\n | \"fadeIn\"\n | \"blurIn\"\n | \"blurInUp\"\n | \"blurInDown\"\n | \"slideUp\"\n | \"slideDown\"\n | \"slideLeft\"\n | \"slideRight\"\n | \"scaleUp\"\n | \"scaleDown\"\n\nconst motionElements = {\n article: motion.article,\n div: motion.div,\n h1: motion.h1,\n h2: motion.h2,\n h3: motion.h3,\n h4: motion.h4,\n h5: motion.h5,\n h6: motion.h6,\n li: motion.li,\n p: motion.p,\n section: motion.section,\n span: motion.span,\n} as const\n\ntype MotionElementType = Extract<\n keyof DOMMotionComponents,\n keyof typeof motionElements\n>\n\ninterface TextAnimateProps extends Omit<MotionProps, \"children\"> {\n /**\n * The text content to animate\n */\n children: string\n /**\n * The class name to be applied to the component\n */\n className?: string\n /**\n * The class name to be applied to each segment\n */\n segmentClassName?: string\n /**\n * The delay before the animation starts\n */\n delay?: number\n /**\n * The duration of the animation\n */\n duration?: number\n /**\n * Custom motion variants for the animation\n */\n variants?: Variants\n /**\n * The element type to render\n */\n as?: MotionElementType\n /**\n * How to split the text (\"text\", \"word\", \"character\")\n */\n by?: AnimationType\n /**\n * Whether to start animation when component enters viewport\n */\n startOnView?: boolean\n /**\n * Whether to animate only once\n */\n once?: boolean\n /**\n * The animation preset to use\n */\n animation?: AnimationVariant\n /**\n * Whether to enable accessibility features (default: true)\n */\n accessible?: boolean\n}\n\nconst staggerTimings: Record<AnimationType, number> = {\n text: 0.06,\n word: 0.05,\n character: 0.03,\n line: 0.06,\n}\n\nconst defaultContainerVariants = {\n hidden: { opacity: 1 },\n show: {\n opacity: 1,\n transition: {\n delayChildren: 0,\n staggerChildren: 0.05,\n },\n },\n exit: {\n opacity: 0,\n transition: {\n staggerChildren: 0.05,\n staggerDirection: -1,\n },\n },\n}\n\nconst defaultItemVariants: Variants = {\n hidden: { opacity: 0 },\n show: {\n opacity: 1,\n },\n exit: {\n opacity: 0,\n },\n}\n\nconst defaultItemAnimationVariants: Record<\n AnimationVariant,\n { container: Variants; item: Variants }\n> = {\n fadeIn: {\n container: defaultContainerVariants,\n item: {\n hidden: { opacity: 0, y: 20 },\n show: {\n opacity: 1,\n y: 0,\n transition: {\n duration: 0.3,\n },\n },\n exit: {\n opacity: 0,\n y: 20,\n transition: { duration: 0.3 },\n },\n },\n },\n blurIn: {\n container: defaultContainerVariants,\n item: {\n hidden: { opacity: 0, filter: \"blur(10px)\" },\n show: {\n opacity: 1,\n filter: \"blur(0px)\",\n transition: {\n duration: 0.3,\n },\n },\n exit: {\n opacity: 0,\n filter: \"blur(10px)\",\n transition: { duration: 0.3 },\n },\n },\n },\n blurInUp: {\n container: defaultContainerVariants,\n item: {\n hidden: { opacity: 0, filter: \"blur(10px)\", y: 20 },\n show: {\n opacity: 1,\n filter: \"blur(0px)\",\n y: 0,\n transition: {\n y: { duration: 0.3 },\n opacity: { duration: 0.4 },\n filter: { duration: 0.3 },\n },\n },\n exit: {\n opacity: 0,\n filter: \"blur(10px)\",\n y: 20,\n transition: {\n y: { duration: 0.3 },\n opacity: { duration: 0.4 },\n filter: { duration: 0.3 },\n },\n },\n },\n },\n blurInDown: {\n container: defaultContainerVariants,\n item: {\n hidden: { opacity: 0, filter: \"blur(10px)\", y: -20 },\n show: {\n opacity: 1,\n filter: \"blur(0px)\",\n y: 0,\n transition: {\n y: { duration: 0.3 },\n opacity: { duration: 0.4 },\n filter: { duration: 0.3 },\n },\n },\n },\n },\n slideUp: {\n container: defaultContainerVariants,\n item: {\n hidden: { y: 20, opacity: 0 },\n show: {\n y: 0,\n opacity: 1,\n transition: {\n duration: 0.3,\n },\n },\n exit: {\n y: -20,\n opacity: 0,\n transition: {\n duration: 0.3,\n },\n },\n },\n },\n slideDown: {\n container: defaultContainerVariants,\n item: {\n hidden: { y: -20, opacity: 0 },\n show: {\n y: 0,\n opacity: 1,\n transition: { duration: 0.3 },\n },\n exit: {\n y: 20,\n opacity: 0,\n transition: { duration: 0.3 },\n },\n },\n },\n slideLeft: {\n container: defaultContainerVariants,\n item: {\n hidden: { x: 20, opacity: 0 },\n show: {\n x: 0,\n opacity: 1,\n transition: { duration: 0.3 },\n },\n exit: {\n x: -20,\n opacity: 0,\n transition: { duration: 0.3 },\n },\n },\n },\n slideRight: {\n container: defaultContainerVariants,\n item: {\n hidden: { x: -20, opacity: 0 },\n show: {\n x: 0,\n opacity: 1,\n transition: { duration: 0.3 },\n },\n exit: {\n x: 20,\n opacity: 0,\n transition: { duration: 0.3 },\n },\n },\n },\n scaleUp: {\n container: defaultContainerVariants,\n item: {\n hidden: { scale: 0.5, opacity: 0 },\n show: {\n scale: 1,\n opacity: 1,\n transition: {\n duration: 0.3,\n scale: {\n type: \"spring\",\n damping: 15,\n stiffness: 300,\n },\n },\n },\n exit: {\n scale: 0.5,\n opacity: 0,\n transition: { duration: 0.3 },\n },\n },\n },\n scaleDown: {\n container: defaultContainerVariants,\n item: {\n hidden: { scale: 1.5, opacity: 0 },\n show: {\n scale: 1,\n opacity: 1,\n transition: {\n duration: 0.3,\n scale: {\n type: \"spring\",\n damping: 15,\n stiffness: 300,\n },\n },\n },\n exit: {\n scale: 1.5,\n opacity: 0,\n transition: { duration: 0.3 },\n },\n },\n },\n}\n\nconst TextAnimateBase = ({\n children,\n delay = 0,\n duration = 0.3,\n variants,\n className,\n segmentClassName,\n as: Component = \"p\",\n startOnView = true,\n once = false,\n by = \"word\",\n animation = \"fadeIn\",\n accessible = true,\n ...props\n}: TextAnimateProps) => {\n const MotionComponent = motionElements[Component]\n\n let segments: string[] = []\n switch (by) {\n case \"word\":\n segments = children.split(/(\\s+)/)\n break\n case \"character\":\n segments = children.split(\"\")\n break\n case \"line\":\n segments = children.split(\"\\n\")\n break\n case \"text\":\n default:\n segments = [children]\n break\n }\n\n const finalVariants = variants\n ? {\n container: {\n hidden: { opacity: 0 },\n show: {\n opacity: 1,\n transition: {\n opacity: { duration: 0.01, delay },\n delayChildren: delay,\n staggerChildren: duration / segments.length,\n },\n },\n exit: {\n opacity: 0,\n transition: {\n staggerChildren: duration / segments.length,\n staggerDirection: -1,\n },\n },\n },\n item: variants,\n }\n : animation\n ? {\n container: {\n ...defaultItemAnimationVariants[animation].container,\n show: {\n ...defaultItemAnimationVariants[animation].container.show,\n transition: {\n delayChildren: delay,\n staggerChildren: duration / segments.length,\n },\n },\n exit: {\n ...defaultItemAnimationVariants[animation].container.exit,\n transition: {\n staggerChildren: duration / segments.length,\n staggerDirection: -1,\n },\n },\n },\n item: defaultItemAnimationVariants[animation].item,\n }\n : { container: defaultContainerVariants, item: defaultItemVariants }\n\n return (\n <AnimatePresence mode=\"popLayout\">\n <MotionComponent\n variants={finalVariants.container as Variants}\n initial=\"hidden\"\n whileInView={startOnView ? \"show\" : undefined}\n animate={startOnView ? undefined : \"show\"}\n exit=\"exit\"\n className={cn(\"whitespace-pre-wrap\", className)}\n viewport={{ once }}\n aria-label={accessible ? children : undefined}\n {...props}\n >\n {accessible && <span className=\"sr-only\">{children}</span>}\n {segments.map((segment, i) => (\n <motion.span\n key={`${by}-${segment}-${i}`}\n variants={finalVariants.item}\n custom={i * staggerTimings[by]}\n className={cn(\n by === \"line\" ? \"block\" : \"inline-block whitespace-pre\",\n by === \"character\" && \"\",\n segmentClassName\n )}\n aria-hidden={accessible ? true : undefined}\n >\n {segment}\n </motion.span>\n ))}\n </MotionComponent>\n </AnimatePresence>\n )\n}\n\n// Export the memoized version\nexport const TextAnimate = memo(TextAnimateBase)\n","type": "registry:ui"}]diff --git a/apps/www/public/r/typing-animation.json b/apps/www/public/r/typing-animation.jsonindex cc642fe2..8baccb45 100644--- a/apps/www/public/r/typing-animation.json+++ b/apps/www/public/r/typing-animation.json@@ -10,7 +10,7 @@"files": [{"path": "registry/magicui/typing-animation.tsx",- "content": "\"use client\"\n\nimport { useEffect, useMemo, useRef, useState } from \"react\"\nimport { motion, useInView, type MotionProps } from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface TypingAnimationProps extends MotionProps {\n children?: string\n words?: string[]\n className?: string\n duration?: number\n typeSpeed?: number\n deleteSpeed?: number\n delay?: number\n pauseDelay?: number\n loop?: boolean\n as?: React.ElementType\n startOnView?: boolean\n showCursor?: boolean\n blinkCursor?: boolean\n cursorStyle?: \"line\" | \"block\" | \"underscore\"\n}\n\nexport function TypingAnimation({\n children,\n words,\n className,\n duration = 100,\n typeSpeed,\n deleteSpeed,\n delay = 0,\n pauseDelay = 1000,\n loop = false,\n as: Component = \"span\",\n startOnView = true,\n showCursor = true,\n blinkCursor = true,\n cursorStyle = \"line\",\n ...props\n}: TypingAnimationProps) {\n const MotionComponent = motion.create(Component, {\n forwardMotionProps: true,\n })\n\n const [displayedText, setDisplayedText] = useState<string>(\"\")\n const [currentWordIndex, setCurrentWordIndex] = useState(0)\n const [currentCharIndex, setCurrentCharIndex] = useState(0)\n const [phase, setPhase] = useState<\"typing\" | \"pause\" | \"deleting\">(\"typing\")\n const elementRef = useRef<HTMLElement | null>(null)\n const isInView = useInView(elementRef as React.RefObject<Element>, {\n amount: 0.3,\n once: true,\n })\n\n const wordsToAnimate = useMemo(\n () => words ?? (children ? [children] : []),\n [words, children]\n )\n const hasMultipleWords = wordsToAnimate.length > 1\n\n const typingSpeed = typeSpeed ?? duration\n const deletingSpeed = deleteSpeed ?? typingSpeed / 2\n\n const shouldStart = startOnView ? isInView : true\n\n useEffect(() => {\n if (!shouldStart || wordsToAnimate.length === 0) return\n\n const timeoutDelay =\n delay > 0 && displayedText === \"\"\n ? delay\n : phase === \"typing\"\n ? typingSpeed\n : phase === \"deleting\"\n ? deletingSpeed\n : pauseDelay\n\n const timeout = setTimeout(() => {\n const currentWord = wordsToAnimate[currentWordIndex] || \"\"\n const graphemes = Array.from(currentWord)\n\n switch (phase) {\n case \"typing\":\n if (currentCharIndex < graphemes.length) {\n setDisplayedText(graphemes.slice(0, currentCharIndex + 1).join(\"\"))\n setCurrentCharIndex(currentCharIndex + 1)\n } else {\n if (hasMultipleWords || loop) {\n const isLastWord = currentWordIndex === wordsToAnimate.length - 1\n if (!isLastWord || loop) {\n setPhase(\"pause\")\n }\n }\n }\n break\n\n case \"pause\":\n setPhase(\"deleting\")\n break\n\n case \"deleting\":\n if (currentCharIndex > 0) {\n setDisplayedText(graphemes.slice(0, currentCharIndex - 1).join(\"\"))\n setCurrentCharIndex(currentCharIndex - 1)\n } else {\n const nextIndex = (currentWordIndex + 1) % wordsToAnimate.length\n setCurrentWordIndex(nextIndex)\n setPhase(\"typing\")\n }\n break\n }\n }, timeoutDelay)\n\n return () => clearTimeout(timeout)\n }, [\n shouldStart,\n phase,\n currentCharIndex,\n currentWordIndex,\n displayedText,\n wordsToAnimate,\n hasMultipleWords,\n loop,\n typingSpeed,\n deletingSpeed,\n pauseDelay,\n delay,\n ])\n\n const currentWordGraphemes = Array.from(\n wordsToAnimate[currentWordIndex] || \"\"\n )\n const isComplete =\n !loop &&\n currentWordIndex === wordsToAnimate.length - 1 &&\n currentCharIndex >= currentWordGraphemes.length &&\n phase !== \"deleting\"\n\n const shouldShowCursor =\n showCursor &&\n !isComplete &&\n (hasMultipleWords || loop || currentCharIndex < currentWordGraphemes.length)\n\n const getCursorChar = () => {\n switch (cursorStyle) {\n case \"block\":\n return \"▌\"\n case \"underscore\":\n return \"_\"\n case \"line\":\n default:\n return \"|\"\n }\n }\n\n return (\n <MotionComponent\n ref={elementRef}\n className={cn(\"leading-20 tracking-[-0.02em]\", className)}\n {...props}\n >\n {displayedText}\n {shouldShowCursor && (\n <span\n className={cn(\"inline-block\", blinkCursor && \"animate-blink-cursor\")}\n >\n {getCursorChar()}\n </span>\n )}\n </MotionComponent>\n )\n}\n",+ "content": "\"use client\"\n\nimport {\n useEffect,\n useMemo,\n useRef,\n useState,\n type ComponentType,\n type RefAttributes,\n type RefObject,\n} from \"react\"\nimport {\n motion,\n useInView,\n type DOMMotionComponents,\n type HTMLMotionProps,\n type MotionProps,\n} from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\nconst motionElements = {\n article: motion.article,\n div: motion.div,\n h1: motion.h1,\n h2: motion.h2,\n h3: motion.h3,\n h4: motion.h4,\n h5: motion.h5,\n h6: motion.h6,\n li: motion.li,\n p: motion.p,\n section: motion.section,\n span: motion.span,\n} as const\n\ntype MotionElementType = Extract<\n keyof DOMMotionComponents,\n keyof typeof motionElements\n>\ntype TypingAnimationMotionComponent = ComponentType<\n Omit<HTMLMotionProps<\"span\">, \"ref\"> & RefAttributes<HTMLElement>\n>\n\ninterface TypingAnimationProps extends Omit<MotionProps, \"children\"> {\n children?: string\n words?: string[]\n className?: string\n duration?: number\n typeSpeed?: number\n deleteSpeed?: number\n delay?: number\n pauseDelay?: number\n loop?: boolean\n as?: MotionElementType\n startOnView?: boolean\n showCursor?: boolean\n blinkCursor?: boolean\n cursorStyle?: \"line\" | \"block\" | \"underscore\"\n}\n\nexport function TypingAnimation({\n children,\n words,\n className,\n duration = 100,\n typeSpeed,\n deleteSpeed,\n delay = 0,\n pauseDelay = 1000,\n loop = false,\n as: Component = \"span\",\n startOnView = true,\n showCursor = true,\n blinkCursor = true,\n cursorStyle = \"line\",\n ...props\n}: TypingAnimationProps) {\n const MotionComponent = motionElements[\n Component\n ] as TypingAnimationMotionComponent\n\n const [displayedText, setDisplayedText] = useState<string>(\"\")\n const [currentWordIndex, setCurrentWordIndex] = useState(0)\n const [currentCharIndex, setCurrentCharIndex] = useState(0)\n const [phase, setPhase] = useState<\"typing\" | \"pause\" | \"deleting\">(\"typing\")\n const elementRef = useRef<HTMLElement | null>(null)\n const isInView = useInView(elementRef as RefObject<Element>, {\n amount: 0.3,\n once: true,\n })\n\n const wordsToAnimate = useMemo(\n () => words ?? (children ? [children] : []),\n [words, children]\n )\n const hasMultipleWords = wordsToAnimate.length > 1\n\n const typingSpeed = typeSpeed ?? duration\n const deletingSpeed = deleteSpeed ?? typingSpeed / 2\n\n const shouldStart = startOnView ? isInView : true\n const animationSourceKey = useMemo(\n () => (words ? words.join(\"\\u0000\") : (children ?? \"\")),\n [words, children]\n )\n\n useEffect(() => {\n setDisplayedText(\"\")\n setCurrentWordIndex(0)\n setCurrentCharIndex(0)\n setPhase(\"typing\")\n }, [animationSourceKey])\n\n useEffect(() => {\n if (!shouldStart || wordsToAnimate.length === 0) return\n\n const timeoutDelay =\n delay > 0 && displayedText === \"\"\n ? delay\n : phase === \"typing\"\n ? typingSpeed\n : phase === \"deleting\"\n ? deletingSpeed\n : pauseDelay\n\n const timeout = setTimeout(() => {\n const currentWord = wordsToAnimate[currentWordIndex] || \"\"\n const graphemes = Array.from(currentWord)\n\n switch (phase) {\n case \"typing\":\n if (currentCharIndex < graphemes.length) {\n setDisplayedText(graphemes.slice(0, currentCharIndex + 1).join(\"\"))\n setCurrentCharIndex(currentCharIndex + 1)\n } else {\n if (hasMultipleWords || loop) {\n const isLastWord = currentWordIndex === wordsToAnimate.length - 1\n if (!isLastWord || loop) {\n setPhase(\"pause\")\n }\n }\n }\n break\n\n case \"pause\":\n setPhase(\"deleting\")\n break\n\n case \"deleting\":\n if (currentCharIndex > 0) {\n setDisplayedText(graphemes.slice(0, currentCharIndex - 1).join(\"\"))\n setCurrentCharIndex(currentCharIndex - 1)\n } else {\n const nextIndex = (currentWordIndex + 1) % wordsToAnimate.length\n setCurrentWordIndex(nextIndex)\n setPhase(\"typing\")\n }\n break\n }\n }, timeoutDelay)\n\n return () => clearTimeout(timeout)\n }, [\n shouldStart,\n phase,\n currentCharIndex,\n currentWordIndex,\n displayedText,\n wordsToAnimate,\n hasMultipleWords,\n loop,\n typingSpeed,\n deletingSpeed,\n pauseDelay,\n delay,\n ])\n\n const currentWordGraphemes = Array.from(\n wordsToAnimate[currentWordIndex] || \"\"\n )\n const isComplete =\n !loop &&\n currentWordIndex === wordsToAnimate.length - 1 &&\n currentCharIndex >= currentWordGraphemes.length &&\n phase !== \"deleting\"\n\n const shouldShowCursor =\n showCursor &&\n !isComplete &&\n (hasMultipleWords || loop || currentCharIndex < currentWordGraphemes.length)\n\n const getCursorChar = () => {\n switch (cursorStyle) {\n case \"block\":\n return \"▌\"\n case \"underscore\":\n return \"_\"\n case \"line\":\n default:\n return \"|\"\n }\n }\n\n return (\n <MotionComponent\n ref={elementRef}\n className={cn(\n \"leading-20 tracking-[-0.02em]\",\n Component === \"span\" && \"inline-block\",\n className\n )}\n {...props}\n >\n {displayedText}\n {shouldShowCursor && (\n <span\n className={cn(\"inline-block\", blinkCursor && \"animate-blink-cursor\")}\n >\n {getCursorChar()}\n </span>\n )}\n </MotionComponent>\n )\n}\n","type": "registry:ui"}],diff --git a/apps/www/registry/magicui/hyper-text.tsx b/apps/www/registry/magicui/hyper-text.tsxindex 6fbef43e..65ee46dd 100644--- a/apps/www/registry/magicui/hyper-text.tsx+++ b/apps/www/registry/magicui/hyper-text.tsx@@ -1,13 +1,48 @@"use client"-import { useEffect, useRef, useState } from "react"-import { AnimatePresence, motion, type MotionProps } from "motion/react"+import {+ useEffect,+ useRef,+ useState,+ type ComponentType,+ type RefAttributes,+} from "react"+import {+ AnimatePresence,+ motion,+ type DOMMotionComponents,+ type HTMLMotionProps,+ type MotionProps,+} from "motion/react"import { cn } from "@/lib/utils"type CharacterSet = string[] | readonly string[]-interface HyperTextProps extends MotionProps {+const motionElements = {+ article: motion.article,+ div: motion.div,+ h1: motion.h1,+ h2: motion.h2,+ h3: motion.h3,+ h4: motion.h4,+ h5: motion.h5,+ h6: motion.h6,+ li: motion.li,+ p: motion.p,+ section: motion.section,+ span: motion.span,+} as const++type MotionElementType = Extract<+ keyof DOMMotionComponents,+ keyof typeof motionElements+>+type HyperTextMotionComponent = ComponentType<+ Omit<HTMLMotionProps<"div">, "ref"> & RefAttributes<HTMLElement>+>++interface HyperTextProps extends Omit<MotionProps, "children"> {/** The text content to be animated */children: string/** Optional className for styling */@@ -17,7 +52,7 @@ interface HyperTextProps extends MotionProps {/** Delay before animation starts in milliseconds */delay?: number/** Component to render as - defaults to div */- as?: React.ElementType+ as?: MotionElementType/** Whether to start animation when element comes into view */startOnView?: boolean/** Whether to trigger animation on hover */@@ -43,16 +78,14 @@ export function HyperText({characterSet = DEFAULT_CHARACTER_SET,...props}: HyperTextProps) {- const MotionComponent = motion.create(Component, {- forwardMotionProps: true,- })+ const MotionComponent = motionElements[Component] as HyperTextMotionComponentconst [displayText, setDisplayText] = useState<string[]>(() =>children.split(""))const [isAnimating, setIsAnimating] = useState(false)const iterationCount = useRef(0)- const elementRef = useRef<HTMLElement>(null)+ const elementRef = useRef<HTMLElement | null>(null)const handleAnimationTrigger = () => {if (animateOnHover && !isAnimating) {diff --git a/apps/www/registry/magicui/line-shadow-text.tsx b/apps/www/registry/magicui/line-shadow-text.tsxindex 93b6591b..5b88a0cb 100644--- a/apps/www/registry/magicui/line-shadow-text.tsx+++ b/apps/www/registry/magicui/line-shadow-text.tsx@@ -1,15 +1,39 @@"use client"-import { motion, type MotionProps } from "motion/react"+import { type CSSProperties, type HTMLAttributes } from "react"+import {+ motion,+ type DOMMotionComponents,+ type MotionProps,+} from "motion/react"import { cn } from "@/lib/utils"+const motionElements = {+ article: motion.article,+ div: motion.div,+ h1: motion.h1,+ h2: motion.h2,+ h3: motion.h3,+ h4: motion.h4,+ h5: motion.h5,+ h6: motion.h6,+ li: motion.li,+ p: motion.p,+ section: motion.section,+ span: motion.span,+} as const++type MotionElementType = Extract<+ keyof DOMMotionComponents,+ keyof typeof motionElements+>+interface LineShadowTextProps- extends- Omit<React.HTMLAttributes<HTMLElement>, keyof MotionProps>,- MotionProps {+ extends Omit<HTMLAttributes<HTMLElement>, keyof MotionProps>, MotionProps {+ children: stringshadowColor?: string- as?: React.ElementType+ as?: MotionElementType}export function LineShadowText({@@ -19,16 +43,11 @@ export function LineShadowText({as: Component = "span",...props}: LineShadowTextProps) {- const MotionComponent = motion.create(Component)- const content = typeof children === "string" ? children : null-- if (!content) {- throw new Error("LineShadowText only accepts string content")- }+ const MotionComponent = motionElements[Component]return (<MotionComponent- style={{ "--shadow-color": shadowColor } as React.CSSProperties}+ style={{ "--shadow-color": shadowColor } as CSSProperties}className={cn("relative z-0 inline-flex","after:absolute after:top-[0.04em] after:left-[0.04em] after:content-[attr(data-text)]",@@ -37,10 +56,10 @@ export function LineShadowText({"after:animate-line-shadow",className)}- data-text={content}+ data-text={children}{...props}>- {content}+ {children}</MotionComponent>)}diff --git a/apps/www/registry/magicui/terminal.tsx b/apps/www/registry/magicui/terminal.tsxindex a9f91578..9311ebdf 100644--- a/apps/www/registry/magicui/terminal.tsx+++ b/apps/www/registry/magicui/terminal.tsx@@ -8,8 +8,16 @@ import {useMemo,useRef,useState,+ type ComponentType,+ type RefAttributes,} from "react"-import { motion, useInView, type MotionProps } from "motion/react"+import {+ motion,+ useInView,+ type DOMMotionComponents,+ type HTMLMotionProps,+ type MotionProps,+} from "motion/react"import { cn } from "@/lib/utils"@@ -26,6 +34,29 @@ const useSequence = () => useContext(SequenceContext)const ItemIndexContext = createContext<number | null>(null)const useItemIndex = () => useContext(ItemIndexContext)+const motionElements = {+ article: motion.article,+ div: motion.div,+ h1: motion.h1,+ h2: motion.h2,+ h3: motion.h3,+ h4: motion.h4,+ h5: motion.h5,+ h6: motion.h6,+ li: motion.li,+ p: motion.p,+ section: motion.section,+ span: motion.span,+} as const++type MotionElementType = Extract<+ keyof DOMMotionComponents,+ keyof typeof motionElements+>+type TerminalTypingMotionComponent = ComponentType<+ Omit<HTMLMotionProps<"span">, "ref"> & RefAttributes<HTMLElement>+>+interface AnimatedSpanProps extends MotionProps {children: React.ReactNodedelay?: number@@ -79,12 +110,12 @@ export const AnimatedSpan = ({)}-interface TypingAnimationProps extends MotionProps {+interface TypingAnimationProps extends Omit<MotionProps, "children"> {children: stringclassName?: stringduration?: numberdelay?: number- as?: React.ElementType+ as?: MotionElementTypestartOnView?: boolean}@@ -101,13 +132,9 @@ export const TypingAnimation = ({throw new Error("TypingAnimation: children must be a string. Received:")}- const MotionComponent = useMemo(- () =>- motion.create(Component, {- forwardMotionProps: true,- }),- [Component]- )+ const MotionComponent = motionElements[+ Component+ ] as TerminalTypingMotionComponentconst [displayedText, setDisplayedText] = useState<string>("")const [started, setStarted] = useState(false)diff --git a/apps/www/registry/magicui/text-animate.tsx b/apps/www/registry/magicui/text-animate.tsxindex 77dd7079..ce2b453f 100644--- a/apps/www/registry/magicui/text-animate.tsx+++ b/apps/www/registry/magicui/text-animate.tsx@@ -1,10 +1,11 @@"use client"-import { ElementType, memo } from "react"+import { memo } from "react"import {AnimatePresence,motion,Variants,+ type DOMMotionComponents,type MotionProps,} from "motion/react"@@ -23,7 +24,27 @@ type AnimationVariant =| "scaleUp"| "scaleDown"-interface TextAnimateProps extends MotionProps {+const motionElements = {+ article: motion.article,+ div: motion.div,+ h1: motion.h1,+ h2: motion.h2,+ h3: motion.h3,+ h4: motion.h4,+ h5: motion.h5,+ h6: motion.h6,+ li: motion.li,+ p: motion.p,+ section: motion.section,+ span: motion.span,+} as const++type MotionElementType = Extract<+ keyof DOMMotionComponents,+ keyof typeof motionElements+>++interface TextAnimateProps extends Omit<MotionProps, "children"> {/*** The text content to animate*/@@ -51,7 +72,7 @@ interface TextAnimateProps extends MotionProps {/*** The element type to render*/- as?: ElementType+ as?: MotionElementType/*** How to split the text ("text", "word", "character")*/@@ -322,7 +343,7 @@ const TextAnimateBase = ({accessible = true,...props}: TextAnimateProps) => {- const MotionComponent = motion.create(Component)+ const MotionComponent = motionElements[Component]let segments: string[] = []switch (by) {diff --git a/apps/www/registry/magicui/typing-animation.tsx b/apps/www/registry/magicui/typing-animation.tsxindex d4754e28..43d59105 100644--- a/apps/www/registry/magicui/typing-animation.tsx+++ b/apps/www/registry/magicui/typing-animation.tsx@@ -1,11 +1,48 @@"use client"-import { useEffect, useMemo, useRef, useState } from "react"-import { motion, useInView, type MotionProps } from "motion/react"+import {+ useEffect,+ useMemo,+ useRef,+ useState,+ type ComponentType,+ type RefAttributes,+ type RefObject,+} from "react"+import {+ motion,+ useInView,+ type DOMMotionComponents,+ type HTMLMotionProps,+ type MotionProps,+} from "motion/react"import { cn } from "@/lib/utils"-interface TypingAnimationProps extends MotionProps {+const motionElements = {+ article: motion.article,+ div: motion.div,+ h1: motion.h1,+ h2: motion.h2,+ h3: motion.h3,+ h4: motion.h4,+ h5: motion.h5,+ h6: motion.h6,+ li: motion.li,+ p: motion.p,+ section: motion.section,+ span: motion.span,+} as const++type MotionElementType = Extract<+ keyof DOMMotionComponents,+ keyof typeof motionElements+>+type TypingAnimationMotionComponent = ComponentType<+ Omit<HTMLMotionProps<"span">, "ref"> & RefAttributes<HTMLElement>+>++interface TypingAnimationProps extends Omit<MotionProps, "children"> {children?: stringwords?: string[]className?: string@@ -15,7 +52,7 @@ interface TypingAnimationProps extends MotionProps {delay?: numberpauseDelay?: numberloop?: boolean- as?: React.ElementType+ as?: MotionElementTypestartOnView?: booleanshowCursor?: booleanblinkCursor?: boolean@@ -39,16 +76,16 @@ export function TypingAnimation({cursorStyle = "line",...props}: TypingAnimationProps) {- const MotionComponent = motion.create(Component, {- forwardMotionProps: true,- })+ const MotionComponent = motionElements[+ Component+ ] as TypingAnimationMotionComponentconst [displayedText, setDisplayedText] = useState<string>("")const [currentWordIndex, setCurrentWordIndex] = useState(0)const [currentCharIndex, setCurrentCharIndex] = useState(0)const [phase, setPhase] = useState<"typing" | "pause" | "deleting">("typing")const elementRef = useRef<HTMLElement | null>(null)- const isInView = useInView(elementRef as React.RefObject<Element>, {+ const isInView = useInView(elementRef as RefObject<Element>, {amount: 0.3,once: true,})@@ -63,6 +100,17 @@ export function TypingAnimation({const deletingSpeed = deleteSpeed ?? typingSpeed / 2const shouldStart = startOnView ? isInView : true+ const animationSourceKey = useMemo(+ () => (words ? words.join("\u0000") : (children ?? "")),+ [words, children]+ )++ useEffect(() => {+ setDisplayedText("")+ setCurrentWordIndex(0)+ setCurrentCharIndex(0)+ setPhase("typing")+ }, [animationSourceKey])useEffect(() => {if (!shouldStart || wordsToAnimate.length === 0) return@@ -157,7 +205,11 @@ export function TypingAnimation({return (<MotionComponentref={elementRef}- className={cn("leading-20 tracking-[-0.02em]", className)}+ className={cn(+ "leading-20 tracking-[-0.02em]",+ Component === "span" && "inline-block",+ className+ )}{...props}>{displayedText}