Overview
Components
Text Animations
Apple-style animated gradient text with wave effect.
motion-sv
Just ship things.
preview.svelte
<script lang="ts"> import { GradientWaveText } from "$lib/components/spell/gradient-wave-text/index.js";</script>
<GradientWaveText once={false} triggerOnView class="text-3xl font-medium tracking-[-.03em] md:text-5xl"> Just ship things.</GradientWaveText>Installation
pnpm dlx shadcn-svelte@latest add https://sv-animations.vercel.app/s/gradient-wave-text.json
Install dependencies
Install the required packages for this component:
pnpm add motion-sv
Copy the Source Code
Copy and paste the following code into your project:
gradient-wave-text.svelte
<script lang="ts"> import { cn } from "#lib/utils.js"; import { useInView } from "motion-sv"; import type { Snippet } from "svelte"; import type { ClassValue, HTMLAttributes } from "svelte/elements";
type Align = "left" | "center" | "right";
const defaultColors = ["#8d6869", "#5a8ea6", "#b9c96e", "#c7c571", "#cb706f", "#7e5e5f"];
interface Props extends HTMLAttributes<HTMLDivElement> { children?: Snippet; align?: Align; class?: ClassValue; speed?: number; paused?: boolean; delay?: number; repeat?: boolean; triggerOnView?: boolean; once?: boolean; radial?: boolean; bottomOffset?: number; bandGap?: number; bandCount?: number; customColors?: string[]; ariaLabel?: string; style?: string; role?: string; }
let { children, align = "center", class: className, speed = 1, paused = false, delay = 0, repeat = false, triggerOnView = false, once = true, radial = true, bottomOffset = 20, bandGap = 4, bandCount = 8, customColors, ariaLabel, style, role, ...props }: Props = $props();
let element = $state<HTMLDivElement | null>(null); let view = useInView( () => (triggerOnView ? element : null)!, () => ({ once, amount: 0.1 }) as any );
let rafId = 0; let gradientIndex = -25; let cyclesDone = 0; let finished = false; let started = false; let startAt = 0;
const cycles = $derived(repeat ? 0 : 1); const resolvedColors = $derived(customColors?.length ? customColors : defaultColors); const isInView = $derived(triggerOnView ? view.current : true); const justifyContent = $derived( align === "left" ? "flex-start" : align === "right" ? "flex-end" : "center" );
const stops = $derived.by(() => { const parts: string[] = []; const baseColor = "var(--gradient-wave-base, rgb(29,29,31))";
parts.push(`${baseColor} calc((var(--gi) + 0) * 1%)`);
for (let index = 0; index < bandCount && index < resolvedColors.length * 2; index += 1) { const color = resolvedColors[index % resolvedColors.length]; const offset = (index + 2) * bandGap; parts.push(`${color} calc((var(--gi) + ${offset}) * 1%)`); }
const endOffset = (bandCount + 2) * bandGap; parts.push(`${baseColor} calc((var(--gi) + ${endOffset}) * 1%)`);
return parts.join(", "); });
const gradient = $derived( radial ? `radial-gradient(circle at 50% bottom, ${stops})` : `linear-gradient(0deg, ${stops})` );
const rootStyle = $derived( [`justify-content: ${justifyContent}`, "--gi: -25", style].filter(Boolean).join("; ") );
const textStyle = $derived( [ `text-align: ${align}`, `background-image: ${gradient}`, "-webkit-background-clip: text", "background-clip: text", "-webkit-text-fill-color: transparent", "color: transparent", "white-space: pre-wrap", "word-break: break-word", "display: inline-block", "-webkit-font-smoothing: antialiased", "-moz-osx-font-smoothing: grayscale", "-webkit-backface-visibility: hidden", "backface-visibility: hidden", "transform: translateZ(0)", `padding-bottom: ${bottomOffset}%`, `margin-bottom: -${bottomOffset}%`, "padding-inline: 2px", ].join("; ") );
function setGradientIndex(value: number) { gradientIndex = value; element?.style.setProperty("--gi", String(value)); }
$effect(() => { if (!element) { return; }
setGradientIndex(-25); });
$effect(() => { if (!element || !isInView) { return; }
gradientIndex = -25; cyclesDone = 0; finished = false; started = false; startAt = performance.now() + Math.max(0, delay * 1000); setGradientIndex(-25); });
$effect(() => { if (!element || !isInView) { return; }
const node = element; const range = 200; let last = performance.now();
const tick = (now: number) => { if (finished || node !== element) { return; }
if (!started) { if (now >= startAt) { started = true; last = now; } else { rafId = requestAnimationFrame(tick); return; } }
const delta = Math.min(64, now - last); last = now;
if (!paused) { const increment = (delta * speed) / 16.6667; let next = gradientIndex + increment;
if (cycles === 0) { if (next >= range) { next %= range; }
setGradientIndex(next); } else { while (next >= range && cyclesDone < cycles) { next -= range; cyclesDone += 1; }
if (cyclesDone >= cycles) { setGradientIndex(range); finished = true; return; }
setGradientIndex(next); } }
rafId = requestAnimationFrame(tick); };
rafId = requestAnimationFrame(tick);
return () => cancelAnimationFrame(rafId); });</script>
<div bind:this={element} class={cn( "flex h-full w-full items-center [--gradient-wave-base:rgb(29,29,31)] dark:[--gradient-wave-base:rgb(255,255,255)]", className )} style={rootStyle} aria-label={ariaLabel} role={role ?? (ariaLabel ? "img" : undefined)} {...props}> <span style={textStyle}> {@render children?.()} </span></div> index.ts
import GradientWaveText from "./gradient-wave-text.svelte";export { GradientWaveText };Folder Structure
Folder Structure
src/└── lib/ └── components/ └── spell/ └── gradient-wave-text/ ├── gradient-wave-text.svelte └── index.tsInstall and integrate the Svelte component documented below.https://sv-animations.vercel.app/spell/gradient-wave-text/llms.txt
Follow the guide's installation and usage instructions.Match the project's existing structure, imports, and styles.Keep changes scoped to the component and verify it works.Reply with a short bullet list of completed changes.Usage
<script lang="ts"> import { GradientWaveText } from "#lib/components/spell/gradient-wave-text/index.js";</script>
<GradientWaveText>Just ship things.</GradientWaveText>Examples
Linear Bands
Signals move in deliberate lines
linear-bands-example.svelte
<script lang="ts"> import { GradientWaveText } from "$lib/components/spell/gradient-wave-text/index.js";
let customColors = ["#2563eb", "#0ea5e9", "#67e8f9", "#e0f2fe"];</script>
<GradientWaveText repeat radial={false} {customColors} class="text-3xl font-medium tracking-[-.03em] md:text-5xl"> Signals move in deliberate lines</GradientWaveText>Props
| Name | Type | Default | Description |
|---|---|---|---|
children | Snippet | required | The text content rendered inside the animated gradient mask. |
align | "left" | "center" | "right" | "center" | Controls content alignment and text alignment for the rendered headline. |
speed | number | 1 | Controls how quickly the gradient index advances through the color bands. |
paused | boolean | false | Pauses gradient movement while keeping the current visual state rendered. |
delay | number | 0 | Adds a delay in seconds before the gradient animation begins. |
repeat | boolean | false | When true, loops the gradient wave indefinitely instead of stopping after one pass. |
triggerOnView | boolean | false | Waits to animate until the component enters the viewport. |
once | boolean | true | When using triggerOnView, controls whether the animation runs only on first entry. |
radial | boolean | true | Uses a radial gradient when true and a linear gradient when false. |
bottomOffset | number | 20 | Controls how much extra bottom padding is applied to preserve the gradient bloom. |
bandGap | number | 4 | Sets the spacing between each gradient color band. |
bandCount | number | 8 | Controls how many color bands are rendered into the gradient. |
customColors | string[] | | Overrides the default gradient palette with a custom color list. |
ariaLabel | string | | Provides an accessible label when the rendered content should be announced as an image-like effect. |
role | string | | Overrides the computed root role if you need explicit semantics. |
class | ClassValue | | Custom classes applied to the root wrapper. |
style | string | | Inline styles merged onto the root wrapper. |