{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"aurora-ribbon-cursor","type":"registry:component","title":"Aurora Ribbon Cursor","description":"The pointer paints a small aurora: a ribbon of light coloured from the indigo fringe to rose that fades like the sky, sending short rays up from every point so the trail reads as a curtain.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/aurora-ribbon-cursor.tsx","content":"\"use client\";\n\nimport { useEffect, useRef, useSyncExternalStore } from \"react\";\nimport type { CSSProperties, ReactNode } from \"react\";\n\n/**\n * AuroraRibbonCursor — the pointer paints a small aurora.\n *\n * Moving through the area draws a ribbon of light that fades like the sky\n * (800ms by default), coloured by its place along the ribbon from the\n * indigo fringe at the tail to rose at the head, and from every point a\n * short ray rises, so the trail reads as a curtain. Faster strokes throw\n * longer rays. A 2D canvas that draws only while there is light; off under\n * reduced motion.\n *\n * Part of the Aurora kit: a near-black night (#050608) lit by curtains of\n * aurora in mint #7cf5c4 and sky #38bdf8, a violet #a78bfa blend, a rose\n * #f472b6 crown and an indigo #5b6cc4 fringe, all on one 60s clock; Bricolage\n * Grotesque through var(--font-bricolage) for lit display type over Geist.\n * Respects prefers-reduced-motion. No dependencies beyond React. Paste it as\n * its own file: it repeats the kit's small helpers, which would clash in one\n * module. For the display face, load Bricolage Grotesque with next/font\n * (variable: \"--font-bricolage\") on a parent; elsewhere, load it with a\n * Google Fonts link or @fontsource and set --font-bricolage yourself.\n */\n\nconst HEX = /^#[0-9a-fA-F]{6}$/;\n\n/**\n * The sky's colours by altitude: the core low in the curtain (two hues it\n * drifts between on the aurora clock), a violet blend above it, a rose crown\n * seen only in a strong display, and an indigo fringe under the lower border.\n */\nexport type AuPalette = { core: string; core2: string; blend: string; high: string; fringe: string };\n\nexport const AU_PALETTES = {\n  boreal: { core: \"#7cf5c4\", core2: \"#38bdf8\", blend: \"#a78bfa\", high: \"#f472b6\", fringe: \"#5b6cc4\" },\n  verdant: { core: \"#6ee7a0\", core2: \"#7cf5c4\", blend: \"#8fb4f0\", high: \"#e879b9\", fringe: \"#5b6cc4\" },\n  violet: { core: \"#a78bfa\", core2: \"#38bdf8\", blend: \"#c4a6fb\", high: \"#f472b6\", fringe: \"#4c5bb8\" },\n} as const satisfies Record<string, AuPalette>;\n\nexport type AuPaletteName = keyof typeof AU_PALETTES;\n\nfunction own<T extends object>(map: T, key: string): key is Extract<keyof T, string> {\n  return Object.prototype.hasOwnProperty.call(map, key);\n}\n\n/** A named palette, or boreal. */\nfunction paletteOf(name: string): AuPalette {\n  return own(AU_PALETTES, name) ? AU_PALETTES[name] : AU_PALETTES.boreal;\n}\n\nfunction rgbOf(hex: string): [number, number, number] {\n  const n = parseInt((HEX.test(hex) ? hex : \"#7cf5c4\").slice(1), 16);\n  return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n}\n\nfunction subscribeMotion(cb: () => void) {\n  const m = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n  m.addEventListener(\"change\", cb);\n  return () => m.removeEventListener(\"change\", cb);\n}\n\n/** True when the visitor asked for reduced motion. False on the server. */\nfunction useReducedMotion(): boolean {\n  return useSyncExternalStore(\n    subscribeMotion,\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\n/** The palette as CSS variables, for the parts drawn in CSS. */\nfunction paletteVars(p: AuPalette): CSSProperties {\n  return { \"--au-core\": p.core, \"--au-core2\": p.core2, \"--au-blend\": p.blend, \"--au-high\": p.high, \"--au-ring\": p.core } as CSSProperties;\n}\n\nexport type AuroraRibbonCursorProps = {\n  children?: ReactNode;\n  palette?: AuPaletteName;\n  /** How long a stretch of ribbon lasts, 400-1400ms. */\n  life?: number;\n  /** Width of the ribbon's lit core, 2-6px. */\n  width?: number;\n  /** Let the ribbon send short rays upward, like a curtain. */\n  rays?: boolean;\n  /** \"under\" draws below the children, \"over\" above them (never catching the pointer). */\n  layer?: \"under\" | \"over\";\n  /** While nobody moves, a slow ghost stroke crosses the area every few seconds (a landing page or a demo); it stops as soon as the pointer moves. */\n  attract?: boolean;\n  className?: string;\n  style?: CSSProperties;\n};\n\n/**\n * The pointer paints a small aurora. Moving through the area draws a ribbon\n * of light that fades like the sky (800ms by default): a thin lit core in a\n * soft halo, coloured by its place along the ribbon, from the indigo fringe\n * at the tail through the core hues to violet and rose at the head, and from\n * every point of it a short ray rises and fades, so the trail reads as a\n * curtain, not a line. Faster strokes throw longer rays. It draws on a 2D\n * canvas only while there is light to draw, and not at all under reduced\n * motion. With `attract`, a slow ghost stroke crosses the area every 10.8s\n * until the visitor moves.\n */\nexport function AuroraRibbonCursor({ children, palette = \"boreal\", life = 800, width = 3.5, rays = true, layer = \"under\", attract = false, className, style }: AuroraRibbonCursorProps) {\n  const p = paletteOf(palette);\n  const reduced = useReducedMotion();\n  const hostRef = useRef<HTMLDivElement>(null);\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const optsRef = useRef({ p, life, width, rays, attract });\n  useEffect(() => {\n    optsRef.current = { p, life: Math.max(400, Math.min(1400, life)), width: Math.max(2, Math.min(6, width)), rays, attract };\n  });\n\n  useEffect(() => {\n    const host = hostRef.current;\n    const canvas = canvasRef.current;\n    if (!host || !canvas || reduced) return;\n    const ctx = canvas.getContext(\"2d\");\n    if (!ctx) return;\n    let W = 1;\n    let H = 1;\n    let raf = 0;\n    let visible = false;\n    let lastReal = -1e9;\n    const pts: { x: number; y: number; t: number; v: number }[] = [];\n    const add = (x: number, y: number, now: number) => {\n      const last = pts[pts.length - 1];\n      if (last && now - last.t < optsRef.current.life) {\n        const dx = x - last.x;\n        const dy = y - last.y;\n        const d = Math.hypot(dx, dy);\n        const v = (d / Math.max(1, now - last.t)) * 1000;\n        // Fill long gaps, so the rays stay dense on a fast stroke.\n        const n = Math.min(14, Math.floor(d / 6));\n        for (let i = 1; i <= n; i++) pts.push({ x: last.x + (dx * i) / (n + 1), y: last.y + (dy * i) / (n + 1), t: last.t + ((now - last.t) * i) / (n + 1), v });\n        pts.push({ x, y, t: now, v });\n      } else {\n        pts.push({ x, y, t: now, v: 0 });\n      }\n      if (pts.length > 180) pts.splice(0, pts.length - 180);\n    };\n    // The ghost stroke: 1.8s across the middle of the area every 10.8s, while nobody is moving.\n    const ghosting = (now: number) => optsRef.current.attract && visible && now - lastReal > 2500;\n    const ghost = (now: number) => {\n      const k = (now % 10800) / 1800;\n      if (k >= 1) return;\n      add(W * (0.12 + 0.76 * k), H * (0.58 - 0.16 * Math.sin(k * Math.PI) + 0.05 * Math.sin(k * Math.PI * 4)), now);\n    };\n    const size = () => {\n      const dpr = Math.min(window.devicePixelRatio || 1, 2);\n      W = Math.max(1, host.clientWidth);\n      H = Math.max(1, host.clientHeight);\n      canvas.width = Math.round(W * dpr);\n      canvas.height = Math.round(H * dpr);\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n    };\n    // Tail to head: the fringe, the two core hues, the blend, the crown.\n    const colorAt = (k: number): [number, number, number] => {\n      const q = optsRef.current.p;\n      const stops = [q.fringe, q.core2, q.core, q.blend, q.high].map(rgbOf);\n      const f = Math.max(0, Math.min(1, k)) * (stops.length - 1);\n      const i = Math.min(stops.length - 2, Math.floor(f));\n      const m = f - i;\n      return [0, 1, 2].map((c) => Math.round(stops[i][c] + (stops[i + 1][c] - stops[i][c]) * m)) as [number, number, number];\n    };\n    const draw = (now: number) => {\n      raf = 0;\n      const o = optsRef.current;\n      if (ghosting(now)) ghost(now);\n      while (pts.length && now - pts[0].t > o.life) pts.shift();\n      ctx.clearRect(0, 0, W, H);\n      if (pts.length < 2) {\n        if (pts.length || (o.attract && visible)) raf = requestAnimationFrame(draw);\n        return;\n      }\n      ctx.globalCompositeOperation = \"lighter\";\n      ctx.lineCap = \"round\";\n      for (let i = 1; i < pts.length; i++) {\n        const a = pts[i - 1];\n        const b = pts[i];\n        const age = Math.max(0, 1 - (now - b.t) / o.life);\n        const [r, g, bl] = colorAt(i / (pts.length - 1));\n        const alpha = 0.55 * age * age;\n        ctx.beginPath();\n        ctx.moveTo(a.x, a.y);\n        ctx.lineTo(b.x, b.y);\n        ctx.strokeStyle = `rgba(${r},${g},${bl},${(alpha * 0.2).toFixed(3)})`;\n        ctx.lineWidth = o.width * 4.5;\n        ctx.stroke();\n        ctx.strokeStyle = `rgba(${r},${g},${bl},${alpha.toFixed(3)})`;\n        ctx.lineWidth = o.width;\n        ctx.stroke();\n        if (o.rays) {\n          // A ray rising from the ribbon, longer for a faster stroke.\n          const h = (14 + Math.min(46, b.v * 0.03)) * (0.35 + 0.65 * age);\n          const gr = ctx.createLinearGradient(b.x, b.y, b.x, b.y - h);\n          gr.addColorStop(0, `rgba(${r},${g},${bl},${(alpha * 0.55).toFixed(3)})`);\n          gr.addColorStop(1, `rgba(${r},${g},${bl},0)`);\n          ctx.fillStyle = gr;\n          ctx.fillRect(b.x - 1, b.y - h, 2, h);\n        }\n      }\n      const head = pts[pts.length - 1];\n      const hAge = Math.max(0, 1 - (now - head.t) / o.life);\n      const [hr, hg, hb] = colorAt(1);\n      const glow = ctx.createRadialGradient(head.x, head.y, 0, head.x, head.y, o.width * 5);\n      glow.addColorStop(0, `rgba(${Math.min(255, hr + 60)},${Math.min(255, hg + 60)},${Math.min(255, hb + 60)},${(0.6 * hAge).toFixed(3)})`);\n      glow.addColorStop(1, `rgba(${hr},${hg},${hb},0)`);\n      ctx.fillStyle = glow;\n      ctx.fillRect(head.x - o.width * 5, head.y - o.width * 5, o.width * 10, o.width * 10);\n      raf = requestAnimationFrame(draw);\n    };\n    const onMove = (e: PointerEvent) => {\n      const r = host.getBoundingClientRect();\n      // Layout units, so a scaled host (a thumbnail) still lines up.\n      const x = (e.clientX - r.left) * (host.clientWidth / (r.width || 1));\n      const y = (e.clientY - r.top) * (host.clientHeight / (r.height || 1));\n      const now = performance.now();\n      if (now - lastReal > 2500) pts.length = 0;\n      lastReal = now;\n      add(x, y, now);\n      if (!raf) raf = requestAnimationFrame(draw);\n    };\n    const io = new IntersectionObserver((entries) => {\n      visible = entries[entries.length - 1].isIntersecting;\n      if (visible && !raf && optsRef.current.attract) raf = requestAnimationFrame(draw);\n    });\n    const ro = new ResizeObserver(size);\n    size();\n    ro.observe(host);\n    io.observe(host);\n    host.addEventListener(\"pointermove\", onMove);\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      host.removeEventListener(\"pointermove\", onMove);\n    };\n  }, [reduced]);\n\n  return (\n    <div ref={hostRef} className={\"au-scope relative isolate\" + (className ? \" \" + className : \"\")} style={{ ...paletteVars(p), ...style }}>\n      <canvas ref={canvasRef} aria-hidden className={\"pointer-events-none absolute inset-0 h-full w-full \" + (layer === \"over\" ? \"z-[2]\" : \"z-0\")} />\n      {children !== undefined && <div className=\"relative z-[1]\">{children}</div>}\n    </div>\n  );\n}\n","type":"registry:component","target":"components/viberdy/aurora-ribbon-cursor.tsx"}],"meta":{"tier":"free","tags":["cursor","trail","pointer","canvas","aurora","ribbon","interactive"],"href":"https://viberdy.dev/library/aurora-ribbon-cursor","aiPrompt":"Build a React + Tailwind wrapper, `AuroraRibbonCursor({ children, palette, life, width, rays, layer, attract, className, style })`.\n\nA relative host with a 2D canvas absolutely inside it (under or over the children, pointer-events none), sized to the host at devicePixelRatio up to 2. On pointermove convert to layout units (correcting for scaled ancestors), push { x, y, t, v } (v = px/s) and fill gaps longer than 6px with interpolated points (at most 14); keep at most 180. Each frame drop points older than life, clear, set globalCompositeOperation lighter, and for each segment: colour by its index along the ribbon through fringe, core2, core, blend, high; alpha 0.55 x age squared; a halo stroke (width x 4.5, alpha x 0.2) and a core stroke; and, with rays, a 2px vertical gradient rising (14 + min(46, v x 0.03)) x (0.35 + 0.65 age) px. A soft radial at the head. Run the loop only while there are points (or, with attract, while visible). Attract: after 2.5s without real movement, lay a ghost stroke across the middle over 1.8s every 10.8s.\n\nAurora grammar: a near-black night #050608 (panels #0a0d12, raised #0f141a; ink #ecf4f8 at 94/64/42%; hairlines at 8% and 16%). The light is real aurora, coloured by altitude: a core in mint #7cf5c4 drifting toward sky #38bdf8 on one shared 60s clock, a violet #a78bfa blend above it, a rose #f472b6 crown seen only in a strong display, and an indigo #5b6cc4 fringe under the lower border (palettes: boreal, verdant #6ee7a0, violet). Never a hue-rotate cycle, never full-saturation rainbow; colour is a function of position and altitude, blended through noise. Curtains have a bright lower border, rays that rise and fray, folds that brighten where a sheet turns edge-on, and stretches that are lit and gone; layers are phase-offset, never in unison. A static 2% dither against banding (not re-seeded). Text never sits on bare aurora: frosted glass (blur 14-18px) or the dark between curtains. Bricolage Grotesque through var(--font-bricolage, \"Bricolage Grotesque\", ...) at 600-650 for lit display type only, Geist for UI, Geist Mono uppercase captions. Radii 20-24px on panels, pills for controls. Motion: the 60s aurora clock, ambient drifts of 30s and longer, discrete hover or focus changes under 450ms, pointer chases that settle over 600-900ms (1 - e^(-4dt)); WebGL runs at 30fps and only on screen. Every CSS-animated glow is started where the clock already is (a negative animation-delay from performance.now()), so parts mounted at different moments stay in step. Nothing interpolated into the small static <style> each part renders; colours arrive as CSS variables. Respect prefers-reduced-motion (still sky, no chases). No dependencies beyond React.","license":"https://viberdy.dev/license"}}