{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bg-dark-veil",
  "type": "registry:component",
  "title": "Dark Veil",
  "description": "A dark translucent veil of drifting smoke with faint colored light at its edges. The pointer lifts a ragged, glowing tear in it that stretches as it moves.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "background",
    "smoke",
    "noise",
    "veil",
    "glow",
    "canvas"
  ],
  "docs": "https://hyperblur.dev/effects/bg-dark-veil",
  "files": [
    {
      "path": "registry/hyperblur/bg-dark-veil.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/bg-dark-veil.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface BgDarkVeilProps extends React.HTMLAttributes<HTMLDivElement> {\n  accent?: string;\n  edgeColor?: string;\n  veilColor?: string;\n  opacity?: number;\n  tearRadius?: number;\n  grain?: number;\n  speed?: number;\n}\n\nconst css = `\n.hb-qq2 { position: absolute; inset: 0; overflow: hidden; pointer-events: none; box-sizing: border-box; }\n.hb-qq2-c { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }\n.hb-qq2-in { position: relative; z-index: 1; width: 100%; height: 100%; pointer-events: auto; font-family: inherit; }\n`;\n\nfunction qq2Rgb(color: string, fallback: [number, number, number]): [number, number, number] {\n  const m = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(color.trim());\n  if (!m) return fallback;\n  let s = m[1];\n  if (s.length === 3) s = s[0] + s[0] + s[1] + s[1] + s[2] + s[2];\n  const v = parseInt(s, 16);\n  return [(v >> 16) & 255, (v >> 8) & 255, v & 255];\n}\n\nfunction qq2Lattice(x: number, y: number) {\n  let n = Math.imul(x | 0, 374761393) + Math.imul(y | 0, 668265263);\n  n = Math.imul(n ^ (n >>> 13), 1274126177);\n  n ^= n >>> 16;\n  return (n >>> 0) / 4294967296;\n}\n\nfunction qq2Noise(x: number, y: number) {\n  const ix = Math.floor(x);\n  const iy = Math.floor(y);\n  const fx = x - ix;\n  const fy = y - iy;\n  const ux = fx * fx * (3 - 2 * fx);\n  const uy = fy * fy * (3 - 2 * fy);\n  const a = qq2Lattice(ix, iy);\n  const b = qq2Lattice(ix + 1, iy);\n  const c = qq2Lattice(ix, iy + 1);\n  const d = qq2Lattice(ix + 1, iy + 1);\n  return a + (b - a) * ux + (c - a) * uy + (a - b - c + d) * ux * uy;\n}\n\nfunction qq2Fbm(x: number, y: number) {\n  return qq2Noise(x, y) * 0.55 + qq2Noise(x * 2.03 + 17.1, y * 2.03 - 9.2) * 0.3 + qq2Noise(x * 4.1 - 3.7, y * 4.1 + 5.3) * 0.15;\n}\n\nexport function BgDarkVeil({\n  accent = \"#2f7bff\",\n  edgeColor = \"#a64dff\",\n  veilColor = \"#06070a\",\n  opacity = 0.94,\n  tearRadius = 70,\n  grain = 0.04,\n  speed = 1,\n  className = \"\",\n  style,\n  children,\n  ...rest\n}: BgDarkVeilProps) {\n  const wrapRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n\n  React.useEffect(() => {\n    const wrap = wrapRef.current;\n    const host = wrap?.parentElement;\n    const canvas = canvasRef.current;\n    const ctx = canvas?.getContext(\"2d\");\n    const veil = document.createElement(\"canvas\");\n    const vctx = veil.getContext(\"2d\");\n    if (!wrap || !host || !canvas || !ctx || !vctx) return;\n\n    const [vr, vg, vb] = qq2Rgb(veilColor, [6, 7, 10]);\n    const [ar, ag, ab] = qq2Rgb(accent, [47, 123, 255]);\n    const [er, eg, eb] = qq2Rgb(edgeColor, [166, 77, 255]);\n    const baseAlpha = Math.min(1, Math.max(0.3, opacity));\n\n    let w = 0;\n    let h = 0;\n    let t = 0;\n    let cols = 0;\n    let rows = 0;\n    let cell = 6;\n    let img: ImageData | null = null;\n    let inside = false;\n    let tx = 0;\n    let ty = 0;\n    let px = 0;\n    let py = 0;\n    let vx = 0;\n    let vy = 0;\n    let act = 0;\n    let placed = false;\n\n    function idleX(tt: number) {\n      return w * (0.5 + 0.32 * Math.sin(tt * 0.27 + 0.4) + 0.06 * Math.sin(tt * 0.9));\n    }\n    function idleY(tt: number) {\n      return h * (0.5 + 0.22 * Math.sin(tt * 0.41 + 2.2));\n    }\n\n    function track(dt: number) {\n      const gx = inside ? tx : idleX(t);\n      const gy = inside ? ty : idleY(t);\n      if (!placed) {\n        px = gx;\n        py = gy;\n        placed = true;\n        return;\n      }\n      const k = 1 - Math.exp(-dt * (inside ? 9 : 1.6));\n      const nx = px + (gx - px) * k;\n      const ny = py + (gy - py) * k;\n      if (dt > 0) {\n        const kv = 1 - Math.exp(-dt * 6);\n        vx += ((nx - px) / dt - vx) * kv;\n        vy += ((ny - py) / dt - vy) * kv;\n      }\n      px = nx;\n      py = ny;\n      act += ((inside ? 1 : 0) - act) * (1 - Math.exp(-dt * 2.5));\n    }\n\n    function render() {\n      if (!img || !vctx) return;\n      const data = img.data;\n      const s = 1 / Math.max(80, Math.min(w, h) * 0.55);\n      const tt = t * 0.09;\n      const gpx = px / cell;\n      const gpy = py / cell;\n      const sp = Math.hypot(vx, vy);\n      const dirx = sp > 1 ? vx / sp : 1;\n      const diry = sp > 1 ? vy / sp : 0;\n      const stretch = 1 + Math.min(1.2, sp / 600);\n      const lift = 0.45 + 0.55 * act + 0.12 * Math.sin(t * 1.3);\n      const rad = (tearRadius * (0.75 + 0.35 * act)) / cell;\n      for (let j = 0; j < rows; j++) {\n        const yy = j * cell;\n        const ey = Math.min(j, rows - 1 - j) / Math.max(1, rows * 0.5);\n        for (let i = 0; i < cols; i++) {\n          const xx = i * cell;\n          const sx = xx * s;\n          const sy = yy * s;\n          const wx = qq2Noise(sx * 1.3 + tt, sy * 1.3 - tt * 0.6) - 0.5;\n          const wy = qq2Noise(sx * 1.3 - 4.1 - tt * 0.5, sy * 1.3 + 7.7 + tt) - 0.5;\n          const n = qq2Fbm(sx * 2.2 + wx * 1.6 + tt * 0.7, sy * 2.2 + wy * 1.6 - tt * 0.4);\n          const ex = Math.min(i, cols - 1 - i) / Math.max(1, cols * 0.5);\n          const edge = Math.max(0, 1 - Math.min(ex * 1.6, ey * 1.3));\n          const band = Math.max(0, 1 - Math.abs(n - 0.55) * 4.5);\n          const ddx = i - gpx;\n          const ddy = j - gpy;\n          const along = ddx * dirx + ddy * diry;\n          const across = -ddx * diry + ddy * dirx;\n          const d = Math.sqrt((along * along) / (stretch * stretch) + across * across);\n          const ragged = rad * (0.7 + 0.6 * n);\n          let tear = d < ragged ? 1 - d / ragged : 0;\n          tear = tear * tear * (3 - 2 * tear) * lift;\n          const rim = Math.max(0, 1 - Math.abs(d - ragged) / Math.max(1.5, rad * 0.35)) * lift;\n          const shade = 0.55 + n * 0.9;\n          const g = (qq2Lattice(i + ((t * 24) | 0), j) - 0.5) * grain * 255;\n          const tintE = edge * band * 0.55;\n          const tintR = rim * 0.75;\n          let r = vr * shade + er * tintE + ar * tintR + g;\n          let gg = vg * shade + eg * tintE + ag * tintR + g;\n          let b = vb * shade + eb * tintE + ab * tintR + g;\n          r = r < 0 ? 0 : r > 255 ? 255 : r;\n          gg = gg < 0 ? 0 : gg > 255 ? 255 : gg;\n          b = b < 0 ? 0 : b > 255 ? 255 : b;\n          let a = baseAlpha * (0.82 + 0.18 * n) - edge * band * 0.28 - tear * 0.92;\n          a = a < 0 ? 0 : a > 1 ? 1 : a;\n          const o = (j * cols + i) * 4;\n          data[o] = r;\n          data[o + 1] = gg;\n          data[o + 2] = b;\n          data[o + 3] = a * 255;\n        }\n      }\n      vctx.putImageData(img, 0, 0);\n    }\n\n    function draw() {\n      if (!ctx || !w || !h) return;\n      ctx.clearRect(0, 0, w, h);\n      const R = Math.max(w, h);\n      const base = ctx.createLinearGradient(0, 0, w, h);\n      base.addColorStop(0, edgeColor);\n      base.addColorStop(0.5, \"#05060a\");\n      base.addColorStop(1, accent);\n      ctx.globalAlpha = 0.55;\n      ctx.fillStyle = base;\n      ctx.fillRect(0, 0, w, h);\n      ctx.globalAlpha = 1;\n      const glowR = tearRadius * (1.6 + 0.6 * act);\n      const glow = ctx.createRadialGradient(px, py, 0, px, py, glowR);\n      glow.addColorStop(0, \"#ffffff\");\n      glow.addColorStop(0.18, accent);\n      glow.addColorStop(0.6, edgeColor);\n      glow.addColorStop(1, \"rgba(0,0,0,0)\");\n      ctx.globalCompositeOperation = \"lighter\";\n      ctx.globalAlpha = 0.75;\n      ctx.fillStyle = glow;\n      ctx.fillRect(px - R, py - R, R * 2, R * 2);\n      ctx.globalCompositeOperation = \"source-over\";\n      ctx.globalAlpha = 1;\n      render();\n      ctx.imageSmoothingEnabled = true;\n      ctx.imageSmoothingQuality = \"high\";\n      ctx.drawImage(veil, 0, 0, cols, rows, -cell / 2, -cell / 2, cols * cell, rows * cell);\n    }\n\n    function resize() {\n      if (!wrap || !canvas || !ctx || !vctx) return;\n      const nw = wrap.clientWidth;\n      const nh = wrap.clientHeight;\n      if (!nw || !nh) return;\n      const dpr = Math.min(2, window.devicePixelRatio || 1);\n      w = nw;\n      h = nh;\n      canvas.width = Math.max(1, Math.round(w * dpr));\n      canvas.height = Math.max(1, Math.round(h * dpr));\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      cell = 5;\n      while ((w / cell + 2) * (h / cell + 2) > 16000) cell *= 1.2;\n      cols = Math.ceil(w / cell) + 2;\n      rows = Math.ceil(h / cell) + 2;\n      veil.width = cols;\n      veil.height = rows;\n      img = vctx.createImageData(cols, rows);\n      if (motion.matches) still();\n      else {\n        track(0);\n        draw();\n      }\n    }\n\n    const motion = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    let visible = true;\n    let raf = 0;\n    let prev = 0;\n\n    function still() {\n      t = 4;\n      inside = false;\n      placed = false;\n      act = 0;\n      vx = 0;\n      vy = 0;\n      track(0);\n      draw();\n    }\n\n    function frame(now: number) {\n      const dt = Math.min(0.033, (now - prev) / 1000);\n      prev = now;\n      t += dt * speed;\n      track(dt);\n      draw();\n      raf = requestAnimationFrame(frame);\n    }\n\n    function sync() {\n      const run = visible && !document.hidden && !motion.matches;\n      if (run && !raf) {\n        prev = performance.now();\n        raf = requestAnimationFrame(frame);\n      } else if (!run && raf) {\n        cancelAnimationFrame(raf);\n        raf = 0;\n      }\n      if (motion.matches) still();\n    }\n\n    function move(e: PointerEvent) {\n      if (!wrap || motion.matches) return;\n      const rect = wrap.getBoundingClientRect();\n      const kx = rect.width ? wrap.clientWidth / rect.width : 1;\n      const ky = rect.height ? wrap.clientHeight / rect.height : 1;\n      tx = (e.clientX - rect.left) * kx;\n      ty = (e.clientY - rect.top) * ky;\n      inside = true;\n    }\n\n    function leave(e: PointerEvent) {\n      if (e.type === \"pointerup\" && e.pointerType === \"mouse\") return;\n      inside = false;\n    }\n\n    const ro = new ResizeObserver(resize);\n    const io = new IntersectionObserver((entries) => {\n      visible = entries[entries.length - 1].isIntersecting;\n      sync();\n    });\n    ro.observe(wrap);\n    io.observe(wrap);\n    document.addEventListener(\"visibilitychange\", sync);\n    motion.addEventListener(\"change\", sync);\n    host.addEventListener(\"pointermove\", move, { passive: true });\n    host.addEventListener(\"pointerdown\", move, { passive: true });\n    host.addEventListener(\"pointerleave\", leave);\n    host.addEventListener(\"pointerup\", leave);\n    host.addEventListener(\"pointercancel\", leave);\n    resize();\n    sync();\n\n    return () => {\n      if (raf) cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      document.removeEventListener(\"visibilitychange\", sync);\n      motion.removeEventListener(\"change\", sync);\n      host.removeEventListener(\"pointermove\", move);\n      host.removeEventListener(\"pointerdown\", move);\n      host.removeEventListener(\"pointerleave\", leave);\n      host.removeEventListener(\"pointerup\", leave);\n      host.removeEventListener(\"pointercancel\", leave);\n    };\n  }, [accent, edgeColor, veilColor, opacity, tearRadius, grain, speed]);\n\n  return (\n    <div ref={wrapRef} className={`hb-qq2 ${className}`} style={style} {...rest}>\n      <style href=\"hb-bg-dark-veil\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-qq2-c\" aria-hidden=\"true\" />\n      {children ? <div className=\"hb-qq2-in\">{children}</div> : null}\n    </div>\n  );\n}\n"
    }
  ]
}