{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "fluid-ink-cursor",
  "title": "Fluid Ink Cursor",
  "description": "A background where the pointer paints with ink: drops pool along your path, merge into one another, blend between colours like marbled paper, bleed into the paper's grain at the edges, and slowly spread and fade away.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/fluid-ink-cursor/fluid-ink-cursor.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 FluidInkCursorProps extends React.ComponentPropsWithoutRef<\"div\"> {\n  /** Ink colours; neighbouring drops blend between them like marbled paper. */\n  colors?: [string, string, string, string];\n  /** The paper the ink lands on. */\n  paper?: string;\n  /** Drop size in px. */\n  size?: number;\n  /** Seconds before a drop has spread out and faded. */\n  life?: number;\n}\n\n// Enough drops for a long sweep across the screen; each pixel loops over all of them, so the canvas renders at 1x.\nconst MAX = 96;\n\nconst VERTEX = `attribute vec2 aPos;\nvoid main() { gl_Position = vec4(aPos, 0.0, 1.0); }`;\n\nconst FRAGMENT = `precision mediump float;\nuniform vec2 uRes;\nuniform float uTime;\nuniform vec4 uDrops[${MAX}];\nuniform float uTone[${MAX}];\nuniform vec3 uPaper;\nuniform vec3 uC0;\nuniform vec3 uC1;\nuniform vec3 uC2;\nuniform vec3 uC3;\nfloat hash(vec2 p) { p = fract(p * vec2(123.34, 456.21)); p += dot(p, p + 45.32); return fract(p.x * p.y); }\nfloat noise(vec2 p) {\n  vec2 i = floor(p); vec2 f = fract(p); 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}\nvec3 ramp(float x) {\n  x = fract(x) * 4.0;\n  if (x < 1.0) return mix(uC0, uC1, x);\n  if (x < 2.0) return mix(uC1, uC2, x - 1.0);\n  if (x < 3.0) return mix(uC2, uC3, x - 2.0);\n  return mix(uC3, uC0, x - 3.0);\n}\nvoid main() {\n  vec2 p = gl_FragCoord.xy;\n  float field = 0.0;\n  vec3 tint = vec3(0.0);\n  float wsum = 0.0;\n  for (int i = 0; i < ${MAX}; i++) {\n    vec4 d = uDrops[i];\n    if (d.z <= 0.0) continue;\n    vec2 v = p - d.xy;\n    // A gaussian per drop: strokes stay close to the path instead of ballooning where drops overlap.\n    float f = exp(-dot(v, v) / (d.z * d.z)) * d.w;\n    field += f;\n    tint += ramp(uTone[i]) * f;\n    wsum += f;\n  }\n  vec3 ink = tint / max(wsum, 1e-4);\n  // Ragged, bleeding edges: the threshold wobbles with fine noise, like ink soaking into fibres.\n  float grain = noise(p * 0.09 + uTime * 0.2) * 0.5 + noise(p * 0.35) * 0.2;\n  float thr = 0.42 + grain * 0.22;\n  float edge = smoothstep(thr, thr + 0.12, field);\n  // Like watercolour, pigment pools in a darker line along the edge and thins toward the middle.\n  float rim = 1.0 - smoothstep(thr + 0.05, thr + 0.6, field);\n  vec3 col = mix(ink * 1.12, ink * 0.62, rim);\n  vec3 paper = uPaper * (0.97 + 0.06 * noise(p * 0.6));\n  gl_FragColor = vec4(mix(paper, col, edge * 0.95), 1.0);\n}`;\n\nfunction rgb(hex: string): [number, number, number] {\n  const h = hex.replace(\"#\", \"\");\n  const full = h.length === 3 ? h.split(\"\").map((c) => c + c).join(\"\") : 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\ntype Drop = { x: number; y: number; r: number; born: number; tone: number };\n\nexport function FluidInkCursor({ colors = [\"#1d3fbb\", \"#0a7f86\", \"#c2185b\", \"#1a1a2e\"], paper = \"#f3efe6\", size = 22, life = 2.6, className, style, children, ...props }: FluidInkCursorProps) {\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  const live = React.useRef({ colors, paper, size, life });\n  React.useEffect(() => {\n    live.current = { colors, paper, size, life };\n  }, [colors, paper, size, life]);\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const canvas = canvasRef.current;\n    if (!root || !canvas || reduce) return;\n    const gl = canvas.getContext(\"webgl\", { antialias: false, premultipliedAlpha: false });\n    const fail = () => requestAnimationFrame(() => setFailed(true));\n    if (!gl) {\n      fail();\n      return;\n    }\n    const make = (type: number, src: string) => {\n      const s = gl.createShader(type)!;\n      gl.shaderSource(s, src);\n      gl.compileShader(s);\n      return gl.getShaderParameter(s, gl.COMPILE_STATUS) ? s : null;\n    };\n    const vs = make(gl.VERTEX_SHADER, VERTEX);\n    const fs = make(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 = (n: string) => gl.getUniformLocation(program, n);\n    const uRes = u(\"uRes\");\n    const uTime = u(\"uTime\");\n    const uDrops = u(\"uDrops\");\n    const uTone = u(\"uTone\");\n    const tones = new Float32Array(MAX);\n    let tone = Math.random();\n    const uPaper = u(\"uPaper\");\n    const uC = [u(\"uC0\"), u(\"uC1\"), u(\"uC2\"), u(\"uC3\")];\n\n    const drops: Drop[] = [];\n    const data = new Float32Array(MAX * 4);\n    let next = 0;\n    let dpr = 1;\n    let raf = 0;\n    let running = false;\n    const last = { x: -1, y: -1 };\n\n    const resize = () => {\n      dpr = 1;\n      canvas.width = Math.max(1, Math.round(root.clientWidth * dpr));\n      canvas.height = Math.max(1, Math.round(root.clientHeight * dpr));\n      gl.viewport(0, 0, canvas.width, canvas.height);\n    };\n    const draw = (now: number) => {\n      const L = live.current;\n      data.fill(0);\n      let alive = 0;\n      for (let i = 0; i < MAX; i++) {\n        const d = drops[i];\n        if (!d) continue;\n        const age = (now - d.born) / 1000 / L.life;\n        if (age >= 1) continue;\n        alive++;\n        // Ink spreads out as it soaks in, then fades.\n        data[i * 4] = d.x * dpr;\n        data[i * 4 + 1] = (root.clientHeight - d.y) * dpr;\n        data[i * 4 + 2] = d.r * dpr * (1 + age * 1.1);\n        data[i * 4 + 3] = Math.pow(1 - age, 1.6);\n        tones[i] = d.tone;\n      }\n      gl.uniform2f(uRes, canvas.width, canvas.height);\n      gl.uniform1f(uTime, now / 1000);\n      gl.uniform4fv(uDrops, data);\n      gl.uniform1fv(uTone, tones);\n      gl.uniform3fv(uPaper, rgb(L.paper));\n      L.colors.forEach((c, i) => gl.uniform3fv(uC[i], rgb(c)));\n      gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);\n      return alive;\n    };\n    const tick = (now: number) => {\n      const alive = draw(now);\n      if (alive > 0) raf = requestAnimationFrame(tick);\n      else running = false;\n    };\n    const kick = () => {\n      if (!running) {\n        running = true;\n        raf = requestAnimationFrame(tick);\n      }\n    };\n    const onMove = (event: PointerEvent) => {\n      const r = root.getBoundingClientRect();\n      const scale = r.width / root.offsetWidth || 1;\n      const x = (event.clientX - r.left) / scale;\n      const y = (event.clientY - r.top) / scale;\n      const dist = last.x < 0 ? 999 : Math.hypot(x - last.x, y - last.y);\n      const step = live.current.size * 0.7;\n      if (dist < step) return;\n      // Fill the gap with evenly spaced drops; faster strokes lay down thinner ink.\n      const n = last.x < 0 ? 1 : Math.min(10, Math.floor(dist / step));\n      const thin = Math.max(0.55, 1 - dist / 260);\n      for (let k = 1; k <= n; k++) {\n        const t = k / n;\n        // The colour drifts slowly along the stroke, so neighbouring drops share a tone and blend smoothly.\n        tone += 0.012;\n        drops[next] = { x: last.x < 0 ? x : last.x + (x - last.x) * t, y: last.y < 0 ? y : last.y + (y - last.y) * t, r: live.current.size * thin * (0.85 + Math.random() * 0.3), born: performance.now(), tone };\n        next = (next + 1) % MAX;\n      }\n      last.x = x;\n      last.y = y;\n      kick();\n    };\n    const onLeave = () => {\n      last.x = -1;\n      last.y = -1;\n    };\n    const ro = new ResizeObserver(() => {\n      resize();\n      draw(performance.now());\n    });\n    ro.observe(root);\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerleave\", onLeave);\n    resize();\n    draw(performance.now());\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n    };\n  }, [reduce]);\n\n  return (\n    <div ref={rootRef} className={cn(\"relative isolate overflow-hidden\", className)} style={{ background: paper, ...style }} {...props}>\n      {!reduce && !failed && <canvas ref={canvasRef} aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 -z-10 h-full w-full\" />}\n      {children}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}