# Integrate `Kinetic` from Motion Garden

You are helping me add the **Kinetic** component to an existing project.
Everything you need is below — full source, dependencies, props and the
behavioural contract. Read it all before writing anything.

- **Component:** Kinetic
- **Category:** Text Animations
- **Summary:** Type with mass: every glyph is its own spring, and the squash and stretch are read back off that spring rather than authored.
- **Reference:** https://motion-garden.netlify.app/components/kinetic
- **Full catalog (for you, the agent):** https://motion-garden.netlify.app/llms.txt

## Stack this source assumes

- React 19 with the Next.js App Router (never the `pages/` directory)
- TypeScript, strict
- Tailwind CSS v4, CSS-first config (utilities are inline; no `tailwind.config` needed)

If my project differs, adapt the integration — but do not rewrite the animation math to suit a different stack. Ask me first.

## Dependencies

```bash
bun add motion clsx tailwind-merge
```

## Files to create

2 files — all of them are required. Paths are as shipped; the component may live anywhere in my project, but keep every peer file at the exact path shown so the import aliases resolve.

### 1. `components/registry/kinetic/kinetic.tsx`

```tsx
"use client";

import { useEffect, useMemo, useState } from "react";
import {
  animate,
  motion,
  useMotionValue,
  useSpring,
  useTransform,
  useVelocity,
} from "motion/react";
import { cn } from "@/lib/utils";

export type KineticSplit = "character" | "word";
export type KineticTrigger = "loop" | "hover";

export interface KineticProps {
  text?: string;
  stiffness?: number;
  damping?: number;
  mass?: number;
  jumpHeight?: number;
  anticipation?: number;
  windUp?: number;
  squash?: number;
  stagger?: number;
  interval?: number;
  trigger?: KineticTrigger;
  split?: KineticSplit;
  shadow?: boolean;
  accentColor?: string;
  paused?: boolean;
  reducedMotion?: boolean;
  className?: string;
}

interface BodyProps {
  text: string;
  index: number;
  halted: boolean;
  cycle: number;
  stiffness: number;
  damping: number;
  mass: number;
  jumpHeight: number;
  anticipation: number;
  windUp: number;
  squash: number;
  stagger: number;
  interval: number;
  repeat: boolean;
  shadow: boolean;
  accentColor: string;
}

const SPEED_REF = 14;
const DEPTH_REF = 0.35;

function Body({
  text,
  index,
  halted,
  cycle,
  stiffness,
  damping,
  mass,
  jumpHeight,
  anticipation,
  windUp,
  squash,
  stagger,
  interval,
  repeat,
  shadow,
  accentColor,
}: BodyProps) {
  const target = useMotionValue(0);
  const y = useSpring(target, { stiffness, damping, mass });
  const velocity = useVelocity(y);

  const speedRef = Math.max(120, jumpHeight * SPEED_REF);
  const depthRef = Math.max(2, jumpHeight * DEPTH_REF);

  const scaleY = useTransform<number, number>(
    [velocity, y],
    ([v, py]: number[]) => {
      const stretch = Math.min(1, Math.abs(v) / speedRef);
      const depth = Math.min(1, Math.max(0, py) / depthRef);
      return 1 + squash * (stretch * 0.75 - depth * 1.05);
    },
  );
  const scaleX = useTransform<number, number>(
    [velocity, y],
    ([v, py]: number[]) => {
      const stretch = Math.min(1, Math.abs(v) / speedRef);
      const depth = Math.min(1, Math.max(0, py) / depthRef);
      return 1 - squash * (stretch * 0.42 - depth * 0.62);
    },
  );

  const lift = useTransform(y, (v: number) => Math.min(0, v));

  const shadowScale = useTransform(y, [-jumpHeight - 1, 0], [0.34, 1], {
    clamp: true,
  });
  const shadowFade = useTransform(y, [-jumpHeight - 1, 0], [0.08, 0.4], {
    clamp: true,
  });

  useEffect(() => {
    if (halted) {
      target.set(0);
      return;
    }
    const rise = 110;
    const fall = 190;
    const wind = anticipation > 0 ? Math.max(16, windUp) : 0;
    const total = wind + rise + fall;

    const controls = animate(
      target,
      wind > 0 ? [0, anticipation, -jumpHeight, 0] : [0, -jumpHeight, 0],
      {
        duration: total / 1000,
        times:
          wind > 0
            ? [0, wind / total, (wind + rise) / total, 1]
            : [0, rise / (rise + fall), 1],
        ease: "linear",
        delay: (index * stagger) / 1000,
        ...(repeat
          ? { repeat: Infinity, repeatDelay: Math.max(0, interval) / 1000 }
          : {}),
      },
    );
    return () => controls.stop();
  }, [
    target,
    halted,
    cycle,
    index,
    jumpHeight,
    anticipation,
    windUp,
    stagger,
    interval,
    repeat,
  ]);

  return (
    <span className="relative inline-block">
      {shadow ? (
        <motion.span
          aria-hidden
          className="pointer-events-none absolute inset-x-[12%] bottom-[-0.16em] h-[0.12em] rounded-[50%] blur-[1.5px]"
          style={{
            backgroundColor: accentColor,
            scaleX: shadowScale,
            opacity: shadowFade,
          }}
        />
      ) : null}
      <motion.span
        className="inline-block origin-bottom whitespace-pre"
        style={{ y: lift, scaleX, scaleY }}
      >
        {text}
      </motion.span>
    </span>
  );
}

export default function Kinetic({
  text = "",
  stiffness = 620,
  damping = 20,
  mass = 1,
  jumpHeight = 26,
  anticipation = 7,
  windUp = 130,
  squash = 0.62,
  stagger = 34,
  interval = 2400,
  trigger = "loop",
  split = "character",
  shadow = true,
  accentColor = "#a855f7",
  paused = false,
  reducedMotion = false,
  className,
}: KineticProps) {
  const halted = paused || reducedMotion;
  const [cycle, setCycle] = useState(0);

  const groups = useMemo(() => {
    const words = text.split(/(\s+)/).filter((part) => part.length > 0);
    let n = 0;
    return words.map((part) => {
      if (/^\s+$/.test(part)) return { space: true, bodies: [] as string[], at: [] as number[] };
      const bodies = split === "word" ? [part] : Array.from(part);
      const at = bodies.map(() => n++);
      return { space: false, bodies, at };
    });
  }, [text, split]);

  const replay = () => {
    if (trigger !== "hover" || halted) return;
    setCycle((n) => n + 1);
  };

  return (
    <div
      className={cn("select-none", className)}
      onPointerEnter={replay}
      onFocus={replay}
      tabIndex={trigger === "hover" ? 0 : undefined}
      onPointerDown={trigger === "hover" ? replay : undefined}
    >
      <span aria-hidden>
        {groups.map((group, gi) =>
          group.space ? (
            <span key={gi}> </span>
          ) : (
            <span key={gi} className="inline-block">
              {group.bodies.map((body, bi) => (
                <Body
                  key={bi}
                  text={body}
                  index={group.at[bi]}
                  halted={halted}
                  cycle={cycle}
                  stiffness={stiffness}
                  damping={damping}
                  mass={mass}
                  jumpHeight={jumpHeight}
                  anticipation={anticipation}
                  windUp={windUp}
                  squash={squash}
                  stagger={stagger}
                  interval={interval}
                  repeat={trigger === "loop"}
                  shadow={shadow}
                  accentColor={accentColor}
                />
              ))}
            </span>
          ),
        )}
      </span>
      <span className="sr-only">{text}</span>
    </div>
  );
}
```

