UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
feat(dia-text-reveal): add Dia Text Reveal component with examples an… (#948)
Matheus Sanodd03620e10e4
diff --git a/apps/www/config/docs.ts b/apps/www/config/docs.tsindex 10f8123a..0b84cab0 100644--- a/apps/www/config/docs.ts+++ b/apps/www/config/docs.ts@@ -396,6 +396,12 @@ export const docsConfig: DocsConfig = {items: [],label: "",},+ {+ title: "Dia Text Reveal",+ href: `/docs/components/dia-text-reveal`,+ items: [],+ label: "New",+ },{title: "Hyper Text",href: `/docs/components/hyper-text`,diff --git a/apps/www/content/docs/components/dia-text-reveal.mdx b/apps/www/content/docs/components/dia-text-reveal.mdxnew file mode 100644index 00000000..afe87914--- /dev/null+++ b/apps/www/content/docs/components/dia-text-reveal.mdx@@ -0,0 +1,104 @@+---+title: Dia Text Reveal+date: 2026-04-13+description: A horizontal color band sweeps across text with a gradient shine, then settles on your theme foreground color.+author: magicuidesign+published: true+---++<ComponentPreview name="dia-text-reveal-demo" />++## Examples++### Custom gradient++Override `colors` for a shorter or softer palette on a single line of text.++<ComponentPreview name="dia-text-reveal-demo-2" />++### Rotating phrases in a heading++Pass `text` as an array and set `repeat` to cycle strings after each sweep. You can place static words in the same `<h1>` (or paragraph) before the component—no extra layout wrappers are required for basic inline use.++<ComponentPreview name="dia-text-reveal-demo-3" />++Use `fixedWidth` when the strings differ a lot in length and you want to avoid horizontal layout shift (not shown in this example).++### Duration and delay++Slow the sweep with `duration`, or add a short `delay` before the band moves.++<ComponentPreview name="dia-text-reveal-demo-4" />++## Installation++<Tabs defaultValue="cli">++<TabsList>+ <TabsTrigger value="cli">CLI</TabsTrigger>+ <TabsTrigger value="manual">Manual</TabsTrigger>+</TabsList>+<TabsContent value="cli">++```bash+npx shadcn@latest add @magicui/dia-text-reveal+```++</TabsContent>++<TabsContent value="manual">++<Steps>++<Step>Copy and paste the following code into your project.</Step>++<ComponentSource name="dia-text-reveal" />++<Step>Update the import paths to match your project setup.</Step>++</Steps>++</TabsContent>++</Tabs>++## Usage++```tsx showLineNumbers+import { DiaTextReveal } from "@/components/ui/dia-text-reveal"+```++```tsx showLineNumbers+<DiaTextReveal text="Magic UI" />+```++```tsx showLineNumbers+<h1 className="text-3xl font-semibold">+ Learn to{" "}+ <DiaTextReveal+ repeat+ repeatDelay={1.2}+ text={["build faster", "ship smarter", "scale easier"]}+ />+</h1>+```++## Props++| Prop | Type | Default | Description |+| ------------- | -------------------- | --------------------------------------------------------- | ------------------------------------------------------------------------------- |+| `text` | `string \| string[]` | — | Text to display. Use an array to rotate between strings when `repeat` is on. |+| `colors` | `string[]` | `["#c679c4", "#fa3d1d", "#ffb005", "#e1e1fe", "#0358f7"]` | Colors in the sweeping gradient band. |+| `textColor` | `string` | `var(--foreground)` | Solid text color after the animation (matches your theme by default). |+| `duration` | `number` | `1.5` | Sweep duration in seconds. |+| `delay` | `number` | `0` | Delay before the sweep starts, in seconds. |+| `repeat` | `boolean` | `false` | When `text` is an array, advance to the next string after each cycle. |+| `repeatDelay` | `number` | `0.5` | Pause in seconds before replaying or advancing (when `repeat` is true). |+| `startOnView` | `boolean` | `true` | Start the animation when the element enters the viewport. |+| `once` | `boolean` | `true` | Play only the first time (when `startOnView` is used). |+| `className` | `string` | — | Additional CSS classes on the root `span`. |+| `fixedWidth` | `boolean` | `false` | Lock width to the widest string when `text` is an array to reduce layout shift. |++## Credits++- Credit to [@chishiyac](https://github.com/chishiyac)diff --git a/apps/www/public/llms-full.txt b/apps/www/public/llms-full.txtindex 4dcfe2ee..756861de 100644--- a/apps/www/public/llms-full.txt+++ b/apps/www/public/llms-full.txt@@ -5652,6 +5652,358 @@ export default function CoolModeCustom() {+===== COMPONENT: dia-text-reveal =====+Title: Dia Text Reveal+Description: A horizontal color band sweeps across text, revealing a gradient shine before settling on the base color.++--- file: magicui/dia-text-reveal.tsx ---+"use client"++import { useEffect, useRef, useState } from "react"+import {+ animate,+ motion,+ useInView,+ useMotionValue,+ useReducedMotion,+ useTransform,+ type HTMLMotionProps,+} from "motion/react"++import { cn } from "@/lib/utils"++const DEFAULT_COLORS = ["#c679c4", "#fa3d1d", "#ffb005", "#e1e1fe", "#0358f7"]+const BAND_HALF = 17+const SWEEP_START = -BAND_HALF+const SWEEP_END = 100 + BAND_HALF++const sweepEase = (t: number) =>+ t < 0.5 ? 4 * t ** 3 : 1 - (-2 * t + 2) ** 3 / 2++function buildGradient(pos: number, colors: string[], textColor: string) {+ const bandStart = pos - BAND_HALF+ const bandEnd = pos + BAND_HALF++ if (bandStart >= 100) {+ return `linear-gradient(90deg, ${textColor}, ${textColor})`+ }+ const n = colors.length+ const parts: string[] = []++ if (bandStart > 0)+ parts.push(`${textColor} 0%`, `${textColor} ${bandStart.toFixed(2)}%`)++ colors.forEach((c, i) => {+ const pct = n === 1 ? pos : bandStart + (i / (n - 1)) * BAND_HALF * 2+ parts.push(`${c} ${pct.toFixed(2)}%`)+ })++ if (bandEnd < 100)+ parts.push(`transparent ${bandEnd.toFixed(2)}%`, `transparent 100%`)++ return `linear-gradient(90deg, ${parts.join(", ")})`+}++function measureWidths(el: HTMLElement, texts: string[]) {+ const ghost = el.cloneNode() as HTMLElement+ Object.assign(ghost.style, {+ position: "absolute",+ visibility: "hidden",+ pointerEvents: "none",+ width: "auto",+ whiteSpace: "nowrap",+ })+ el.parentElement!.appendChild(ghost)+ const widths = texts.map((t) => {+ ghost.textContent = t+ return ghost.getBoundingClientRect().width+ })+ ghost.remove()+ return widths+}++/**+ * Props for {@link DiaTextReveal}.+ */+export interface DiaTextRevealProps extends Omit<+ HTMLMotionProps<"span">,+ "ref" | "children" | "style" | "animate" | "transition" | "color"+> {+ /**+ * Text to reveal. Pass multiple strings to rotate when {@link DiaTextRevealProps.repeat} is `true`.+ */+ text: string | string[]+ /**+ * Colors sampled across the moving gradient band. Defaults to a built-in palette.+ */+ colors?: string[]+ /**+ * CSS color for revealed text after the sweep and for leading/trailing regions during the animation.+ * @defaultValue `"var(--foreground)"`+ */+ textColor?: string+ /**+ * Duration of one sweep pass, in seconds.+ * @defaultValue `1.5`+ */+ duration?: number+ /**+ * Delay before the sweep starts, in seconds.+ * @defaultValue `0`+ */+ delay?: number+ /**+ * When `text` is an array, replay the sweep and advance to the next string after each completion.+ * @defaultValue `false`+ */+ repeat?: boolean+ /**+ * Pause between cycles when {@link DiaTextRevealProps.repeat} is `true`, in seconds.+ * @defaultValue `0.5`+ */+ repeatDelay?: number+ /**+ * If `true`, the animation starts only after the element enters the viewport.+ * @defaultValue `true`+ */+ startOnView?: boolean+ /**+ * Passed to `useInView`: if `true`, in-view detection fires at most once (no replay on scroll-back).+ * @defaultValue `true`+ */+ once?: boolean+ /**+ * Additional class names for the animated `span` (e.g. typography utilities).+ */+ className?: string+ /**+ * When `text` has multiple entries, use the widest string’s width for layout instead of animating width per line.+ * @defaultValue `false`+ */+ fixedWidth?: boolean+}++export function DiaTextReveal({+ text,+ colors = DEFAULT_COLORS,+ textColor = "var(--foreground)",+ duration = 1.5,+ delay = 0,+ repeat = false,+ repeatDelay = 0.5,+ startOnView = true,+ once = true,+ className,+ fixedWidth = false,+ ...props+}: DiaTextRevealProps) {+ const texts = Array.isArray(text) ? text : [text]+ const isMulti = texts.length > 1+ const prefersReducedMotion = useReducedMotion()++ const spanRef = useRef<HTMLSpanElement>(null)+ const optsRef = useRef({+ colors,+ textColor,+ duration,+ delay,+ repeat,+ repeatDelay,+ texts,+ })+ optsRef.current = {+ colors,+ textColor,+ duration,+ delay,+ repeat,+ repeatDelay,+ texts,+ }++ const indexRef = useRef(0)+ const hasPlayedRef = useRef(false)+ const timerRef = useRef<ReturnType<typeof setTimeout>>(undefined)+ const playRef = useRef<() => void>(null!)+ const stopRef = useRef<(() => void) | null>(null)++ const [activeIndex, setActiveIndex] = useState(0)+ const [measuredWidths, setMeasuredWidths] = useState<number[]>([])++ const sweepPos = useMotionValue(SWEEP_START)++ const backgroundImage = useTransform(sweepPos, (pos) =>+ buildGradient(pos, optsRef.current.colors, optsRef.current.textColor)+ )++ const isInView = useInView(spanRef, { once, amount: 0.1 })++ useEffect(() => {+ const el = spanRef.current+ if (!el || !isMulti) return+ setMeasuredWidths(measureWidths(el, texts))+ }, [Array.isArray(text) ? text.join("\0") : text])++ playRef.current = () => {+ const { duration, delay, repeat, repeatDelay, texts } = optsRef.current++ sweepPos.set(SWEEP_START)++ const controls = animate(sweepPos, SWEEP_END, {+ duration,+ delay,+ ease: sweepEase,+ onComplete() {+ if (!repeat) return+ timerRef.current = setTimeout(() => {+ const next = (indexRef.current + 1) % texts.length+ indexRef.current = next+ setActiveIndex(next)+ playRef.current()+ }, repeatDelay * 1000)+ },+ })++ stopRef.current = () => controls.stop()+ }++ useEffect(() => {+ if (prefersReducedMotion) {+ sweepPos.set(SWEEP_END)+ return+ }+ if (startOnView && !isInView) return+ if (once && hasPlayedRef.current) return+ hasPlayedRef.current = true+ playRef.current()++ return () => {+ stopRef.current?.()+ clearTimeout(timerRef.current)+ }+ }, [isInView, startOnView, once, prefersReducedMotion, sweepPos])++ const fixedW =+ isMulti && fixedWidth && measuredWidths.length > 0+ ? Math.max(...measuredWidths)+ : undefined++ const animatedW =+ isMulti && !fixedWidth && measuredWidths[activeIndex] != null+ ? measuredWidths[activeIndex]+ : undefined++ return (+ <motion.span+ ref={spanRef}+ className={cn("align-bottom leading-[100%] text-inherit", className)}+ style={{+ transform: "translateY(-2px)",+ color: "transparent",+ backgroundClip: "text",+ WebkitBackgroundClip: "text",+ backgroundSize: "100% 100%",+ backgroundImage,+ ...(isMulti && {+ display: "inline-block",+ overflow: "hidden",+ whiteSpace: "nowrap",+ verticalAlign: "text-center",+ ...(fixedW != null && { width: fixedW }),+ }),+ }}+ animate={animatedW != null ? { width: animatedW } : undefined}+ transition={{ duration: 0.4, ease: [0.4, 0, 0.2, 1] }}+ {...props}+ >+ {texts[activeIndex]}+ </motion.span>+ )+}+++===== EXAMPLE: dia-text-reveal-demo =====+Title: Dia Text Reveal Demo++--- file: example/dia-text-reveal-demo.tsx ---+import { DiaTextReveal } from "@/registry/magicui/dia-text-reveal"++export default function DiaTextRevealDemo() {+ return (+ <div className="flex min-h-64 items-center justify-center p-8">+ <DiaTextReveal+ className="text-4xl font-bold tracking-tight"+ text="Magic UI"+ colors={["#A97CF8", "#F38CB8", "#FDCC92"]}+ />+ </div>+ )+}+++===== EXAMPLE: dia-text-reveal-demo-2 =====+Title: Dia Text Reveal Demo 2++--- file: example/dia-text-reveal-demo-2.tsx ---+import { DiaTextReveal } from "@/registry/magicui/dia-text-reveal"++export default function DiaTextRevealDemo2() {+ return (+ <div className="flex min-h-56 items-center justify-center p-8">+ <DiaTextReveal+ className="text-4xl font-bold tracking-tight"+ colors={["#22d3ee", "#818cf8", "#f472b6", "#34d399"]}+ text="Design systems"+ />+ </div>+ )+}+++===== EXAMPLE: dia-text-reveal-demo-3 =====+Title: Dia Text Reveal Demo 3++--- file: example/dia-text-reveal-demo-3.tsx ---+import { DiaTextReveal } from "@/registry/magicui/dia-text-reveal"++export default function DiaTextRevealDemo3() {+ return (+ <div className="text-foreground flex min-h-64 items-center justify-center p-8">+ <h1 className="text-center text-3xl font-semibold tracking-tight md:text-4xl">+ Learn to{" "}+ <DiaTextReveal+ repeat+ repeatDelay={1.2}+ text={["build faster", "ship smarter", "scale easier"]}+ />+ </h1>+ </div>+ )+}+++===== EXAMPLE: dia-text-reveal-demo-4 =====+Title: Dia Text Reveal Demo 4++--- file: example/dia-text-reveal-demo-4.tsx ---+import { DiaTextReveal } from "@/registry/magicui/dia-text-reveal"++export default function DiaTextRevealDemo4() {+ return (+ <div className="flex min-h-56 items-center justify-center p-8">+ <DiaTextReveal+ className="text-4xl font-bold tracking-tight"+ colors={["#f97316", "#eab308", "#22c55e", "#3b82f6", "#a855f7"]}+ delay={0.35}+ duration={2.4}+ text="Made with care"+ />+ </div>+ )+}+++===== COMPONENT: dock =====Title: DockDescription: An implementation of the MacOS dock using react + tailwindcss + motiondiff --git a/apps/www/public/llms.txt b/apps/www/public/llms.txtindex 8a1696e2..5b06d6c2 100644--- a/apps/www/public/llms.txt+++ b/apps/www/public/llms.txt@@ -25,6 +25,7 @@ This file provides LLM-friendly entry points to documentation and examples.- [Comic Text](https://magicui.design/docs/components/comic-text): Comic text animation- [Confetti](https://magicui.design/docs/components/confetti): Confetti animations are best used to delight your users when something special happens- [Cool Mode](https://magicui.design/docs/components/cool-mode): Cool mode effect for buttons, links, and other DOMs+- [Dia Text Reveal](https://magicui.design/docs/components/dia-text-reveal): A horizontal color band sweeps across text, revealing a gradient shine before settling on the base color.- [Dock](https://magicui.design/docs/components/dock): An implementation of the MacOS dock using react + tailwindcss + motion- [Dot Pattern](https://magicui.design/docs/components/dot-pattern): A background dot pattern made with SVGs, fully customizable using Tailwind CSS.- [Dotted Map](https://magicui.design/docs/components/dotted-map): A component with a dotted map.@@ -158,6 +159,10 @@ This file provides LLM-friendly entry points to documentation and examples.- [Animated Beam Multiple Inputs](https://github.com/magicuidesign/magicui/blob/main/example/animated-beam-multiple-inputs.tsx): Example usage- [Animated Beam Multiple Outputs](https://github.com/magicuidesign/magicui/blob/main/example/animated-beam-multiple-outputs.tsx): Example usage- [Text Reveal Demo](https://github.com/magicuidesign/magicui/blob/main/example/text-reveal-demo.tsx): Example usage+- [Dia Text Reveal Demo](https://github.com/magicuidesign/magicui/blob/main/example/dia-text-reveal-demo.tsx): Example usage+- [Dia Text Reveal Demo 2](https://github.com/magicuidesign/magicui/blob/main/example/dia-text-reveal-demo-2.tsx): Example usage+- [Dia Text Reveal Demo 3](https://github.com/magicuidesign/magicui/blob/main/example/dia-text-reveal-demo-3.tsx): Example usage+- [Dia Text Reveal Demo 4](https://github.com/magicuidesign/magicui/blob/main/example/dia-text-reveal-demo-4.tsx): Example usage- [Animated Gradient Text Demo](https://github.com/magicuidesign/magicui/blob/main/example/animated-gradient-text-demo.tsx): Example usage- [Animated Gradient Text Demo 2](https://github.com/magicuidesign/magicui/blob/main/example/animated-gradient-text-demo-2.tsx): Example usage- [Orbiting Circles Demo](https://github.com/magicuidesign/magicui/blob/main/example/orbiting-circles-demo.tsx): Example usagediff --git a/apps/www/public/r/dia-text-reveal-demo-2.json b/apps/www/public/r/dia-text-reveal-demo-2.jsonnew file mode 100644index 00000000..85aaa546--- /dev/null+++ b/apps/www/public/r/dia-text-reveal-demo-2.json@@ -0,0 +1,17 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "dia-text-reveal-demo-2",+ "type": "registry:example",+ "title": "Dia Text Reveal Demo 2",+ "description": "Custom gradient colors and settled text color on a light background.",+ "registryDependencies": [+ "@magicui/dia-text-reveal"+ ],+ "files": [+ {+ "path": "registry/example/dia-text-reveal-demo-2.tsx",+ "content": "import { DiaTextReveal } from \"@/registry/magicui/dia-text-reveal\"\n\nexport default function DiaTextRevealDemo2() {\n return (\n <div className=\"flex min-h-56 items-center justify-center p-8\">\n <DiaTextReveal\n className=\"text-4xl font-bold tracking-tight\"\n colors={[\"#22d3ee\", \"#818cf8\", \"#f472b6\", \"#34d399\"]}\n text=\"Design systems\"\n />\n </div>\n )\n}\n",+ "type": "registry:example"+ }+ ]+}\ No newline at end of filediff --git a/apps/www/public/r/dia-text-reveal-demo-3.json b/apps/www/public/r/dia-text-reveal-demo-3.jsonnew file mode 100644index 00000000..777c738f--- /dev/null+++ b/apps/www/public/r/dia-text-reveal-demo-3.json@@ -0,0 +1,17 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "dia-text-reveal-demo-3",+ "type": "registry:example",+ "title": "Dia Text Reveal Demo 3",+ "description": "Rotating phrases with repeat and repeat delay.",+ "registryDependencies": [+ "@magicui/dia-text-reveal"+ ],+ "files": [+ {+ "path": "registry/example/dia-text-reveal-demo-3.tsx",+ "content": "import { DiaTextReveal } from \"@/registry/magicui/dia-text-reveal\"\n\nexport default function DiaTextRevealDemo3() {\n return (\n <div className=\"text-foreground flex min-h-64 items-center justify-center p-8\">\n <h1 className=\"text-center text-3xl font-semibold tracking-tight md:text-4xl\">\n Learn to{\" \"}\n <DiaTextReveal\n repeat\n repeatDelay={1.2}\n text={[\"build faster\", \"ship smarter\", \"scale easier\"]}\n />\n </h1>\n </div>\n )\n}\n",+ "type": "registry:example"+ }+ ]+}\ No newline at end of filediff --git a/apps/www/public/r/dia-text-reveal-demo-4.json b/apps/www/public/r/dia-text-reveal-demo-4.jsonnew file mode 100644index 00000000..87cec403--- /dev/null+++ b/apps/www/public/r/dia-text-reveal-demo-4.json@@ -0,0 +1,17 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "dia-text-reveal-demo-4",+ "type": "registry:example",+ "title": "Dia Text Reveal Demo 4",+ "description": "Slower sweep with delay — custom duration and timing.",+ "registryDependencies": [+ "@magicui/dia-text-reveal"+ ],+ "files": [+ {+ "path": "registry/example/dia-text-reveal-demo-4.tsx",+ "content": "import { DiaTextReveal } from \"@/registry/magicui/dia-text-reveal\"\n\nexport default function DiaTextRevealDemo4() {\n return (\n <div className=\"flex min-h-56 items-center justify-center p-8\">\n <DiaTextReveal\n className=\"text-4xl font-bold tracking-tight\"\n colors={[\"#f97316\", \"#eab308\", \"#22c55e\", \"#3b82f6\", \"#a855f7\"]}\n delay={0.35}\n duration={2.4}\n text=\"Made with care\"\n />\n </div>\n )\n}\n",+ "type": "registry:example"+ }+ ]+}\ No newline at end of filediff --git a/apps/www/public/r/dia-text-reveal-demo.json b/apps/www/public/r/dia-text-reveal-demo.jsonnew file mode 100644index 00000000..b05cbdf1--- /dev/null+++ b/apps/www/public/r/dia-text-reveal-demo.json@@ -0,0 +1,17 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "dia-text-reveal-demo",+ "type": "registry:example",+ "title": "Dia Text Reveal Demo",+ "description": "Example showing a sweeping color band reveal on headline text.",+ "registryDependencies": [+ "@magicui/dia-text-reveal"+ ],+ "files": [+ {+ "path": "registry/example/dia-text-reveal-demo.tsx",+ "content": "import { DiaTextReveal } from \"@/registry/magicui/dia-text-reveal\"\n\nexport default function DiaTextRevealDemo() {\n return (\n <div className=\"flex min-h-64 items-center justify-center p-8\">\n <DiaTextReveal\n className=\"text-4xl font-bold tracking-tight\"\n text=\"Magic UI\"\n colors={[\"#A97CF8\", \"#F38CB8\", \"#FDCC92\"]}\n />\n </div>\n )\n}\n",+ "type": "registry:example"+ }+ ]+}\ No newline at end of filediff --git a/apps/www/public/r/dia-text-reveal.json b/apps/www/public/r/dia-text-reveal.jsonnew file mode 100644index 00000000..2ddfe224--- /dev/null+++ b/apps/www/public/r/dia-text-reveal.json@@ -0,0 +1,17 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "dia-text-reveal",+ "type": "registry:ui",+ "title": "Dia Text Reveal",+ "description": "A horizontal color band sweeps across text, revealing a gradient shine before settling on the base color.",+ "dependencies": [+ "motion"+ ],+ "files": [+ {+ "path": "registry/magicui/dia-text-reveal.tsx",+ "content": "\"use client\"\n\nimport { useEffect, useRef, useState } from \"react\"\nimport {\n animate,\n motion,\n useInView,\n useMotionValue,\n useReducedMotion,\n useTransform,\n type HTMLMotionProps,\n} from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\nconst DEFAULT_COLORS = [\"#c679c4\", \"#fa3d1d\", \"#ffb005\", \"#e1e1fe\", \"#0358f7\"]\nconst BAND_HALF = 17\nconst SWEEP_START = -BAND_HALF\nconst SWEEP_END = 100 + BAND_HALF\n\nconst sweepEase = (t: number) =>\n t < 0.5 ? 4 * t ** 3 : 1 - (-2 * t + 2) ** 3 / 2\n\nfunction buildGradient(pos: number, colors: string[], textColor: string) {\n const bandStart = pos - BAND_HALF\n const bandEnd = pos + BAND_HALF\n\n if (bandStart >= 100) {\n return `linear-gradient(90deg, ${textColor}, ${textColor})`\n }\n const n = colors.length\n const parts: string[] = []\n\n if (bandStart > 0)\n parts.push(`${textColor} 0%`, `${textColor} ${bandStart.toFixed(2)}%`)\n\n colors.forEach((c, i) => {\n const pct = n === 1 ? pos : bandStart + (i / (n - 1)) * BAND_HALF * 2\n parts.push(`${c} ${pct.toFixed(2)}%`)\n })\n\n if (bandEnd < 100)\n parts.push(`transparent ${bandEnd.toFixed(2)}%`, `transparent 100%`)\n\n return `linear-gradient(90deg, ${parts.join(\", \")})`\n}\n\nfunction measureWidths(el: HTMLElement, texts: string[]) {\n const ghost = el.cloneNode() as HTMLElement\n Object.assign(ghost.style, {\n position: \"absolute\",\n visibility: \"hidden\",\n pointerEvents: \"none\",\n width: \"auto\",\n whiteSpace: \"nowrap\",\n })\n el.parentElement!.appendChild(ghost)\n const widths = texts.map((t) => {\n ghost.textContent = t\n return ghost.getBoundingClientRect().width\n })\n ghost.remove()\n return widths\n}\n\n/**\n * Props for {@link DiaTextReveal}.\n */\nexport interface DiaTextRevealProps extends Omit<\n HTMLMotionProps<\"span\">,\n \"ref\" | \"children\" | \"style\" | \"animate\" | \"transition\" | \"color\"\n> {\n /**\n * Text to reveal. Pass multiple strings to rotate when {@link DiaTextRevealProps.repeat} is `true`.\n */\n text: string | string[]\n /**\n * Colors sampled across the moving gradient band. Defaults to a built-in palette.\n */\n colors?: string[]\n /**\n * CSS color for revealed text after the sweep and for leading/trailing regions during the animation.\n * @defaultValue `\"var(--foreground)\"`\n */\n textColor?: string\n /**\n * Duration of one sweep pass, in seconds.\n * @defaultValue `1.5`\n */\n duration?: number\n /**\n * Delay before the sweep starts, in seconds.\n * @defaultValue `0`\n */\n delay?: number\n /**\n * When `text` is an array, replay the sweep and advance to the next string after each completion.\n * @defaultValue `false`\n */\n repeat?: boolean\n /**\n * Pause between cycles when {@link DiaTextRevealProps.repeat} is `true`, in seconds.\n * @defaultValue `0.5`\n */\n repeatDelay?: number\n /**\n * If `true`, the animation starts only after the element enters the viewport.\n * @defaultValue `true`\n */\n startOnView?: boolean\n /**\n * Passed to `useInView`: if `true`, in-view detection fires at most once (no replay on scroll-back).\n * @defaultValue `true`\n */\n once?: boolean\n /**\n * Additional class names for the animated `span` (e.g. typography utilities).\n */\n className?: string\n /**\n * When `text` has multiple entries, use the widest string’s width for layout instead of animating width per line.\n * @defaultValue `false`\n */\n fixedWidth?: boolean\n}\n\nexport function DiaTextReveal({\n text,\n colors = DEFAULT_COLORS,\n textColor = \"var(--foreground)\",\n duration = 1.5,\n delay = 0,\n repeat = false,\n repeatDelay = 0.5,\n startOnView = true,\n once = true,\n className,\n fixedWidth = false,\n ...props\n}: DiaTextRevealProps) {\n const texts = Array.isArray(text) ? text : [text]\n const isMulti = texts.length > 1\n const prefersReducedMotion = useReducedMotion()\n\n const spanRef = useRef<HTMLSpanElement>(null)\n const optsRef = useRef({\n colors,\n textColor,\n duration,\n delay,\n repeat,\n repeatDelay,\n texts,\n })\n optsRef.current = {\n colors,\n textColor,\n duration,\n delay,\n repeat,\n repeatDelay,\n texts,\n }\n\n const indexRef = useRef(0)\n const hasPlayedRef = useRef(false)\n const timerRef = useRef<ReturnType<typeof setTimeout>>(undefined)\n const playRef = useRef<() => void>(null!)\n const stopRef = useRef<(() => void) | null>(null)\n\n const [activeIndex, setActiveIndex] = useState(0)\n const [measuredWidths, setMeasuredWidths] = useState<number[]>([])\n\n const sweepPos = useMotionValue(SWEEP_START)\n\n const backgroundImage = useTransform(sweepPos, (pos) =>\n buildGradient(pos, optsRef.current.colors, optsRef.current.textColor)\n )\n\n const isInView = useInView(spanRef, { once, amount: 0.1 })\n\n useEffect(() => {\n const el = spanRef.current\n if (!el || !isMulti) return\n setMeasuredWidths(measureWidths(el, texts))\n }, [Array.isArray(text) ? text.join(\"\\0\") : text])\n\n playRef.current = () => {\n const { duration, delay, repeat, repeatDelay, texts } = optsRef.current\n\n sweepPos.set(SWEEP_START)\n\n const controls = animate(sweepPos, SWEEP_END, {\n duration,\n delay,\n ease: sweepEase,\n onComplete() {\n if (!repeat) return\n timerRef.current = setTimeout(() => {\n const next = (indexRef.current + 1) % texts.length\n indexRef.current = next\n setActiveIndex(next)\n playRef.current()\n }, repeatDelay * 1000)\n },\n })\n\n stopRef.current = () => controls.stop()\n }\n\n useEffect(() => {\n if (prefersReducedMotion) {\n sweepPos.set(SWEEP_END)\n return\n }\n if (startOnView && !isInView) return\n if (once && hasPlayedRef.current) return\n hasPlayedRef.current = true\n playRef.current()\n\n return () => {\n stopRef.current?.()\n clearTimeout(timerRef.current)\n }\n }, [isInView, startOnView, once, prefersReducedMotion, sweepPos])\n\n const fixedW =\n isMulti && fixedWidth && measuredWidths.length > 0\n ? Math.max(...measuredWidths)\n : undefined\n\n const animatedW =\n isMulti && !fixedWidth && measuredWidths[activeIndex] != null\n ? measuredWidths[activeIndex]\n : undefined\n\n return (\n <motion.span\n ref={spanRef}\n className={cn(\"align-bottom leading-[100%] text-inherit\", className)}\n style={{\n transform: \"translateY(-2px)\",\n color: \"transparent\",\n backgroundClip: \"text\",\n WebkitBackgroundClip: \"text\",\n backgroundSize: \"100% 100%\",\n backgroundImage,\n ...(isMulti && {\n display: \"inline-block\",\n overflow: \"hidden\",\n whiteSpace: \"nowrap\",\n verticalAlign: \"text-center\",\n ...(fixedW != null && { width: fixedW }),\n }),\n }}\n animate={animatedW != null ? { width: animatedW } : undefined}\n transition={{ duration: 0.4, ease: [0.4, 0, 0.2, 1] }}\n {...props}\n >\n {texts[activeIndex]}\n </motion.span>\n )\n}\n",+ "type": "registry:ui"+ }+ ]+}\ No newline at end of filediff --git a/apps/www/public/r/registry.json b/apps/www/public/r/registry.jsonindex 88697286..c6b1a0d6 100644--- a/apps/www/public/r/registry.json+++ b/apps/www/public/r/registry.json@@ -709,6 +709,21 @@}]},+ {+ "name": "dia-text-reveal",+ "type": "registry:ui",+ "title": "Dia Text Reveal",+ "description": "A horizontal color band sweeps across text, revealing a gradient shine before settling on the base color.",+ "dependencies": [+ "motion"+ ],+ "files": [+ {+ "path": "registry/magicui/dia-text-reveal.tsx",+ "type": "registry:ui"+ }+ ]+ },{"name": "hyper-text","type": "registry:ui",@@ -2493,6 +2508,66 @@}]},+ {+ "name": "dia-text-reveal-demo",+ "type": "registry:example",+ "title": "Dia Text Reveal Demo",+ "description": "Example showing a sweeping color band reveal on headline text.",+ "registryDependencies": [+ "@magicui/dia-text-reveal"+ ],+ "files": [+ {+ "path": "registry/example/dia-text-reveal-demo.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "dia-text-reveal-demo-2",+ "type": "registry:example",+ "title": "Dia Text Reveal Demo 2",+ "description": "Custom gradient colors and settled text color on a light background.",+ "registryDependencies": [+ "@magicui/dia-text-reveal"+ ],+ "files": [+ {+ "path": "registry/example/dia-text-reveal-demo-2.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "dia-text-reveal-demo-3",+ "type": "registry:example",+ "title": "Dia Text Reveal Demo 3",+ "description": "Rotating phrases with repeat and repeat delay.",+ "registryDependencies": [+ "@magicui/dia-text-reveal"+ ],+ "files": [+ {+ "path": "registry/example/dia-text-reveal-demo-3.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "dia-text-reveal-demo-4",+ "type": "registry:example",+ "title": "Dia Text Reveal Demo 4",+ "description": "Slower sweep with delay — custom duration and timing.",+ "registryDependencies": [+ "@magicui/dia-text-reveal"+ ],+ "files": [+ {+ "path": "registry/example/dia-text-reveal-demo-4.tsx",+ "type": "registry:example"+ }+ ]+ },{"name": "animated-gradient-text-demo","type": "registry:example",diff --git a/apps/www/public/registry.json b/apps/www/public/registry.jsonindex 88697286..c6b1a0d6 100644--- a/apps/www/public/registry.json+++ b/apps/www/public/registry.json@@ -709,6 +709,21 @@}]},+ {+ "name": "dia-text-reveal",+ "type": "registry:ui",+ "title": "Dia Text Reveal",+ "description": "A horizontal color band sweeps across text, revealing a gradient shine before settling on the base color.",+ "dependencies": [+ "motion"+ ],+ "files": [+ {+ "path": "registry/magicui/dia-text-reveal.tsx",+ "type": "registry:ui"+ }+ ]+ },{"name": "hyper-text","type": "registry:ui",@@ -2493,6 +2508,66 @@}]},+ {+ "name": "dia-text-reveal-demo",+ "type": "registry:example",+ "title": "Dia Text Reveal Demo",+ "description": "Example showing a sweeping color band reveal on headline text.",+ "registryDependencies": [+ "@magicui/dia-text-reveal"+ ],+ "files": [+ {+ "path": "registry/example/dia-text-reveal-demo.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "dia-text-reveal-demo-2",+ "type": "registry:example",+ "title": "Dia Text Reveal Demo 2",+ "description": "Custom gradient colors and settled text color on a light background.",+ "registryDependencies": [+ "@magicui/dia-text-reveal"+ ],+ "files": [+ {+ "path": "registry/example/dia-text-reveal-demo-2.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "dia-text-reveal-demo-3",+ "type": "registry:example",+ "title": "Dia Text Reveal Demo 3",+ "description": "Rotating phrases with repeat and repeat delay.",+ "registryDependencies": [+ "@magicui/dia-text-reveal"+ ],+ "files": [+ {+ "path": "registry/example/dia-text-reveal-demo-3.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "dia-text-reveal-demo-4",+ "type": "registry:example",+ "title": "Dia Text Reveal Demo 4",+ "description": "Slower sweep with delay — custom duration and timing.",+ "registryDependencies": [+ "@magicui/dia-text-reveal"+ ],+ "files": [+ {+ "path": "registry/example/dia-text-reveal-demo-4.tsx",+ "type": "registry:example"+ }+ ]+ },{"name": "animated-gradient-text-demo","type": "registry:example",diff --git a/apps/www/registry.json b/apps/www/registry.jsonindex 88697286..c6b1a0d6 100644--- a/apps/www/registry.json+++ b/apps/www/registry.json@@ -709,6 +709,21 @@}]},+ {+ "name": "dia-text-reveal",+ "type": "registry:ui",+ "title": "Dia Text Reveal",+ "description": "A horizontal color band sweeps across text, revealing a gradient shine before settling on the base color.",+ "dependencies": [+ "motion"+ ],+ "files": [+ {+ "path": "registry/magicui/dia-text-reveal.tsx",+ "type": "registry:ui"+ }+ ]+ },{"name": "hyper-text","type": "registry:ui",@@ -2493,6 +2508,66 @@}]},+ {+ "name": "dia-text-reveal-demo",+ "type": "registry:example",+ "title": "Dia Text Reveal Demo",+ "description": "Example showing a sweeping color band reveal on headline text.",+ "registryDependencies": [+ "@magicui/dia-text-reveal"+ ],+ "files": [+ {+ "path": "registry/example/dia-text-reveal-demo.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "dia-text-reveal-demo-2",+ "type": "registry:example",+ "title": "Dia Text Reveal Demo 2",+ "description": "Custom gradient colors and settled text color on a light background.",+ "registryDependencies": [+ "@magicui/dia-text-reveal"+ ],+ "files": [+ {+ "path": "registry/example/dia-text-reveal-demo-2.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "dia-text-reveal-demo-3",+ "type": "registry:example",+ "title": "Dia Text Reveal Demo 3",+ "description": "Rotating phrases with repeat and repeat delay.",+ "registryDependencies": [+ "@magicui/dia-text-reveal"+ ],+ "files": [+ {+ "path": "registry/example/dia-text-reveal-demo-3.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "dia-text-reveal-demo-4",+ "type": "registry:example",+ "title": "Dia Text Reveal Demo 4",+ "description": "Slower sweep with delay — custom duration and timing.",+ "registryDependencies": [+ "@magicui/dia-text-reveal"+ ],+ "files": [+ {+ "path": "registry/example/dia-text-reveal-demo-4.tsx",+ "type": "registry:example"+ }+ ]+ },{"name": "animated-gradient-text-demo","type": "registry:example",diff --git a/apps/www/registry/__index__.tsx b/apps/www/registry/__index__.tsxindex 436ad97f..b57947f6 100644--- a/apps/www/registry/__index__.tsx+++ b/apps/www/registry/__index__.tsx@@ -678,6 +678,23 @@ export const Index: Record<string, any> = {}),meta: undefined,},+ "dia-text-reveal": {+ name: "dia-text-reveal",+ description: "A horizontal color band sweeps across text, revealing a gradient shine before settling on the base color.",+ type: "registry:ui",+ registryDependencies: undefined,+ files: [{+ path: "registry/magicui/dia-text-reveal.tsx",+ type: "registry:ui",+ target: ""+ }],+ component: React.lazy(async () => {+ const mod = await import("@/registry/magicui/dia-text-reveal.tsx")+ const exportName = Object.keys(mod).find(key => typeof mod[key] === 'function' || typeof mod[key] === 'object') ?? item.name+ return { default: mod.default ?? mod[exportName] }+ }),+ meta: undefined,+ },"hyper-text": {name: "hyper-text",description: "A text animation that scrambles letters before revealing the final text.",@@ -2548,6 +2565,74 @@ export const Index: Record<string, any> = {}),meta: undefined,},+ "dia-text-reveal-demo": {+ name: "dia-text-reveal-demo",+ description: "Example showing a sweeping color band reveal on headline text.",+ type: "registry:example",+ registryDependencies: ["@magicui/dia-text-reveal"],+ files: [{+ path: "registry/example/dia-text-reveal-demo.tsx",+ type: "registry:example",+ target: ""+ }],+ component: React.lazy(async () => {+ const mod = await import("@/registry/example/dia-text-reveal-demo.tsx")+ const exportName = Object.keys(mod).find(key => typeof mod[key] === 'function' || typeof mod[key] === 'object') ?? item.name+ return { default: mod.default ?? mod[exportName] }+ }),+ meta: undefined,+ },+ "dia-text-reveal-demo-2": {+ name: "dia-text-reveal-demo-2",+ description: "Custom gradient colors and settled text color on a light background.",+ type: "registry:example",+ registryDependencies: ["@magicui/dia-text-reveal"],+ files: [{+ path: "registry/example/dia-text-reveal-demo-2.tsx",+ type: "registry:example",+ target: ""+ }],+ component: React.lazy(async () => {+ const mod = await import("@/registry/example/dia-text-reveal-demo-2.tsx")+ const exportName = Object.keys(mod).find(key => typeof mod[key] === 'function' || typeof mod[key] === 'object') ?? item.name+ return { default: mod.default ?? mod[exportName] }+ }),+ meta: undefined,+ },+ "dia-text-reveal-demo-3": {+ name: "dia-text-reveal-demo-3",+ description: "Rotating phrases with repeat and repeat delay.",+ type: "registry:example",+ registryDependencies: ["@magicui/dia-text-reveal"],+ files: [{+ path: "registry/example/dia-text-reveal-demo-3.tsx",+ type: "registry:example",+ target: ""+ }],+ component: React.lazy(async () => {+ const mod = await import("@/registry/example/dia-text-reveal-demo-3.tsx")+ const exportName = Object.keys(mod).find(key => typeof mod[key] === 'function' || typeof mod[key] === 'object') ?? item.name+ return { default: mod.default ?? mod[exportName] }+ }),+ meta: undefined,+ },+ "dia-text-reveal-demo-4": {+ name: "dia-text-reveal-demo-4",+ description: "Slower sweep with delay — custom duration and timing.",+ type: "registry:example",+ registryDependencies: ["@magicui/dia-text-reveal"],+ files: [{+ path: "registry/example/dia-text-reveal-demo-4.tsx",+ type: "registry:example",+ target: ""+ }],+ component: React.lazy(async () => {+ const mod = await import("@/registry/example/dia-text-reveal-demo-4.tsx")+ const exportName = Object.keys(mod).find(key => typeof mod[key] === 'function' || typeof mod[key] === 'object') ?? item.name+ return { default: mod.default ?? mod[exportName] }+ }),+ meta: undefined,+ },"animated-gradient-text-demo": {name: "animated-gradient-text-demo",description: "Example showing text with animated gradient backgrounds.",diff --git a/apps/www/registry/example/dia-text-reveal-demo-2.tsx b/apps/www/registry/example/dia-text-reveal-demo-2.tsxnew file mode 100644index 00000000..1bb014f6--- /dev/null+++ b/apps/www/registry/example/dia-text-reveal-demo-2.tsx@@ -0,0 +1,13 @@+import { DiaTextReveal } from "@/registry/magicui/dia-text-reveal"++export default function DiaTextRevealDemo2() {+ return (+ <div className="flex min-h-56 items-center justify-center p-8">+ <DiaTextReveal+ className="text-4xl font-bold tracking-tight"+ colors={["#22d3ee", "#818cf8", "#f472b6", "#34d399"]}+ text="Design systems"+ />+ </div>+ )+}diff --git a/apps/www/registry/example/dia-text-reveal-demo-3.tsx b/apps/www/registry/example/dia-text-reveal-demo-3.tsxnew file mode 100644index 00000000..23ea3dab--- /dev/null+++ b/apps/www/registry/example/dia-text-reveal-demo-3.tsx@@ -0,0 +1,16 @@+import { DiaTextReveal } from "@/registry/magicui/dia-text-reveal"++export default function DiaTextRevealDemo3() {+ return (+ <div className="text-foreground flex min-h-64 items-center justify-center p-8">+ <h1 className="text-center text-3xl font-semibold tracking-tight md:text-4xl">+ Learn to{" "}+ <DiaTextReveal+ repeat+ repeatDelay={1.2}+ text={["build faster", "ship smarter", "scale easier"]}+ />+ </h1>+ </div>+ )+}diff --git a/apps/www/registry/example/dia-text-reveal-demo-4.tsx b/apps/www/registry/example/dia-text-reveal-demo-4.tsxnew file mode 100644index 00000000..e0c9a3f8--- /dev/null+++ b/apps/www/registry/example/dia-text-reveal-demo-4.tsx@@ -0,0 +1,15 @@+import { DiaTextReveal } from "@/registry/magicui/dia-text-reveal"++export default function DiaTextRevealDemo4() {+ return (+ <div className="flex min-h-56 items-center justify-center p-8">+ <DiaTextReveal+ className="text-4xl font-bold tracking-tight"+ colors={["#f97316", "#eab308", "#22c55e", "#3b82f6", "#a855f7"]}+ delay={0.35}+ duration={2.4}+ text="Made with care"+ />+ </div>+ )+}diff --git a/apps/www/registry/example/dia-text-reveal-demo.tsx b/apps/www/registry/example/dia-text-reveal-demo.tsxnew file mode 100644index 00000000..6ac245fa--- /dev/null+++ b/apps/www/registry/example/dia-text-reveal-demo.tsx@@ -0,0 +1,13 @@+import { DiaTextReveal } from "@/registry/magicui/dia-text-reveal"++export default function DiaTextRevealDemo() {+ return (+ <div className="flex min-h-64 items-center justify-center p-8">+ <DiaTextReveal+ className="text-4xl font-bold tracking-tight"+ text="Magic UI"+ colors={["#A97CF8", "#F38CB8", "#FDCC92"]}+ />+ </div>+ )+}diff --git a/apps/www/registry/magicui/dia-text-reveal.tsx b/apps/www/registry/magicui/dia-text-reveal.tsxnew file mode 100644index 00000000..8f9d7544--- /dev/null+++ b/apps/www/registry/magicui/dia-text-reveal.tsx@@ -0,0 +1,263 @@+"use client"++import { useEffect, useRef, useState } from "react"+import {+ animate,+ motion,+ useInView,+ useMotionValue,+ useReducedMotion,+ useTransform,+ type HTMLMotionProps,+} from "motion/react"++import { cn } from "@/lib/utils"++const DEFAULT_COLORS = ["#c679c4", "#fa3d1d", "#ffb005", "#e1e1fe", "#0358f7"]+const BAND_HALF = 17+const SWEEP_START = -BAND_HALF+const SWEEP_END = 100 + BAND_HALF++const sweepEase = (t: number) =>+ t < 0.5 ? 4 * t ** 3 : 1 - (-2 * t + 2) ** 3 / 2++function buildGradient(pos: number, colors: string[], textColor: string) {+ const bandStart = pos - BAND_HALF+ const bandEnd = pos + BAND_HALF++ if (bandStart >= 100) {+ return `linear-gradient(90deg, ${textColor}, ${textColor})`+ }+ const n = colors.length+ const parts: string[] = []++ if (bandStart > 0)+ parts.push(`${textColor} 0%`, `${textColor} ${bandStart.toFixed(2)}%`)++ colors.forEach((c, i) => {+ const pct = n === 1 ? pos : bandStart + (i / (n - 1)) * BAND_HALF * 2+ parts.push(`${c} ${pct.toFixed(2)}%`)+ })++ if (bandEnd < 100)+ parts.push(`transparent ${bandEnd.toFixed(2)}%`, `transparent 100%`)++ return `linear-gradient(90deg, ${parts.join(", ")})`+}++function measureWidths(el: HTMLElement, texts: string[]) {+ const ghost = el.cloneNode() as HTMLElement+ Object.assign(ghost.style, {+ position: "absolute",+ visibility: "hidden",+ pointerEvents: "none",+ width: "auto",+ whiteSpace: "nowrap",+ })+ el.parentElement!.appendChild(ghost)+ const widths = texts.map((t) => {+ ghost.textContent = t+ return ghost.getBoundingClientRect().width+ })+ ghost.remove()+ return widths+}++/**+ * Props for {@link DiaTextReveal}.+ */+export interface DiaTextRevealProps extends Omit<+ HTMLMotionProps<"span">,+ "ref" | "children" | "style" | "animate" | "transition" | "color"+> {+ /**+ * Text to reveal. Pass multiple strings to rotate when {@link DiaTextRevealProps.repeat} is `true`.+ */+ text: string | string[]+ /**+ * Colors sampled across the moving gradient band. Defaults to a built-in palette.+ */+ colors?: string[]+ /**+ * CSS color for revealed text after the sweep and for leading/trailing regions during the animation.+ * @defaultValue `"var(--foreground)"`+ */+ textColor?: string+ /**+ * Duration of one sweep pass, in seconds.+ * @defaultValue `1.5`+ */+ duration?: number+ /**+ * Delay before the sweep starts, in seconds.+ * @defaultValue `0`+ */+ delay?: number+ /**+ * When `text` is an array, replay the sweep and advance to the next string after each completion.+ * @defaultValue `false`+ */+ repeat?: boolean+ /**+ * Pause between cycles when {@link DiaTextRevealProps.repeat} is `true`, in seconds.+ * @defaultValue `0.5`+ */+ repeatDelay?: number+ /**+ * If `true`, the animation starts only after the element enters the viewport.+ * @defaultValue `true`+ */+ startOnView?: boolean+ /**+ * Passed to `useInView`: if `true`, in-view detection fires at most once (no replay on scroll-back).+ * @defaultValue `true`+ */+ once?: boolean+ /**+ * Additional class names for the animated `span` (e.g. typography utilities).+ */+ className?: string+ /**+ * When `text` has multiple entries, use the widest string’s width for layout instead of animating width per line.+ * @defaultValue `false`+ */+ fixedWidth?: boolean+}++export function DiaTextReveal({+ text,+ colors = DEFAULT_COLORS,+ textColor = "var(--foreground)",+ duration = 1.5,+ delay = 0,+ repeat = false,+ repeatDelay = 0.5,+ startOnView = true,+ once = true,+ className,+ fixedWidth = false,+ ...props+}: DiaTextRevealProps) {+ const texts = Array.isArray(text) ? text : [text]+ const isMulti = texts.length > 1+ const prefersReducedMotion = useReducedMotion()++ const spanRef = useRef<HTMLSpanElement>(null)+ const optsRef = useRef({+ colors,+ textColor,+ duration,+ delay,+ repeat,+ repeatDelay,+ texts,+ })+ optsRef.current = {+ colors,+ textColor,+ duration,+ delay,+ repeat,+ repeatDelay,+ texts,+ }++ const indexRef = useRef(0)+ const hasPlayedRef = useRef(false)+ const timerRef = useRef<ReturnType<typeof setTimeout>>(undefined)+ const playRef = useRef<() => void>(null!)+ const stopRef = useRef<(() => void) | null>(null)++ const [activeIndex, setActiveIndex] = useState(0)+ const [measuredWidths, setMeasuredWidths] = useState<number[]>([])++ const sweepPos = useMotionValue(SWEEP_START)++ const backgroundImage = useTransform(sweepPos, (pos) =>+ buildGradient(pos, optsRef.current.colors, optsRef.current.textColor)+ )++ const isInView = useInView(spanRef, { once, amount: 0.1 })++ useEffect(() => {+ const el = spanRef.current+ if (!el || !isMulti) return+ setMeasuredWidths(measureWidths(el, texts))+ }, [Array.isArray(text) ? text.join("\0") : text])++ playRef.current = () => {+ const { duration, delay, repeat, repeatDelay, texts } = optsRef.current++ sweepPos.set(SWEEP_START)++ const controls = animate(sweepPos, SWEEP_END, {+ duration,+ delay,+ ease: sweepEase,+ onComplete() {+ if (!repeat) return+ timerRef.current = setTimeout(() => {+ const next = (indexRef.current + 1) % texts.length+ indexRef.current = next+ setActiveIndex(next)+ playRef.current()+ }, repeatDelay * 1000)+ },+ })++ stopRef.current = () => controls.stop()+ }++ useEffect(() => {+ if (prefersReducedMotion) {+ sweepPos.set(SWEEP_END)+ return+ }+ if (startOnView && !isInView) return+ if (once && hasPlayedRef.current) return+ hasPlayedRef.current = true+ playRef.current()++ return () => {+ stopRef.current?.()+ clearTimeout(timerRef.current)+ }+ }, [isInView, startOnView, once, prefersReducedMotion, sweepPos])++ const fixedW =+ isMulti && fixedWidth && measuredWidths.length > 0+ ? Math.max(...measuredWidths)+ : undefined++ const animatedW =+ isMulti && !fixedWidth && measuredWidths[activeIndex] != null+ ? measuredWidths[activeIndex]+ : undefined++ return (+ <motion.span+ ref={spanRef}+ className={cn("align-bottom leading-[100%] text-inherit", className)}+ style={{+ transform: "translateY(-2px)",+ color: "transparent",+ backgroundClip: "text",+ WebkitBackgroundClip: "text",+ backgroundSize: "100% 100%",+ backgroundImage,+ ...(isMulti && {+ display: "inline-block",+ overflow: "hidden",+ whiteSpace: "nowrap",+ verticalAlign: "text-center",+ ...(fixedW != null && { width: fixedW }),+ }),+ }}+ animate={animatedW != null ? { width: animatedW } : undefined}+ transition={{ duration: 0.4, ease: [0.4, 0, 0.2, 1] }}+ {...props}+ >+ {texts[activeIndex]}+ </motion.span>+ )+}diff --git a/apps/www/registry/registry-examples.ts b/apps/www/registry/registry-examples.tsindex 01fae25a..8a741ee3 100644--- a/apps/www/registry/registry-examples.ts+++ b/apps/www/registry/registry-examples.ts@@ -1019,6 +1019,60 @@ export const examples: Registry["items"] = [},],},+ {+ name: "dia-text-reveal-demo",+ type: "registry:example",+ title: "Dia Text Reveal Demo",+ description:+ "Example showing a sweeping color band reveal on headline text.",+ registryDependencies: ["@magicui/dia-text-reveal"],+ files: [+ {+ path: "example/dia-text-reveal-demo.tsx",+ type: "registry:example",+ },+ ],+ },+ {+ name: "dia-text-reveal-demo-2",+ type: "registry:example",+ title: "Dia Text Reveal Demo 2",+ description:+ "Custom gradient colors and settled text color on a light background.",+ registryDependencies: ["@magicui/dia-text-reveal"],+ files: [+ {+ path: "example/dia-text-reveal-demo-2.tsx",+ type: "registry:example",+ },+ ],+ },+ {+ name: "dia-text-reveal-demo-3",+ type: "registry:example",+ title: "Dia Text Reveal Demo 3",+ description: "Rotating phrases with repeat and repeat delay.",+ registryDependencies: ["@magicui/dia-text-reveal"],+ files: [+ {+ path: "example/dia-text-reveal-demo-3.tsx",+ type: "registry:example",+ },+ ],+ },+ {+ name: "dia-text-reveal-demo-4",+ type: "registry:example",+ title: "Dia Text Reveal Demo 4",+ description: "Slower sweep with delay — custom duration and timing.",+ registryDependencies: ["@magicui/dia-text-reveal"],+ files: [+ {+ path: "example/dia-text-reveal-demo-4.tsx",+ type: "registry:example",+ },+ ],+ },{name: "animated-gradient-text-demo",type: "registry:example",diff --git a/apps/www/registry/registry-ui.ts b/apps/www/registry/registry-ui.tsindex bdf33824..8630416d 100644--- a/apps/www/registry/registry-ui.ts+++ b/apps/www/registry/registry-ui.ts@@ -675,6 +675,20 @@ export const ui: Registry["items"] = [},],},+ {+ name: "dia-text-reveal",+ type: "registry:ui",+ title: "Dia Text Reveal",+ description:+ "A horizontal color band sweeps across text, revealing a gradient shine before settling on the base color.",+ dependencies: ["motion"],+ files: [+ {+ path: "magicui/dia-text-reveal.tsx",+ type: "registry:ui",+ },+ ],+ },{name: "hyper-text",type: "registry:ui",