{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "northern-lights",
  "title": "Northern Lights",
  "description": "A night sky shader with shimmering aurora curtains that ripple and pulse over a mountain ridge and twinkling stars; the curtains brighten and lean toward the pointer, and anything you place inside sits on top.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/northern-lights/northern-lights.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface NorthernLightsProps extends Omit<React.ComponentPropsWithoutRef<\"div\">, \"children\"> {\n  /** Content shown on top of the background. */\n  children?: React.ReactNode;\n  /** Aurora colours, bottom edge to top of the curtains, then the star colour. */\n  colors?: [string, string, string, string];\n  /** Base colour behind the effect. */\n  background?: string;\n  /** Animation speed multiplier. */\n  speed?: number;\n  /** Overall brightness of the effect. */\n  intensity?: number;\n  /** Curtains near the pointer brighten and lean toward it. */\n  interactive?: boolean;\n  /** Render scale: 1 is full resolution, lower values are cheaper on very large screens. */\n  resolution?: number;\n  /** Freeze the animation on its current frame. */\n  paused?: boolean;\n}\n\nconst DEFAULT_COLORS: [string, string, string, string] = [\"#3dffa0\", \"#19d3c5\", \"#8b5cff\", \"#e6f7ff\"];\nconst DEFAULT_BACKGROUND = \"#040912\";\n\nconst VERTEX = `attribute vec2 aPos;\nvoid main() { gl_Position = vec4(aPos, 0.0, 1.0); }`;\n\nconst FRAGMENT = `#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\nuniform vec2 uRes;\nuniform float uTime;\nuniform vec2 uMouse;\nuniform float uHover;\nuniform float uIntensity;\nuniform vec3 uBg;\nuniform vec3 uC0;\nuniform vec3 uC1;\nuniform vec3 uC2;\nuniform vec3 uC3;\n\nfloat hash(vec2 p) {\n  p = fract(p * vec2(123.34, 456.21));\n  p += dot(p, p + 45.32);\n  return fract(p.x * p.y);\n}\nfloat noise(vec2 p) {\n  vec2 i = floor(p);\n  vec2 f = fract(p);\n  vec2 u = f * f * (3.0 - 2.0 * f);\n  return mix(mix(hash(i), hash(i + vec2(1.0, 0.0)), u.x), mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), u.x), u.y);\n}\nfloat fbm(vec2 p) {\n  float v = 0.0;\n  float a = 0.5;\n  for (int i = 0; i < 5; i++) {\n    v += a * noise(p);\n    p = p * 2.03 + vec2(1.7, 9.2);\n    a *= 0.5;\n  }\n  return v;\n}\nvoid main() {\n  vec2 uv = gl_FragCoord.xy / uRes;\n  float ar = uRes.x / uRes.y;\n  vec2 p = vec2(uv.x * ar, uv.y);\n  float t = uTime;\n  vec3 col = mix(uBg * 1.6, uBg * 0.45, uv.y);\n\n  // Stars, twinkling, fading out toward the horizon.\n  vec2 sp = p * 170.0;\n  vec2 si = floor(sp);\n  float s = hash(si);\n  vec2 sf = fract(sp) - 0.5;\n  float star = step(0.9965, s) * smoothstep(0.32, 0.0, length(sf)) * (0.55 + 0.45 * sin(t * 2.2 + s * 60.0));\n  col += uC3 * star * smoothstep(0.28, 0.65, uv.y);\n\n  // Three curtains: a wavy lower edge, a long soft glow upward and fine vertical rays.\n  float mx = uMouse.x * ar;\n  vec3 aur = vec3(0.0);\n  for (int i = 0; i < 3; i++) {\n    float fi = float(i);\n    float x = p.x + fi * 1.9;\n    float lean = (mx - p.x) * 0.06 * uHover * exp(-pow((p.x - mx) * 1.6, 2.0));\n    float base = 0.5 + fi * 0.06 + 0.075 * sin(x * 2.3 + t * 0.18 + fi * 2.1) + 0.04 * sin(x * 5.1 - t * 0.27 + fi) + (fbm(vec2(x * 1.1 + t * 0.05, fi * 3.7)) - 0.5) * 0.42 + lean;\n    float d = uv.y - base;\n    float shape = d > 0.0 ? exp(-d * d * (16.0 + fi * 8.0)) : exp(-d * d * 420.0);\n    float rays = 0.45 + 0.55 * fbm(vec2(x * 22.0 + t * 0.35, uv.y * 1.2 - t * 0.25));\n    float pulse = 0.72 + 0.28 * sin(x * 2.4 + t * 0.7 + fi * 1.3);\n    vec3 c = mix(uC0, uC1, clamp(d * 4.0 + 0.4, 0.0, 1.0));\n    c = mix(c, uC2, clamp(d * 3.0 - 0.15, 0.0, 1.0));\n    aur += c * shape * rays * pulse * (0.85 - fi * 0.2);\n  }\n  aur *= 1.0 + 0.7 * uHover * exp(-pow((p.x - mx) * 2.2, 2.0));\n  col += aur * uIntensity;\n\n  // A ridge of mountains with a faint glow of the sky on it.\n  float ridge = 0.13 + 0.07 * fbm(vec2(p.x * 2.2, 3.0)) + 0.025 * sin(p.x * 6.5 + 1.0);\n  float m = smoothstep(ridge + 0.003, ridge - 0.003, uv.y);\n  vec3 land = uBg * 0.35 + aur * 0.06;\n  col = mix(col, land, m);\n  col *= 1.0 - 0.25 * length((uv - 0.5) * vec2(1.0, 0.6));\n  gl_FragColor = vec4(col, 1.0);\n}`;\n\nconst UNIFORMS = [\"uRes\", \"uTime\", \"uMouse\", \"uHover\", \"uIntensity\", \"uBg\", \"uC0\", \"uC1\", \"uC2\", \"uC3\"] as const;\n\nfunction rgb(hex: string): [number, number, number] {\n  const h = hex.replace(\"#\", \"\");\n  const full =\n    h.length === 3\n      ? h\n          .split(\"\")\n          .map((c) => c + c)\n          .join(\"\")\n      : h.slice(0, 6);\n  const n = parseInt(full, 16) || 0;\n  return [((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255];\n}\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nfunction compile(gl: WebGLRenderingContext, type: number, source: string) {\n  const shader = gl.createShader(type);\n  if (!shader) return null;\n  gl.shaderSource(shader, source);\n  gl.compileShader(shader);\n  if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n    console.warn(\"NorthernLights shader:\", gl.getShaderInfoLog(shader));\n    gl.deleteShader(shader);\n    return null;\n  }\n  return shader;\n}\n\nexport function NorthernLights({\n  children,\n  colors = DEFAULT_COLORS,\n  background = DEFAULT_BACKGROUND,\n  speed = 1,\n  intensity = 1,\n  interactive = true,\n  resolution = 1,\n  paused = false,\n  className,\n  style,\n  onPointerMove,\n  onPointerEnter,\n  onPointerLeave,\n  onPointerDown,\n  onPointerUp,\n  ...props\n}: NorthernLightsProps) {\n  const reduce = useReducedMotion();\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const [failed, setFailed] = React.useState(false);\n  // The render loop reads the latest props from here, so changing a prop never rebuilds WebGL.\n  const live = React.useRef({ colors, background, speed, intensity, interactive, resolution, still: paused || reduce });\n  const kick = React.useRef<() => void>(() => {});\n  // Pointer state in 0..1 (y up, like gl_FragCoord), eased toward its target every frame.\n  const input = React.useRef({ x: 0.5, y: 0.5, tx: 0.5, ty: 0.5, hover: 0, thover: 0, down: false, clickX: 0.5, clickY: 0.5, clicks: 0 });\n\n  React.useEffect(() => {\n    live.current = { colors, background, speed, intensity, interactive, resolution, still: paused || reduce };\n    kick.current();\n  }, [colors, background, speed, intensity, interactive, resolution, paused, reduce]);\n\n  React.useEffect(() => {\n    const canvas = canvasRef.current;\n    const root = rootRef.current;\n    if (!canvas || !root) return;\n    const gl = canvas.getContext(\"webgl\", { antialias: false, alpha: false, preserveDrawingBuffer: true, powerPreference: \"low-power\" });\n    const fail = () => requestAnimationFrame(() => setFailed(true));\n    if (!gl) {\n      fail();\n      return;\n    }\n    const vs = compile(gl, gl.VERTEX_SHADER, VERTEX);\n    const fs = compile(gl, gl.FRAGMENT_SHADER, FRAGMENT);\n    const program = gl.createProgram();\n    if (!vs || !fs || !program) {\n      fail();\n      return;\n    }\n    gl.attachShader(program, vs);\n    gl.attachShader(program, fs);\n    gl.linkProgram(program);\n    if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n      fail();\n      return;\n    }\n    gl.useProgram(program);\n    const buffer = gl.createBuffer();\n    gl.bindBuffer(gl.ARRAY_BUFFER, buffer);\n    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);\n    const aPos = gl.getAttribLocation(program, \"aPos\");\n    gl.enableVertexAttribArray(aPos);\n    gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);\n    const u = Object.fromEntries(UNIFORMS.map((name) => [name, gl.getUniformLocation(program, name)])) as Record<(typeof UNIFORMS)[number], WebGLUniformLocation | null>;\n\n    const state = { time: 8, last: 0 };\n    let raf = 0;\n    let visible = true;\n\n    const resize = () => {\n      const dpr = Math.min(window.devicePixelRatio || 1, 1.5) * Math.max(0.25, Math.min(1, live.current.resolution));\n      const w = Math.max(1, Math.round(root.clientWidth * dpr));\n      const h = Math.max(1, Math.round(root.clientHeight * dpr));\n      if (canvas.width !== w || canvas.height !== h) {\n        canvas.width = w;\n        canvas.height = h;\n        gl.viewport(0, 0, w, h);\n      }\n    };\n\n    const draw = (dt: number) => {\n      const L = live.current;\n      const inp = input.current;\n      const ease = 1 - Math.exp(-dt * 5);\n      inp.x += (inp.tx - inp.x) * ease;\n      inp.y += (inp.ty - inp.y) * ease;\n      inp.hover += ((L.interactive ? inp.thover : 0) - inp.hover) * (1 - Math.exp(-dt * 3));\n      const step = L.still ? 0 : dt * L.speed;\n      state.time += step;\n\n      const [c0, c1, c2, c3] = L.colors;\n      gl.uniform2f(u.uRes, canvas.width, canvas.height);\n      gl.uniform1f(u.uTime, state.time);\n      gl.uniform2f(u.uMouse, inp.x, inp.y);\n      gl.uniform1f(u.uHover, inp.hover);\n      gl.uniform1f(u.uIntensity, L.intensity);\n      gl.uniform3fv(u.uBg, rgb(L.background));\n      gl.uniform3fv(u.uC0, rgb(c0));\n      gl.uniform3fv(u.uC1, rgb(c1));\n      gl.uniform3fv(u.uC2, rgb(c2));\n      gl.uniform3fv(u.uC3, rgb(c3));\n      gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);\n    };\n\n    const frame = (now: number) => {\n      const dt = Math.min(0.05, state.last ? (now - state.last) / 1000 : 1 / 60);\n      state.last = now;\n      resize();\n      draw(dt);\n      // Keep running while visible and moving; a still background draws once and waits for a kick.\n      if (visible && !document.hidden && !live.current.still) raf = requestAnimationFrame(frame);\n      else state.last = 0;\n    };\n    const start = () => {\n      cancelAnimationFrame(raf);\n      raf = requestAnimationFrame(frame);\n    };\n    kick.current = start;\n\n    const ro = new ResizeObserver(start);\n    ro.observe(root);\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible) start();\n    });\n    io.observe(root);\n    const onVisibility = () => !document.hidden && start();\n    document.addEventListener(\"visibilitychange\", onVisibility);\n    const onLost = (event: Event) => {\n      event.preventDefault();\n      setFailed(true);\n    };\n    canvas.addEventListener(\"webglcontextlost\", onLost);\n    start();\n\n    return () => {\n      cancelAnimationFrame(raf);\n      kick.current = () => {};\n      ro.disconnect();\n      io.disconnect();\n      document.removeEventListener(\"visibilitychange\", onVisibility);\n      canvas.removeEventListener(\"webglcontextlost\", onLost);\n      gl.deleteBuffer(buffer);\n      gl.deleteProgram(program);\n      gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n    };\n  }, []);\n\n  const point = (event: React.PointerEvent<HTMLDivElement>) => {\n    const r = event.currentTarget.getBoundingClientRect();\n    const inp = input.current;\n    inp.tx = (event.clientX - r.left) / Math.max(1, r.width);\n    inp.ty = 1 - (event.clientY - r.top) / Math.max(1, r.height);\n  };\n\n  return (\n    <div\n      ref={rootRef}\n      className={cn(\"relative isolate overflow-hidden\", className)}\n      style={{ background, ...style }}\n      onPointerMove={(event) => {\n        point(event);\n        onPointerMove?.(event);\n      }}\n      onPointerEnter={(event) => {\n        point(event);\n        input.current.thover = 1;\n        onPointerEnter?.(event);\n      }}\n      onPointerLeave={(event) => {\n        input.current.thover = 0;\n        input.current.down = false;\n        onPointerLeave?.(event);\n      }}\n      onPointerDown={(event) => {\n        point(event);\n        const inp = input.current;\n        inp.down = true;\n        inp.clickX = inp.tx;\n        inp.clickY = inp.ty;\n        inp.clicks += 1;\n        onPointerDown?.(event);\n      }}\n      onPointerUp={(event) => {\n        input.current.down = false;\n        onPointerUp?.(event);\n      }}\n      {...props}\n    >\n      <canvas ref={canvasRef} aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 -z-10 h-full w-full\" />\n      {failed && (\n        <div\n          aria-hidden=\"true\"\n          className=\"absolute inset-0 -z-10\"\n          style={{ background: `radial-gradient(120% 90% at 50% 0%, ${colors[1]}55, transparent 60%), radial-gradient(90% 70% at 50% 100%, ${colors[0]}33, transparent 70%), ${background}` }}\n        />\n      )}\n      {children}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}