{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "spotlight",
  "title": "Spotlight",
  "description": "A surface that catches a soft light under the pointer, on its face, on its edge or by uncovering a hidden layer. Off on touch.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "registry/miseui/ui/spotlight.tsx",
      "content": "import type * as React from \"react\"\nimport { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from \"react\"\nimport { motion, useMotionTemplate, useMotionValue, useReducedMotion, useSpring } from \"motion/react\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\n\ntype SpotlightVariant = \"glow\" | \"border\" | \"reveal\"\ntype SpotlightEffect = \"trail\"\n\n/** Critical damping with the 0.35 s response of SPRING_DEFAULT. useSpring takes physics, not a duration. */\nconst TRAIL_SPRING = { stiffness: 322, damping: 36, mass: 1 }\nconst OFFSTAGE = -9999\n\n/** Inline, because these read custom properties that change on every pointer move and a utility class would add nothing. */\nconst LAYER_STYLE: Record<SpotlightVariant, React.CSSProperties> = {\n  glow: {\n    background: \"radial-gradient(360px circle at var(--mise-spot-x) var(--mise-spot-y), color-mix(in oklab, var(--mise) 14%, transparent), transparent 70%)\",\n  },\n  border: {\n    background: \"radial-gradient(240px circle at var(--mise-spot-x) var(--mise-spot-y), var(--mise), transparent 70%)\",\n    // Keeps the padding ring and cuts out the content box: only the edge catches the light.\n    mask: \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n    maskComposite: \"exclude\",\n  },\n  reveal: {\n    maskImage: \"radial-gradient(180px circle at var(--mise-spot-x) var(--mise-spot-y), #000, transparent 100%)\",\n  },\n}\n\nconst LAYER_CLASS: Record<SpotlightVariant, string> = {\n  glow: \"inset-0 -z-10\",\n  // Past the root's own 1 px border, so the bright ring lands exactly on it.\n  border: \"-inset-px p-px\",\n  reveal: \"inset-0 -z-10 overflow-hidden\",\n}\n\nconst GRID_STYLE: React.CSSProperties = {\n  backgroundImage:\n    \"linear-gradient(color-mix(in oklab, var(--foreground) 16%, transparent) 1px, transparent 1px), linear-gradient(90deg, color-mix(in oklab, var(--foreground) 16%, transparent) 1px, transparent 1px)\",\n  backgroundSize: \"24px 24px\",\n}\n\ninterface Light {\n  move: (clientX: number, clientY: number) => void\n  leave: () => void\n}\n\nconst GroupContext = createContext<{ add: (light: Light) => () => void } | null>(null)\n\nfunction useLight(trail: boolean) {\n  const rootRef = useRef<HTMLDivElement>(null)\n  const litRef = useRef(false)\n  const [lit, setLit] = useState(false)\n  const x = useMotionValue(OFFSTAGE)\n  const y = useMotionValue(OFFSTAGE)\n  const trailX = useSpring(x, TRAIL_SPRING)\n  const trailY = useSpring(y, TRAIL_SPRING)\n  const move = useCallback(\n    (clientX: number, clientY: number) => {\n      const box = rootRef.current?.getBoundingClientRect()\n      if (!box) return\n      x.set(clientX - box.left)\n      y.set(clientY - box.top)\n      // Arriving from outside, the light starts under the pointer instead of flying in from where it last was.\n      if (!litRef.current) {\n        trailX.jump(clientX - box.left)\n        trailY.jump(clientY - box.top)\n      }\n      litRef.current = true\n      setLit(true)\n    },\n    [x, y, trailX, trailY],\n  )\n  const leave = useCallback(() => {\n    litRef.current = false\n    setLit(false)\n  }, [])\n  const left = useMotionTemplate`${trail ? trailX : x}px`\n  const top = useMotionTemplate`${trail ? trailY : y}px`\n  return { rootRef, lit, move, leave, left, top }\n}\n\ntype SpotlightProps = Omit<React.ComponentProps<typeof motion.div>, \"style\" | \"children\"> & {\n  /** `glow` a soft light on the surface, `border` only the edge lights up, `reveal` a hidden layer shows under the pointer. */\n  variant?: SpotlightVariant\n  /** `trail` lets the light lag slightly behind the pointer, as if it had weight. */\n  effect?: SpotlightEffect\n  /** What `reveal` uncovers. Defaults to a fine grid. */\n  revealed?: React.ReactNode\n  style?: React.CSSProperties\n  children?: React.ReactNode\n}\n\nfunction Spotlight({ variant = \"glow\", effect, revealed, className, style, children, onPointerMove, onPointerLeave, ...props }: SpotlightProps) {\n  const reduceMotion = useReducedMotion() ?? false\n  const group = useContext(GroupContext)\n  const { rootRef, lit, move, leave, left, top } = useLight(effect === \"trail\" && !reduceMotion)\n  useEffect(() => group?.add({ move, leave }), [group, move, leave])\n  return (\n    <motion.div\n      ref={rootRef}\n      data-slot=\"spotlight\"\n      data-variant={variant}\n      data-effect={effect}\n      data-lit={lit ? \"true\" : undefined}\n      className={cn(\"relative isolate min-w-0 rounded-lg border bg-card text-card-foreground\", className)}\n      style={{ ...style, \"--mise-spot-x\": left, \"--mise-spot-y\": top } as React.ComponentProps<typeof motion.div>[\"style\"]}\n      onPointerMove={(event) => {\n        onPointerMove?.(event)\n        // A finger has no hover to follow, and a light stuck where it last touched would look like a bug.\n        if (!group && event.pointerType !== \"touch\") move(event.clientX, event.clientY)\n      }}\n      onPointerLeave={(event) => {\n        onPointerLeave?.(event)\n        if (!group) leave()\n      }}\n      {...props}\n    >\n      <span\n        aria-hidden=\"true\"\n        data-slot=\"spotlight-light\"\n        className={cn(\n          \"pointer-events-none absolute rounded-[inherit] transition-opacity duration-(--duration-slow) ease-(--ease-mise) motion-reduce:transition-none\",\n          LAYER_CLASS[variant],\n          lit ? \"opacity-100\" : \"opacity-0\",\n        )}\n        style={LAYER_STYLE[variant]}\n      >\n        {variant === \"reveal\" ? (revealed ?? <span data-slot=\"spotlight-grid\" className=\"absolute inset-0 block\" style={GRID_STYLE} />) : null}\n      </span>\n      {children}\n    </motion.div>\n  )\n}\n\ntype SpotlightGroupProps = React.ComponentProps<\"div\">\n\n/** One pointer lights every card inside at once, so a light passing between two cards catches the edge of both. */\nfunction SpotlightGroup({ className, onPointerMove, onPointerLeave, ...props }: SpotlightGroupProps) {\n  const lights = useRef<ReadonlySet<Light>>(new Set())\n  const registry = useMemo(\n    () => ({\n      add: (light: Light) => {\n        lights.current = new Set([...lights.current, light])\n        return () => {\n          lights.current = new Set([...lights.current].filter((entry) => entry !== light))\n        }\n      },\n    }),\n    [],\n  )\n  return (\n    <GroupContext.Provider value={registry}>\n      <div\n        data-slot=\"spotlight-group\"\n        className={cn(\"min-w-0\", className)}\n        onPointerMove={(event) => {\n          onPointerMove?.(event)\n          if (event.pointerType === \"touch\") return\n          lights.current.forEach((light) => light.move(event.clientX, event.clientY))\n        }}\n        onPointerLeave={(event) => {\n          onPointerLeave?.(event)\n          lights.current.forEach((light) => light.leave())\n        }}\n        {...props}\n      />\n    </GroupContext.Provider>\n  )\n}\n\nexport { Spotlight, SpotlightGroup, type SpotlightProps, type SpotlightGroupProps, type SpotlightVariant, type SpotlightEffect }\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "backgrounds"
  ],
  "type": "registry:ui"
}