### 2. `lib/utils.ts` — peer util, required

```tsx
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs));
}
```


## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `stiffness` | `number` | `620` | Spring tension. Higher launches harder and settles sooner. Range 60–1400. |
| `damping` | `number` | `20` | Spring friction. Low overshoots and rings; high arrives dead, and takes the follow-through with it. Range 4–60. |
| `mass` | `number` | `1` | Weight of a body. Heavier lags further behind its own intent, which is where the whole effect comes from. Range 0.2–4. |
| `jumpHeight` | `number` | `26` | Peak of the jump. Range 0–90 px. |
| `anticipation` | `number` | `7` | Depth of the wind-up before the launch, in spring travel. Spent as compression rather than as downward movement — the floor is real, and a body loading its spring squats instead of sinking. Range 0–30 px. |
| `windUp` | `number` | `130` | How long the wind-up takes. Range 0–500 ms. Ignored while `anticipation` is `0`. |
| `squash` | `number` | `0.62` | How hard velocity and floor contact deform a body. At 0 the type is rigid and still jumps — which is precisely what weightless motion looks like. Range 0–1.5. |
| `stagger` | `number` | `34` | Delay between one body launching and the next. At 0 the line moves as a slab; the offset is what makes it read as a row of separate objects. Range 0–160 ms. |
| `interval` | `number` | `2400` | Rest between one pass finishing and the next beginning. Range 200–6000 ms. Ignored while `trigger` is `hover`. |
| `trigger` | `"loop" | "hover"` | `"loop"` | What starts a pass. Hover also answers focus and touch — a pointer-only trigger is half a component. |
| `split` | `"character" | "word"` | `"character"` | Whether a body is one glyph or one whole word. |
| `shadow` | `boolean` | `true` | Contact shadow under each body, tightening as it rises. Without it a jump is ambiguous with a slide. |
| `accentColor` | `string (hex)` | `"#a855f7"` | The contact shadow. Ignored while `shadow` is `false`. |

## Usage

```tsx
import Kinetic from "@/components/registry/kinetic/kinetic";

<Kinetic
  stiffness={620}
  damping={20}
  mass={1}
  jumpHeight={26}
  anticipation={7}
  windUp={130}
  squash={0.62}
  stagger={34}
  interval={2400}
  trigger="loop"
  split="character"
  shadow={true}
  accentColor="#a855f7"
/>
```

The import path matches the file path above; change it if you move the component. Every value shown is the documented default — pass only what you actually want to change. The snippet lists the tunable props only: if the component's props type in the source requires others (content, handlers, data), pass those too.

## Integration rules

- Keep the `"use client"` directive. This is a client component and will not render as a Server Component.
- It fills its parent. Give the wrapper an explicit height (or a definite grid area) — against a height-auto parent it collapses to nothing.
- It takes a `reducedMotion` prop and quiesces when true. Wire it to a `prefers-reduced-motion` listener rather than hardcoding `false`.
- It runs a free-running animation loop. Halt it when off-screen or backgrounded if you care about battery.
- `lib/utils.ts` is required, not optional. It exports the `cn` helper the component imports from `@/lib/utils` — keep it at that path, or rewrite every `cn` import to wherever you already keep yours. If your project is shadcn-based you almost certainly have this file already; keep yours and drop mine.

## Your task

1. Tell me where in my project this should live and why.
2. Create the files above verbatim.
3. Wire the component into the place I point you at, with sensible props for that context.
4. Flag anything in my setup that conflicts with the stack assumptions above.

Do not restyle the component or alter the animation math unless I ask.
