{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"aurora-drift-text","type":"registry:component","title":"Aurora Drift Text","description":"Display type filled with aurora light: three bands drift through the letters on slow loops, ray threads slide through them, and the brightest band leans toward the pointer when it comes near.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/aurora-drift-text.tsx","content":"\"use client\";\n\nimport { useEffect, useRef, useSyncExternalStore } from \"react\";\nimport type { CSSProperties } from \"react\";\n\n/**\n * AuroraDriftText — display type filled with aurora light.\n *\n * Three bands of the sky's colours drift through the letters (32s, 38s and\n * 45s loops), fine ray threads slide through them, and a blurred copy\n * behind the words gives the light volume. The brightest band leans to the\n * pointer when it comes near (a ~700ms chase); the others keep drifting.\n * Real text throughout; still under 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 DISPLAY = 'var(--font-bricolage, \"Bricolage Grotesque\", var(--font-sans, \"Geist\"), ui-sans-serif, system-ui, sans-serif)';\n\nconst HEX = /^#[0-9a-fA-F]{6}$/;\n\n/** The night the kit is set in. */\nconst SKY = {\n  ground: \"#050608\",\n  panel: \"#0a0d12\",\n  raised: \"#0f141a\",\n  ink: \"rgba(236,244,248,0.94)\",\n  ink2: \"rgba(236,244,248,0.64)\",\n  ink3: \"rgba(236,244,248,0.42)\",\n  line: \"rgba(236,244,248,0.08)\",\n  line2: \"rgba(236,244,248,0.16)\",\n  shadow: \"0 40px 100px -30px rgba(0,0,0,0.7)\",\n} as const;\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 rgba(hex: string, a: number): string {\n  const [r, g, b] = rgbOf(hex);\n  return `rgba(${r},${g},${b},${a})`;\n}\n\nfunction mixHex(a: string, b: string, k: number): string {\n  const x = rgbOf(a);\n  const y = rgbOf(b);\n  const c = x.map((v, i) => Math.round(v + (y[i] - v) * Math.max(0, Math.min(1, k))));\n  return \"#\" + c.map((v) => v.toString(16).padStart(2, \"0\")).join(\"\");\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// Registered positions, so the bands drift on the compositor; the pointer's pull arrives as plain variables.\nconst DRIFT_CSS =\n  \"@property --au-d1{syntax:'<percentage>';inherits:true;initial-value:30%}\" +\n  \"@property --au-d2{syntax:'<percentage>';inherits:true;initial-value:70%}\" +\n  \"@property --au-d3{syntax:'<percentage>';inherits:true;initial-value:50%}\" +\n  \"@keyframes au-d1{0%,100%{--au-d1:18%}50%{--au-d1:62%}}\" +\n  \"@keyframes au-d2{0%,100%{--au-d2:84%}50%{--au-d2:38%}}\" +\n  \"@keyframes au-d3{0%,100%{--au-d3:40%}50%{--au-d3:92%}}\" +\n  \"@keyframes au-rays{to{background-position:120px 0,0 0,0 0,0 0,0 0}}\" +\n  \".au-drift{animation:au-d1 32s ease-in-out infinite,au-d2 38s ease-in-out infinite,au-d3 45s ease-in-out infinite}\" +\n  \".au-drift-fill{animation:au-rays 32s linear infinite}\" +\n  \"@media (prefers-reduced-motion: reduce){.au-drift,.au-drift-fill{animation:none}}\";\n\nexport type AuroraDriftTextProps = {\n  /** Line breaks stack it. */\n  text: string;\n  as?: \"h1\" | \"h2\" | \"p\";\n  palette?: AuPaletteName;\n  align?: \"left\" | \"center\";\n  className?: string;\n  style?: CSSProperties;\n};\n\n/**\n * Display type filled with aurora light. Three bands of the sky's colours\n * drift through the letters on their own slow loops (32s, 38s and 45s), fine\n * vertical ray threads slide through them, and a soft blurred copy behind the\n * words gives the light volume. The brightest band leans to the pointer's\n * position when the pointer comes near (a ~700ms chase) and drifts again when\n * it leaves; only that one band follows, so it reads as a sky, not a torch.\n * The words stay real text; under reduced motion the light holds still.\n */\nexport function AuroraDriftText({ text, as: Tag = \"h2\", palette = \"boreal\", align = \"left\", className, style }: AuroraDriftTextProps) {\n  const p = paletteOf(palette);\n  const reduced = useReducedMotion();\n  const ref = useRef<HTMLElement | null>(null);\n\n  useEffect(() => {\n    const el = ref.current;\n    if (!el || reduced) return;\n    let raf = 0;\n    let last = 0;\n    let visible = false;\n    const s = { x: 0.5, tx: 0.5, pull: 0, tPull: 0 };\n    const tick = (now: number) => {\n      raf = 0;\n      const dt = last ? Math.min(0.05, (now - last) / 1000) : 0.016;\n      last = now;\n      s.x += (s.tx - s.x) * (1 - Math.exp(-dt * 4));\n      s.pull += (s.tPull - s.pull) * (1 - Math.exp(-dt * 3));\n      el.style.setProperty(\"--au-x\", `${(s.x * 100).toFixed(2)}%`);\n      el.style.setProperty(\"--au-pull\", s.pull.toFixed(3));\n      if (visible && (Math.abs(s.tx - s.x) > 0.001 || Math.abs(s.tPull - s.pull) > 0.002)) raf = requestAnimationFrame(tick);\n      else last = 0;\n    };\n    const onMove = (e: PointerEvent) => {\n      if (!visible) return;\n      const r = el.getBoundingClientRect();\n      const dy = Math.max(0, Math.abs(e.clientY - (r.top + r.height / 2)) - r.height / 2);\n      s.tPull = dy < 180 ? 1 - dy / 180 : 0;\n      s.tx = Math.max(-0.1, Math.min(1.1, (e.clientX - r.left) / (r.width || 1)));\n      if (!raf) raf = requestAnimationFrame(tick);\n    };\n    const onLeave = () => {\n      s.tPull = 0;\n      if (!raf && visible) raf = requestAnimationFrame(tick);\n    };\n    const io = new IntersectionObserver((entries) => {\n      visible = entries[entries.length - 1].isIntersecting;\n    });\n    io.observe(el);\n    document.addEventListener(\"pointermove\", onMove, { passive: true });\n    document.documentElement.addEventListener(\"pointerleave\", onLeave);\n    return () => {\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      document.removeEventListener(\"pointermove\", onMove);\n      document.documentElement.removeEventListener(\"pointerleave\", onLeave);\n    };\n  }, [reduced]);\n\n  const lead = \"calc(var(--au-d1) * (1 - var(--au-pull)) + var(--au-x) * var(--au-pull))\";\n  const fill = [\n    \"repeating-linear-gradient(90deg, rgba(255,255,255,0.16) 0 1px, rgba(255,255,255,0) 1px 6px)\",\n    `radial-gradient(34% 120% at ${lead} 62%, ${mixHex(p.core, \"#ffffff\", 0.35)}, ${rgba(p.core, 0)} 72%)`,\n    `radial-gradient(40% 110% at var(--au-d2) 40%, ${rgba(p.core2, 0.95)}, ${rgba(p.core2, 0)} 72%)`,\n    `radial-gradient(36% 120% at var(--au-d3) 80%, ${rgba(p.blend, 0.9)}, ${rgba(p.blend, 0)} 72%)`,\n    \"linear-gradient(0deg, rgba(236,244,248,0.5), rgba(236,244,248,0.3))\",\n  ];\n  const lines = text.split(\"\\n\");\n  const words = lines.map((l, i) => (\n    <span key={i} className=\"block\">\n      {l}\n      {i < lines.length - 1 ? \" \" : \"\"}\n    </span>\n  ));\n  const type: CSSProperties = {\n    fontFamily: DISPLAY,\n    fontWeight: 650,\n    fontSize: \"clamp(44px, 8cqw, 124px)\",\n    lineHeight: 1.0,\n    letterSpacing: \"-0.02em\",\n    fontVariationSettings: '\"opsz\" 96',\n    textAlign: align,\n    textWrap: \"balance\",\n  };\n  const clip: CSSProperties = {\n    backgroundImage: fill.join(\", \"),\n    WebkitBackgroundClip: \"text\",\n    backgroundClip: \"text\",\n    color: \"transparent\",\n  };\n  return (\n    <Tag\n      ref={(n: HTMLElement | null) => {\n        ref.current = n;\n      }}\n      className={\"au-scope au-drift relative isolate m-0\" + (className ? \" \" + className : \"\")}\n      style={{ \"--au-x\": \"50%\", \"--au-pull\": \"0\", color: SKY.ink, ...type, ...style } as CSSProperties}\n    >\n      <style>{DRIFT_CSS}</style>\n      {/* The same words, blurred behind: the light's volume. */}\n      <span aria-hidden className=\"au-drift-fill pointer-events-none absolute inset-0 -z-10 select-none\" style={{ ...clip, filter: \"blur(18px)\", opacity: 0.45 }}>\n        {words}\n      </span>\n      <span className=\"au-drift-fill block\" style={clip}>\n        {words}\n      </span>\n    </Tag>\n  );\n}\n","type":"registry:component","target":"components/viberdy/aurora-drift-text.tsx"}],"meta":{"tier":"free","tags":["text","heading","gradient text","aurora","background clip","pointer"],"href":"https://viberdy.dev/library/aurora-drift-text","aiPrompt":"Build a React + Tailwind heading, `AuroraDriftText({ text, as, palette, align, className, style })`.\n\nRegister --au-d1, --au-d2 and --au-d3 as inherited <percentage> properties and drift them on 32s, 38s and 45s ease-in-out loops. Fill the words with background-clip: text over five layers: repeating 1px ray threads every 6px (sliding 120px over 32s), a radial of the core (lightened 35% toward white) at calc(var(--au-d1) * (1 - var(--au-pull)) + var(--au-x) * var(--au-pull)), a radial of core2 at --au-d2, a radial of the blend at --au-d3, and a base of white at 30-50%. Behind the words an aria-hidden copy with the same fill, blurred 18px at 0.45. On document pointermove, when the heading is on screen, set the target x from the pointer and a pull that falls to zero 180px above or below the text; ease both each frame (1 - e^(-4dt) and 1 - e^(-3dt)) and write --au-x and --au-pull. Bricolage Grotesque 650, clamp(44px, 8cqw, 124px), leading 1, text-wrap balance.\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"}}