# Integrate `ShadowCursor` from Motion Garden

You are helping me add the **ShadowCursor** 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:** ShadowCursor
- **Category:** Micro-interactions
- **Summary:** A custom cursor with a shadow at its heel. A precise dot leads while a lagging blade trails on a spring, and when it crosses an interactive element the trail pools and swells around it, inverting whatever lies beneath. Scoped entirely to its own stage, so the page cursor is never touched.
- **Reference:** https://motion-garden.netlify.app/components/shadow-cursor
- **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
```

## Files to create

One file. 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/shadow-cursor/shadow-cursor.tsx`

```tsx
"use client";

import { useEffect, useRef, useState, type ReactNode } from "react";
import { motion, useMotionValue, useSpring } from "motion/react";

interface ShadowCursorProps {
  children?: ReactNode;
  dotSize?: number;
  trailSize?: number;
  stiffness?: number;
  damping?: number;
  cursorColor?: string;
  blendMode?: "difference" | "screen" | "exclusion" | "normal";
  poolScale?: number;
  reducedMotion?: boolean;
  className?: string;
}

export default function ShadowCursor({
  children,
  dotSize = 8,
  trailSize = 36,
  stiffness = 150,
  damping = 15,
  cursorColor = "#a855f7",
  blendMode = "difference",
  poolScale = 2,
  reducedMotion = false,
  className,
}: ShadowCursorProps) {
  const stageRef = useRef<HTMLDivElement>(null);
  const [visible, setVisible] = useState(false);

  const dotX = useMotionValue(0);
  const dotY = useMotionValue(0);

  const trailX = useSpring(0, { stiffness, damping });
  const trailY = useSpring(0, { stiffness, damping });
  const trailScale = useSpring(1, { stiffness: 260, damping: 26 });

  const live = useRef({ poolScale, reducedMotion });
  live.current = { poolScale, reducedMotion };

  const moveTo = (clientX: number, clientY: number, poolCenter?: {
    x: number;
    y: number;
  }) => {
    dotX.set(clientX);
    dotY.set(clientY);
    const tx = poolCenter ? poolCenter.x : clientX;
    const ty = poolCenter ? poolCenter.y : clientY;
    if (live.current.reducedMotion) {
      trailX.jump(tx);
      trailY.jump(ty);
    } else {
      trailX.set(tx);
      trailY.set(ty);
    }
  };

  const handlePointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
    const stage = stageRef.current;
    if (!stage) return;
    const rect = stage.getBoundingClientRect();
    const px = e.clientX - rect.left;
    const py = e.clientY - rect.top;

    const target = e.target as Element | null;
    const pool =
      target?.closest?.("[data-cursor-pool], button, a") ?? null;

    if (pool) {
      trailScale.set(live.current.poolScale);
      const pr = pool.getBoundingClientRect();
      const cx = pr.left + pr.width / 2 - rect.left;
      const cy = pr.top + pr.height / 2 - rect.top;
      moveTo(px, py, live.current.reducedMotion ? undefined : { x: cx, y: cy });
    } else {
      trailScale.set(1);
      moveTo(px, py);
    }
  };

  const handlePointerEnter = (e: React.PointerEvent<HTMLDivElement>) => {
    const stage = stageRef.current;
    if (stage) {
      const rect = stage.getBoundingClientRect();
      const px = e.clientX - rect.left;
      const py = e.clientY - rect.top;
      dotX.set(px);
      dotY.set(py);
      trailX.jump(px);
      trailY.jump(py);
    }
    setVisible(true);
  };

  const handlePointerLeave = () => {
    setVisible(false);
    trailScale.set(1);
  };

  useEffect(() => {
    if (reducedMotion) {
      trailX.jump(dotX.get());
      trailY.jump(dotY.get());
    }
  }, [reducedMotion, trailX, trailY, dotX, dotY]);

  return (
    <div
      ref={stageRef}
      onPointerMove={handlePointerMove}
      onPointerEnter={handlePointerEnter}
      onPointerLeave={handlePointerLeave}
      className={[
        "relative overflow-hidden cursor-none **:cursor-none",
        className ?? "",
      ].join(" ")}
    >
      {children}

      <motion.div
        aria-hidden
        className="pointer-events-none absolute left-0 top-0 z-50 rounded-full transition-opacity duration-200"
        style={{
          x: trailX,
          y: trailY,
          scale: trailScale,
          width: trailSize,
          height: trailSize,
          marginLeft: -trailSize / 2,
          marginTop: -trailSize / 2,
          backgroundColor: cursorColor,
          mixBlendMode: blendMode,
          opacity: visible ? 1 : 0,
        }}
      />

      <motion.div
        aria-hidden
        className="pointer-events-none absolute left-0 top-0 z-50 rounded-full transition-opacity duration-200"
        style={{
          x: dotX,
          y: dotY,
          width: dotSize,
          height: dotSize,
          marginLeft: -dotSize / 2,
          marginTop: -dotSize / 2,
          backgroundColor: cursorColor,
          mixBlendMode: blendMode,
          opacity: visible ? 1 : 0,
        }}
      />
    </div>
  );
}
```


## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `dotSize` | `number` | `8` | Size of the leading precise dot. Range 4–24 px. |
| `trailSize` | `number` | `36` | Size of the lagging trailing ring. Range 12–80 px. |
| `stiffness` | `number` | `150` | Spring stiffness of the trailing ring — higher lags less. Range 50–500. |
| `damping` | `number` | `15` | Spring damping of the trailing ring. Range 8–40. |
| `cursorColor` | `string (hex)` | `"#a855f7"` | Color of the dot and trailing ring. |
| `blendMode` | `"difference" | "screen" | "exclusion" | "normal"` | `"difference"` | Mix-blend-mode of the cursor over content beneath it. |
| `poolScale` | `number` | `2` | How much the trail swells when over an interactive element. Range 1–4 ×. |

## Usage

```tsx
import ShadowCursor from "@/components/registry/shadow-cursor/shadow-cursor";

<ShadowCursor
  dotSize={8}
  trailSize={36}
  stiffness={150}
  damping={15}
  cursorColor="#a855f7"
  blendMode="difference"
  poolScale={2}
/>
```

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`.

## 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.
