{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "goo-cursor",
  "type": "registry:component",
  "title": "Goo Cursor",
  "description": "A translucent jelly cursor with a specular highlight: it drags droplets behind it that stretch into a trail and melt back into it when you stop.",
  "author": "Marcelo Treviño Velázquez <https://furin.dev>",
  "dependencies": [],
  "categories": [
    "Cursors"
  ],
  "docs": "Installed in components/furin/goo-cursor/. Docs, live controls and props table: https://furin.dev/components/goo-cursor/",
  "files": [
    {
      "path": "registry/goo-cursor/GooCursor.tsx",
      "content": "\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport type { CSSProperties, ReactNode } from \"react\";\nimport \"./GooCursor.css\";\n\nexport interface GooCursorProps {\n  /** Color de la gelatina. */\n  color?: string;\n  /** Radio de la gota principal, en px. */\n  size?: number;\n  /** Cuántas gotas siguen al cursor (máx. 9). */\n  drops?: number;\n  /** Oculta el cursor del sistema dentro del contenedor. */\n  hideCursor?: boolean;\n  /** Sigue al cursor en toda la ventana en vez de solo en el contenedor. */\n  global?: boolean;\n  /** Se pasea solo cuando nadie mueve el cursor. */\n  autoplay?: boolean;\n  /** Contenido que queda debajo del cursor. */\n  children?: ReactNode;\n  /** Clase extra para el contenedor. */\n  className?: string;\n  /** Estilos extra para el contenedor. */\n  style?: CSSProperties;\n}\n\nlet colorCtx: CanvasRenderingContext2D | null = null;\nfunction rgb(color: string): [number, number, number] {\n  colorCtx ??= document.createElement(\"canvas\").getContext(\"2d\", { willReadFrequently: true })!;\n  colorCtx.clearRect(0, 0, 1, 1);\n  colorCtx.fillStyle = \"#000\";\n  colorCtx.fillStyle = color;\n  colorCtx.fillRect(0, 0, 1, 1);\n  const d = colorCtx.getImageData(0, 0, 1, 1).data;\n  return [d[0] / 255, d[1] / 255, d[2] / 255];\n}\n\nconst N = 10;\nconst VS = `attribute vec2 a; void main(){ gl_Position = vec4(a, 0.0, 1.0); }`;\n\nconst FS = `precision highp float;\nuniform vec2 uRes;\nuniform float uDpr;\nuniform vec3 uB[${N}];\nuniform vec3 uColor;\n\nvec3 ball(vec2 q, vec3 b){\n  if (b.z < 0.2) return vec3(0.0);\n  vec2 d = q - b.xy;\n  float R = b.z * 2.45;\n  float k = dot(d, d) / (R * R);\n  if (k >= 1.0) return vec3(0.0);\n  float m = 1.0 - k;\n  return vec3(m * m * m, -6.0 * m * m * d / (R * R));\n}\n\nvoid main(){\n  vec2 q = vec2(gl_FragCoord.x, uRes.y - gl_FragCoord.y) / uDpr;\n  vec3 f = vec3(0.0);\n  for (int i = 0; i < ${N}; i++) f += ball(q, uB[i]);\n  float T = 0.46;\n  float g = length(f.yz) + 1e-5;\n  float edge = clamp((f.x - T) / (g / uDpr * 1.1), -1.0, 1.0) * 0.5 + 0.5;\n  // aura suave alrededor de la gelatina\n  float halo = smoothstep(0.0, T, f.x) * (1.0 - edge);\n  if (edge < 0.003 && halo < 0.003) { gl_FragColor = vec4(0.0); return; }\n  float depth = clamp((f.x - T) / 0.5, 0.0, 1.0);\n  float nz = pow(depth, 0.5);\n  vec2 nxy = normalize(-f.yz) * sqrt(max(1.0 - nz * nz, 0.0));\n  vec3 n = vec3(nxy, nz);\n  vec3 L = normalize(vec3(-0.45, -0.65, 0.62));\n  vec3 V = vec3(0.0, 0.0, 1.0);\n  float diff = max(dot(n, L), 0.0);\n  // la luz atraviesa la gelatina y se junta del lado opuesto\n  float trans = pow(max(dot(n.xy, -L.xy) / max(length(L.xy), 1e-3), 0.0), 2.0) * (1.0 - nz * 0.5);\n  vec3 body = mix(uColor * 0.50, uColor * 1.12, pow(depth, 0.7));\n  vec3 col = body * (0.55 + 0.55 * diff);\n  col += uColor * 0.55 * trans * (0.5 + 0.5 * depth);\n  col += mix(uColor, vec3(1.0), 0.65) * pow(1.0 - nz, 2.6) * 0.55;\n  float s1 = pow(max(dot(n, normalize(L + V)), 0.0), 90.0);\n  float s2 = pow(max(dot(n, normalize(L + V)), 0.0), 16.0);\n  col += vec3(1.0) * (s1 * 1.25 + s2 * 0.18);\n  // reflejo de la ventana: pequeño punto suave arriba a la izquierda\n  col += vec3(1.0) * 0.5 * pow(max(dot(n, normalize(vec3(-0.6, -0.7, 0.55))), 0.0), 40.0);\n  vec4 gel = vec4(col * edge, edge);\n  vec4 aura = vec4(uColor * halo * 0.20, halo * 0.20);\n  gl_FragColor = gel + aura * (1.0 - gel.a);\n}`;\n\n/** Cursor de gelatina: una cadena de gotas con resortes encadenados, fundidas como metaballs con luz y brillo. */\nexport function GooCursor({\n  color = \"#4D7CFF\",\n  size = 14,\n  drops = 8,\n  hideCursor = true,\n  global = false,\n  autoplay = false,\n  children,\n  className = \"\",\n  style,\n}: GooCursorProps) {\n  const host = useRef<HTMLDivElement>(null);\n  const live = useRef({ color, size, drops, autoplay });\n  live.current = { color, size, drops, autoplay };\n  const wakeRef = useRef<() => void>(() => {});\n\n  useEffect(() => {\n    const el = host.current;\n    if (!el) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const canvas = document.createElement(\"canvas\");\n    canvas.className = `furin-goo-cursor__canvas${global ? \" furin-goo-cursor__canvas--global\" : \"\"}`;\n    canvas.setAttribute(\"aria-hidden\", \"true\");\n    (global ? document.body : el).appendChild(canvas);\n    const gl = canvas.getContext(\"webgl\", { antialias: false, alpha: true, premultipliedAlpha: true });\n    if (!gl) {\n      canvas.remove();\n      return;\n    }\n    const compile = (type: number, src: string) => {\n      const s = gl.createShader(type)!;\n      gl.shaderSource(s, src);\n      gl.compileShader(s);\n      if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) console.error(\"[goo-cursor] shader:\", gl.getShaderInfoLog(s));\n      return s;\n    };\n    const prog = gl.createProgram()!;\n    gl.attachShader(prog, compile(gl.VERTEX_SHADER, VS));\n    gl.attachShader(prog, compile(gl.FRAGMENT_SHADER, FS));\n    gl.linkProgram(prog);\n    if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) console.error(\"[goo-cursor] link:\", gl.getProgramInfoLog(prog));\n    gl.useProgram(prog);\n    const quad = gl.createBuffer()!;\n    gl.bindBuffer(gl.ARRAY_BUFFER, quad);\n    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);\n    const loc = gl.getAttribLocation(prog, \"a\");\n    gl.enableVertexAttribArray(loc);\n    gl.vertexAttribPointer(loc, 2, gl.FLOAT, false, 0, 0);\n    const U = { res: gl.getUniformLocation(prog, \"uRes\"), dpr: gl.getUniformLocation(prog, \"uDpr\"), b: gl.getUniformLocation(prog, \"uB\"), color: gl.getUniformLocation(prog, \"uColor\") };\n    gl.enable(gl.BLEND);\n    gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);\n    gl.enable(gl.SCISSOR_TEST);\n\n    // Cadena de gotas: cada una persigue a la anterior con un resorte más flojo.\n    const K = [30, 24, 19, 15.5, 13, 11, 9.5, 8.2, 7, 6];\n    const bx = new Float32Array(N);\n    const by = new Float32Array(N);\n    const buf = new Float32Array(N * 3);\n    let W = 1, H = 1, dpr = 1, ox = 0, oy = 0;\n    let tx = 0, ty = 0, inside = false, placed = false;\n    let appear = live.current.autoplay && !reduce ? 1 : 0;\n    let press = 1, pressV = 0, pressT = 1;\n    let time = 0, last = 0, raf = 0, visible = true;\n    let colKey = \"\", col: [number, number, number] = [0.3, 0.5, 1];\n    let lastReal = -1e9;\n    let drawn = false;\n\n    const resize = () => {\n      dpr = Math.min(window.devicePixelRatio || 1, 2);\n      const r = global ? { width: window.innerWidth, height: window.innerHeight } : el.getBoundingClientRect();\n      W = Math.max(1, r.width);\n      H = Math.max(1, r.height);\n      canvas.width = Math.max(2, Math.round(W * dpr));\n      canvas.height = Math.max(2, Math.round(H * dpr));\n      gl.viewport(0, 0, canvas.width, canvas.height);\n      drawn = false;\n    };\n    const origin = () => {\n      if (global) {\n        ox = 0;\n        oy = 0;\n      } else {\n        const r = el.getBoundingClientRect();\n        ox = r.left;\n        oy = r.top;\n      }\n    };\n\n    const draw = () => {\n      if (colKey !== live.current.color) {\n        colKey = live.current.color;\n        col = rgb(colKey);\n      }\n      gl.disable(gl.SCISSOR_TEST);\n      gl.clearColor(0, 0, 0, 0);\n      gl.clear(gl.COLOR_BUFFER_BIT);\n      gl.enable(gl.SCISSOR_TEST);\n      const R = live.current.size * appear * Math.max(0.2, press);\n      if (R < 0.4) return;\n      const nd = Math.max(0, Math.min(N - 1, Math.round(live.current.drops)));\n      let minX = 1e9, minY = 1e9, maxX = -1e9, maxY = -1e9;\n      for (let i = 0; i < N; i++) {\n        let r = 0;\n        if (i === 0) r = R;\n        else if (i <= nd) {\n          const dHead = Math.hypot(bx[i] - bx[0], by[i] - by[0]);\n          // las gotas solo existen cuando se separan de la cabeza; pegadas, se funden con ella\n          const s = Math.min(1, Math.max(0, (dHead - R * 0.15) / (R * 1.3)));\n          r = R * (0.92 - i * 0.065) * s * s * (3 - 2 * s);\n        }\n        buf[i * 3] = bx[i];\n        buf[i * 3 + 1] = by[i];\n        buf[i * 3 + 2] = r;\n        if (r > 0.2) {\n          minX = Math.min(minX, bx[i] - r * 2.2);\n          maxX = Math.max(maxX, bx[i] + r * 2.2);\n          minY = Math.min(minY, by[i] - r * 2.2);\n          maxY = Math.max(maxY, by[i] + r * 2.2);\n        }\n      }\n      if (maxX < minX) return;\n      const sx = Math.max(0, Math.floor(minX * dpr));\n      const sy = Math.max(0, Math.floor((H - maxY) * dpr));\n      const sw = Math.min(canvas.width - sx, Math.ceil((maxX - minX) * dpr) + 2);\n      const sh = Math.min(canvas.height - sy, Math.ceil((maxY - minY) * dpr) + 2);\n      if (sw <= 0 || sh <= 0) return;\n      gl.scissor(sx, sy, sw, sh);\n      gl.uniform2f(U.res, canvas.width, canvas.height);\n      gl.uniform1f(U.dpr, dpr);\n      gl.uniform3fv(U.b, buf);\n      gl.uniform3f(U.color, col[0], col[1], col[2]);\n      gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);\n      drawn = true;\n    };\n\n    const frame = (nowMs: number) => {\n      raf = 0;\n      const dt = Math.min(0.05, Math.max(0.001, (nowMs - last) / 1000));\n      last = nowMs;\n      time += dt;\n      const auto = live.current.autoplay && !reduce && (!inside || nowMs - lastReal > 2500);\n      if (auto) {\n        // paseo en ocho, para que la demo se entienda sola\n        const t = time * 1.15;\n        tx = W * (0.5 + 0.32 * Math.sin(t)) ;\n        ty = H * (0.5 + 0.26 * Math.sin(t * 2 + 0.6));\n        if (!placed) {\n          for (let i = 0; i < N; i++) {\n            bx[i] = tx;\n            by[i] = ty;\n          }\n          placed = true;\n        }\n      }\n      const show = inside || auto;\n      appear += ((show ? 1 : 0) - appear) * (1 - Math.exp(-dt * (show ? 14 : 9)));\n      if (Math.abs(appear - (show ? 1 : 0)) < 0.004) appear = show ? 1 : 0;\n      // gelatina que rebota al presionar\n      pressV += ((pressT - press) * 190 - pressV * 11) * dt;\n      press += pressV * dt;\n      if (reduce) {\n        for (let i = 0; i < N; i++) {\n          bx[i] = tx;\n          by[i] = ty;\n        }\n      } else {\n        bx[0] += (tx - bx[0]) * (1 - Math.exp(-dt * K[0]));\n        by[0] += (ty - by[0]) * (1 - Math.exp(-dt * K[0]));\n        for (let i = 1; i < N; i++) {\n          bx[i] += (bx[i - 1] - bx[i]) * (1 - Math.exp(-dt * K[i]));\n          by[i] += (by[i - 1] - by[i]) * (1 - Math.exp(-dt * K[i]));\n        }\n      }\n      draw();\n      let moving = Math.abs(press - pressT) > 0.003 || Math.abs(pressV) > 0.01 || Math.abs(appear - (show ? 1 : 0)) > 0.004;\n      for (let i = 0; i < N && !moving; i++) if (Math.abs(bx[i] - tx) > 0.15 || Math.abs(by[i] - ty) > 0.15) moving = true;\n      if ((moving || auto) && visible) raf = requestAnimationFrame(frame);\n      else if (!show && drawn) {\n        // todo quieto y escondido: deja el lienzo limpio\n        gl.disable(gl.SCISSOR_TEST);\n        gl.clear(gl.COLOR_BUFFER_BIT);\n        gl.enable(gl.SCISSOR_TEST);\n        drawn = false;\n      }\n    };\n    const wake = () => {\n      if (raf || !visible) return;\n      last = performance.now();\n      raf = requestAnimationFrame(frame);\n    };\n    wakeRef.current = wake;\n\n    const target: EventTarget = global ? window : el;\n    const onMove = (e: Event) => {\n      const pe = e as PointerEvent;\n      origin();\n      tx = pe.clientX - ox;\n      ty = pe.clientY - oy;\n      lastReal = performance.now();\n      inside = true;\n      if (!placed || appear < 0.05) {\n        for (let i = 0; i < N; i++) {\n          bx[i] = tx;\n          by[i] = ty;\n        }\n        placed = true;\n      }\n      wake();\n    };\n    const onLeave = () => {\n      inside = false;\n      wake();\n    };\n    const onDown = (e: Event) => {\n      onMove(e);\n      pressT = 1.38;\n      wake();\n    };\n    const onUp = () => {\n      pressT = 1;\n      wake();\n    };\n    target.addEventListener(\"pointermove\", onMove);\n    target.addEventListener(\"pointerdown\", onDown);\n    target.addEventListener(\"pointerup\", onUp);\n    target.addEventListener(\"pointercancel\", onLeave);\n    if (global) document.documentElement.addEventListener(\"pointerleave\", onLeave);\n    else el.addEventListener(\"pointerleave\", onLeave);\n\n    const io = new IntersectionObserver(([en]) => {\n      visible = en.isIntersecting;\n      if (visible) wake();\n      else if (raf) {\n        cancelAnimationFrame(raf);\n        raf = 0;\n      }\n    });\n    io.observe(el);\n    const onResize = () => {\n      resize();\n      wake();\n    };\n    const ro = new ResizeObserver(onResize);\n    if (global) window.addEventListener(\"resize\", onResize);\n    else ro.observe(el);\n    resize();\n    origin();\n    if (live.current.autoplay && !reduce) wake();\n\n    return () => {\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      ro.disconnect();\n      window.removeEventListener(\"resize\", onResize);\n      target.removeEventListener(\"pointermove\", onMove);\n      target.removeEventListener(\"pointerdown\", onDown);\n      target.removeEventListener(\"pointerup\", onUp);\n      target.removeEventListener(\"pointercancel\", onLeave);\n      if (global) document.documentElement.removeEventListener(\"pointerleave\", onLeave);\n      else el.removeEventListener(\"pointerleave\", onLeave);\n      wakeRef.current = () => {};\n      gl.deleteBuffer(quad);\n      gl.deleteProgram(prog);\n      gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n      canvas.remove();\n    };\n  }, [global]);\n\n  useEffect(() => {\n    wakeRef.current();\n  }, [color, size, drops, autoplay]);\n\n  const cls = `furin-goo-cursor${hideCursor && !global ? \" furin-goo-cursor--sin-cursor\" : \"\"} ${className}`;\n  return (\n    <div ref={host} className={cls} style={style}>\n      <div className=\"furin-goo-cursor__contenido\">{children}</div>\n    </div>\n  );\n}\n\nexport default GooCursor;\n",
      "type": "registry:component",
      "target": "components/furin/goo-cursor/GooCursor.tsx"
    },
    {
      "path": "registry/goo-cursor/GooCursor.css",
      "content": ".furin-goo-cursor {\n  position: relative;\n  width: 100%;\n  height: 100%;\n  min-height: 200px;\n  overflow: hidden;\n  touch-action: pan-y;\n  color: rgba(255, 255, 255, 0.45);\n  font: 500 15px/1.4 system-ui, -apple-system, sans-serif;\n  user-select: none;\n}\n.furin-goo-cursor--sin-cursor, .furin-goo-cursor--sin-cursor * { cursor: none; }\n.furin-goo-cursor__contenido { position: relative; width: 100%; height: 100%; display: grid; place-items: center; }\n.furin-goo-cursor__canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; z-index: 2; }\n.furin-goo-cursor__canvas--global { position: fixed; z-index: 2147483000; }\n",
      "type": "registry:file",
      "target": "components/furin/goo-cursor/GooCursor.css"
    }
  ]
}
