← All components Next componentSplit Orbit→
Cursors · Light
Aura Spotlight
A soft light following the pointer over dark surfaces, also published as --cursor-x / --cursor-y CSS variables.
Move over the words, then the buttons.
Read the docsdata-cursor-text
<AuraGlowSpotlightCursor />Live
A light that follows you
Customize
Light#a78bfa
Installation
Use it in your project
Or skip the copy-paste
One command: writes the file and installs the dependencies.
$ npx deepui-cli add aura-spotlight
01
Install
The 3D packages this component is built on.
Nothing to install: React is all it needs.
02
Add the component
One self-contained file: create components/AuraGlowSpotlightCursor.tsx and paste it in.
components/AuraGlowSpotlightCursor.tsx
1"use client";23import { memo, useEffect, useRef, useState, type CSSProperties, type RefObject } from "react";45/** What counts as interactive: the cursors react when the pointer is over one of these. */6const INTERACTIVE_SELECTOR =7 "a, button, [role='button'], input, select, textarea, label, summary, [data-cursor], [data-cursor-text], [data-cursor-hover]";89/** A layer pinned to the top-left corner and moved with transforms (no layout, no repaint). */10const FOLLOWER_STYLE: CSSProperties = {11 position: "fixed",12 top: 0,13 left: 0,14 pointerEvents: "none",15 zIndex: 9999,16 willChange: "transform",17};1819/**20 * False on touch screens (`pointer: coarse`) and during server rendering: the custom cursor is not21 * drawn and the native cursor is left alone. Follows the media query live (tablet + mouse…).22 */23function useCursorEnabled() {24 const [enabled, setEnabled] = useState(false);25 useEffect(() => {26 const query = window.matchMedia("(pointer: coarse)");27 const sync = () => setEnabled(!query.matches);28 sync();29 query.addEventListener("change", sync);30 return () => query.removeEventListener("change", sync);31 }, []);32 return enabled;33}3435/** Hides the system cursor on the whole page while `active` (restored on unmount). */36function useHideNativeCursor(active: boolean) {37 useEffect(() => {38 if (!active) return undefined;39 const style = document.createElement("style");40 style.setAttribute("data-custom-cursor", "");41 style.textContent = "*, *::before, *::after { cursor: none !important; }";42 document.head.appendChild(style);43 return () => style.remove();44 }, [active]);45}4647interface CursorPointer {48 /** Position in CSS pixels, relative to the viewport. */49 x: number;50 y: number;51 /** Smoothed velocity, in CSS pixels per second. */52 vx: number;53 vy: number;54 speed: number;55 /** False until the first move, and while the pointer is outside the window. */56 visible: boolean;57 down: boolean;58 /** The interactive element under the pointer (closest match of the selector), or null. */59 target: HTMLElement | null;60 /** Incremented on every press, to trigger click effects. */61 clicks: number;62}6364/**65 * Tracks the pointer through window listeners and returns a ref read inside the animation loop:66 * moving the mouse never re-renders React. All listeners are removed on unmount.67 */68function useCursorPointer(enabled: boolean, selector = INTERACTIVE_SELECTOR): RefObject<CursorPointer> {69 const pointer = useRef<CursorPointer>({ x: -100, y: -100, vx: 0, vy: 0, speed: 0, visible: false, down: false, target: null, clicks: 0 });7071 useEffect(() => {72 if (!enabled) return undefined;73 let last = performance.now();74 const p = pointer.current;75 const pick = (event: PointerEvent) => {76 const el = event.target instanceof Element ? event.target.closest(selector) : null;77 p.target = el instanceof HTMLElement ? el : null;78 };79 const move = (event: PointerEvent) => {80 if (event.pointerType === "touch") return;81 const now = performance.now();82 const dt = Math.max(1, now - last) / 1000;83 last = now;84 if (p.visible) {85 // Smoothed: one jittery event must not make the effects jump86 p.vx = p.vx * 0.6 + ((event.clientX - p.x) / dt) * 0.4;87 p.vy = p.vy * 0.6 + ((event.clientY - p.y) / dt) * 0.4;88 }89 p.x = event.clientX;90 p.y = event.clientY;91 p.visible = true;92 pick(event);93 };94 const down = (event: PointerEvent) => {95 if (event.pointerType === "touch") return;96 p.down = true;97 p.clicks += 1;98 pick(event);99 };100 const up = () => {101 p.down = false;102 };103 const leave = () => {104 p.visible = false;105 p.down = false;106 };107 window.addEventListener("pointermove", move, { passive: true });108 window.addEventListener("pointerdown", down, { passive: true });109 window.addEventListener("pointerup", up, { passive: true });110 document.documentElement.addEventListener("pointerleave", leave);111 window.addEventListener("blur", leave);112 return () => {113 window.removeEventListener("pointermove", move);114 window.removeEventListener("pointerdown", down);115 window.removeEventListener("pointerup", up);116 document.documentElement.removeEventListener("pointerleave", leave);117 window.removeEventListener("blur", leave);118 };119 }, [enabled, selector]);120121 return pointer;122}123124/**125 * requestAnimationFrame loop: `frame(dt, time)` runs every frame (dt in seconds, capped) while126 * `enabled`; the browser pauses it in background tabs. The latest callback is always used.127 */128function useAnimationFrame(enabled: boolean, frame: (dt: number, time: number) => void) {129 const frameRef = useRef(frame);130 useEffect(() => {131 frameRef.current = frame;132 });133 useEffect(() => {134 if (!enabled) return undefined;135 let id = 0;136 let last = performance.now();137 const tick = (now: number) => {138 const dt = Math.min((now - last) / 1000, 1 / 20);139 last = now;140 frameRef.current(dt, now / 1000);141 id = requestAnimationFrame(tick);142 };143 id = requestAnimationFrame(tick);144 return () => cancelAnimationFrame(id);145 }, [enabled]);146}147148/**149 * Velocity only changes on pointer events: call this once per frame so it fades out when the pointer150 * stops, and read `speed` afterwards.151 */152function settlePointer(p: CursorPointer, dt: number) {153 const k = Math.exp(-10 * dt);154 p.vx *= k;155 p.vy *= k;156 p.speed = Math.hypot(p.vx, p.vy);157}158159/** Exponential smoothing factor for a frame: frame-rate independent `lerp`. */160const damp = (lambda: number, dt: number) => 1 - Math.exp(-lambda * dt);161162/** "#rrggbb" (or "#rgb") to "r, g, b", for rgba() strings. */163function hexToRgb(hex: string) {164 let h = hex.replace("#", "");165 if (h.length === 3) h = h.split("").map((c) => c + c).join("");166 const n = parseInt(h.slice(0, 6), 16);167 if (Number.isNaN(n)) return "255, 255, 255";168 return `${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}`;169}170171/** 4. Rendering, materials and glow. */172interface MaterialProps {173 /** Main color of the object. Default "#6366f1". */174 primaryColor?: string;175 /** Color of the glow. Default "#00f0ff". */176 emissiveColor?: string;177 /** Strength of the glow, 0 (none) to 3. Default 1. */178 emissiveIntensity?: number;179 /** 0 (mirror, glass) to 1 (matte). Default 0.3. */180 roughness?: number;181 /** 0 (plastic, organic) to 1 (metal). Default 0.5. */182 metalness?: number;183 /** 0 (opaque) to 1 (clear glass): see-through, refracting surfaces. Default 0. */184 transmission?: number;185 /** Technical wireframe rendering. Default false. */186 wireframe?: boolean;187}188189export interface AuraGlowProps extends Pick<MaterialProps, "emissiveColor" | "emissiveIntensity"> {190 /** Radius of the light, in CSS pixels. Default 380. */191 glowSize?: number;192 emissiveColor?: string;193 /** @deprecated Use `emissiveColor`. */194 glowColor?: string;195 /** Strength of the light, 0–1. Default 0.35. */196 emissiveIntensity?: number;197 /** @deprecated Use `emissiveIntensity`. */198 intensity?: number;199 /** Hide the system cursor. Default false (the light is ambient, not a pointer). */200 hideNativeCursor?: boolean;201}202203/**204 * A diffuse spotlight following the pointer that lights up dark surfaces (screen blending). It also205 * publishes the smoothed position as CSS variables on <html> — `--cursor-x`, `--cursor-y` (px) — so206 * your own elements can react to it, e.g.207 * `background: radial-gradient(300px at var(--cursor-x) var(--cursor-y), #fff2, transparent)`.208 */209function AuraGlowSpotlightCursor({ glowSize = 380, emissiveColor, glowColor = emissiveColor ?? "#a78bfa", emissiveIntensity, intensity = emissiveIntensity ?? 0.35, hideNativeCursor = false }: AuraGlowProps) {210 const enabled = useCursorEnabled();211 const pointer = useCursorPointer(enabled);212 useHideNativeCursor(enabled && hideNativeCursor);213 const layer = useRef<HTMLDivElement>(null);214 const state = useRef({ x: -1000, y: -1000, scale: 1, alpha: 0 });215216 // The variables are removed with the cursor217 useEffect(() => {218 if (!enabled) return undefined;219 const root = document.documentElement;220 return () => {221 root.style.removeProperty("--cursor-x");222 root.style.removeProperty("--cursor-y");223 };224 }, [enabled]);225226 useAnimationFrame(enabled, (dt) => {227 const el = layer.current;228 const p = pointer.current;229 if (!el) return;230 settlePointer(p, dt);231 const s = state.current;232 // Soft lag: the light glides rather than sticks233 s.x += (p.x - s.x) * damp(7, dt);234 s.y += (p.y - s.y) * damp(7, dt);235 s.scale += ((p.target ? 1.25 : 1) - s.scale) * damp(5, dt);236 s.alpha += ((p.visible ? 1 : 0) - s.alpha) * damp(5, dt);237 const root = document.documentElement;238 root.style.setProperty("--cursor-x", `${s.x.toFixed(1)}px`);239 root.style.setProperty("--cursor-y", `${s.y.toFixed(1)}px`);240 // A fixed-size halo moved and scaled by transforms: no full-screen repaint per frame241 el.style.opacity = s.alpha.toFixed(3);242 el.style.transform = `translate3d(${(s.x - glowSize).toFixed(1)}px, ${(s.y - glowSize).toFixed(1)}px, 0) scale(${s.scale.toFixed(3)})`;243 });244245 if (!enabled) return null;246 const rgb = hexToRgb(glowColor);247 return (248 <div249 ref={layer}250 aria-hidden="true"251 style={{252 ...FOLLOWER_STYLE,253 width: glowSize * 2,254 height: glowSize * 2,255 opacity: 0,256 borderRadius: "50%",257 mixBlendMode: "screen",258 background: `radial-gradient(circle closest-side, rgba(${rgb}, ${intensity}), rgba(${rgb}, ${intensity * 0.35}) 50%, transparent 100%)`,259 }}260 />261 );262}263264export default memo(AuraGlowSpotlightCursor);
03
Drop it in a page
Updated live with the settings above.
app/page.tsx
1import AuraGlowSpotlightCursor from "@/components/AuraGlowSpotlightCursor";23export default function Section() {4 return (5 // The component fills this box: give it a position and a height6 <div style={{ position: "relative", width: "100%", height: "100vh" }}>7 <AuraGlowSpotlightCursor8 glowSize={380}9 emissiveIntensity={0.35}10 emissiveColor="#a78bfa"11 />12 </div>13 );14}