{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chrome-liquid-logo",
  "title": "Chrome Liquid Logo",
  "description": "Your word or logotype cast in liquid chrome: the letters puff up like inflated metal, reflect a bright studio with a crisp horizon, ripple as liquid flows across them and around the pointer, in silver, gold, copper or any tint.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/chrome-liquid-logo/chrome-liquid-logo.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 ChromeLiquidLogoProps extends Omit<React.ComponentPropsWithoutRef<\"div\">, \"children\"> {\n  /** The word or short logotype to cast in chrome. Use \"\\n\" for a second line. */\n  text?: string;\n  /** CSS font weight and family for the letters. Heavier fonts take the chrome best. */\n  font?: string;\n  /** Background behind the letters. */\n  background?: string;\n  /** Tint of the metal: silver by default; gold, copper or any colour works. */\n  tint?: string;\n  /** How puffed up the letters are. */\n  inflate?: number;\n  /** Speed of the liquid flowing over the surface. */\n  speed?: number;\n  /** Pointer ripples across the metal. */\n  interactive?: boolean;\n}\n\nconst VERTEX = `attribute vec2 aPos;\nvoid main() { gl_Position = vec4(aPos, 0.0, 1.0); }`;\n\nconst FRAGMENT = `precision highp float;\nuniform sampler2D uMask;\nuniform sampler2D uHeight;\nuniform vec2 uRes;\nuniform float uTime;\nuniform vec2 uMouse;\nuniform float uHover;\nuniform float uInflate;\nuniform vec3 uBg;\nuniform vec3 uTint;\n\n// The height map is the letter mask blurred once on the CPU: letters bulge in the middle and roll off\n// at the edges like inflated metal.\nfloat puff(vec2 uv) { return texture2D(uHeight, uv).r; }\nvoid main() {\n  vec2 uv = gl_FragCoord.xy / uRes;\n  float t = uTime;\n  float mask = texture2D(uMask, uv).r;\n  // The height map is 8-bit: measure its slope across a few of its own texels (and diagonals too),\n  // so the tiny steps between levels don't show up as speckles in the reflections.\n  vec2 e = 6.0 / uRes;\n  float h = puff(uv);\n  vec2 g = vec2(puff(uv + vec2(e.x, 0.0)) - puff(uv - vec2(e.x, 0.0)), puff(uv + vec2(0.0, e.y)) - puff(uv - vec2(0.0, e.y)));\n  g += 0.5 * vec2(puff(uv + e) - puff(uv - e) + puff(uv + vec2(e.x, -e.y)) - puff(uv + vec2(-e.x, e.y)), puff(uv + e) - puff(uv - e) - puff(uv + vec2(e.x, -e.y)) + puff(uv + vec2(-e.x, e.y)));\n  g *= 0.125;\n  // Liquid flowing over the surface, plus ripples spreading from the pointer.\n  vec2 p = (gl_FragCoord.xy - 0.5 * uRes) / uRes.y;\n  vec2 m = (uMouse - 0.5) * vec2(uRes.x / uRes.y, 1.0);\n  vec2 flow = vec2(sin(p.y * 7.0 + t * 1.1 + sin(p.x * 4.0 - t * 0.7)), cos(p.x * 6.0 - t * 0.9 + sin(p.y * 5.0 + t * 0.5))) * 0.22;\n  float dm = length(p - m);\n  flow += normalize(p - m + 1e-4) * sin(dm * 60.0 - t * 7.0) * exp(-dm * 7.0) * 0.6 * uHover;\n  vec3 n = normalize(vec3(-g * 28.0 * uInflate + flow * smoothstep(0.1, 0.6, h), 1.0));\n  vec3 view = normalize(vec3((uv.x - 0.5) * 0.4, 0.1 + (uv.y - 0.5) * 0.5, -1.0));\n  vec3 rf = reflect(view, n);\n  float y = rf.y + rf.x * 0.1;\n  // A photographer's studio for the chrome to reflect: dark floor, crisp horizon, bright sky and softboxes.\n  vec3 env = mix(vec3(0.05), vec3(0.32), smoothstep(-0.6, 0.0, y));\n  env = mix(env, vec3(0.92), smoothstep(0.0, 0.55, y));\n  env += vec3(1.0) * smoothstep(0.035, 0.0, abs(y - 0.02)) * 0.9;\n  env -= 0.3 * smoothstep(0.0, -0.06, y) * smoothstep(-0.25, -0.06, y);\n  env += smoothstep(0.88, 0.98, dot(rf, normalize(vec3(-0.6, 0.65, 0.45)))) * 0.9;\n  env += smoothstep(0.86, 0.97, dot(rf, normalize(vec3(0.7, 0.5, 0.5)))) * 0.5;\n  float fres = 0.75 + 0.25 * pow(1.0 - abs(dot(n, -view)), 3.0);\n  vec3 metal = env * fres * uTint;\n  float edge = smoothstep(0.3, 0.6, mask);\n  vec3 col = mix(uBg, metal, edge);\n  gl_FragColor = vec4(col, 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\nexport function ChromeLiquidLogo({\n  text = \"LIQUID\",\n  font = \"900 1px 'Arial Black', 'Helvetica Neue', Helvetica, Arial, sans-serif\",\n  background = \"#0a0a0b\",\n  tint = \"#e9edf5\",\n  inflate = 1,\n  speed = 1,\n  interactive = true,\n  className,\n  style,\n  ...props\n}: ChromeLiquidLogoProps) {\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({ background, tint, inflate, speed, interactive, still: reduce });\n  const redraw = React.useRef<() => void>(() => {});\n  React.useEffect(() => {\n    live.current = { background, tint, inflate, speed, interactive, still: reduce };\n    redraw.current();\n  }, [background, tint, inflate, speed, interactive, reduce]);\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const canvas = canvasRef.current;\n    if (!root || !canvas) return;\n    const gl = canvas.getContext(\"webgl\", { antialias: true, 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 sh = gl.createShader(type)!;\n      gl.shaderSource(sh, src);\n      gl.compileShader(sh);\n      return gl.getShaderParameter(sh, gl.COMPILE_STATUS) ? sh : 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 U = { res: u(\"uRes\"), time: u(\"uTime\"), mouse: u(\"uMouse\"), hover: u(\"uHover\"), inflate: u(\"uInflate\"), bg: u(\"uBg\"), tint: u(\"uTint\") };\n    const makeTexture = (unit: number, name: string) => {\n      const tex = gl.createTexture();\n      gl.activeTexture(gl.TEXTURE0 + unit);\n      gl.bindTexture(gl.TEXTURE_2D, tex);\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n      gl.uniform1i(gl.getUniformLocation(program, name), unit);\n      return tex;\n    };\n    const maskTex = makeTexture(0, \"uMask\");\n    const heightTex = makeTexture(1, \"uHeight\");\n    const maskCanvas = document.createElement(\"canvas\");\n    const heightCanvas = document.createElement(\"canvas\");\n\n    /** Three passes of a running-sum box blur (≈ gaussian) over a single channel, in place. */\n    const blur = (src: Float32Array, w: number, h: number, r: number) => {\n      const tmp = new Float32Array(src.length);\n      const pass = (from: Float32Array, to: Float32Array, horizontal: boolean) => {\n        const len = horizontal ? w : h;\n        const lines = horizontal ? h : w;\n        const norm = 1 / (r * 2 + 1);\n        for (let l = 0; l < lines; l++) {\n          const at = (i: number) => (horizontal ? l * w + Math.min(len - 1, Math.max(0, i)) : Math.min(len - 1, Math.max(0, i)) * w + l);\n          let sum = 0;\n          for (let i = -r; i <= r; i++) sum += from[at(i)];\n          for (let i = 0; i < len; i++) {\n            to[horizontal ? l * w + i : i * w + l] = sum * norm;\n            sum += from[at(i + r + 1)] - from[at(i - r)];\n          }\n        }\n      };\n      for (let k = 0; k < 3; k++) {\n        pass(src, tmp, true);\n        pass(tmp, src, false);\n      }\n    };\n\n    // The letters are drawn once into a 2D canvas as a white-on-black mask, sized to fill the frame.\n    const paintMask = () => {\n      const w = canvas.width;\n      const h = canvas.height;\n      maskCanvas.width = w;\n      maskCanvas.height = h;\n      const ctx = maskCanvas.getContext(\"2d\")!;\n      ctx.fillStyle = \"#000\";\n      ctx.fillRect(0, 0, w, h);\n      const lines = text.split(\"\\n\");\n      ctx.textAlign = \"center\";\n      ctx.textBaseline = \"middle\";\n      ctx.fillStyle = \"#fff\";\n      ctx.font = font.replace(/\\b1px\\b/, \"100px\");\n      const widest = Math.max(...lines.map((l) => ctx.measureText(l).width), 1);\n      const size = Math.min((w * 0.84 * 100) / widest, (h * 0.78) / (lines.length * 1.0));\n      ctx.font = font.replace(/\\b1px\\b/, `${size.toFixed(1)}px`);\n      lines.forEach((line, i) => ctx.fillText(line, w / 2, h / 2 + (i - (lines.length - 1) / 2) * size * 0.98));\n      gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);\n      gl.activeTexture(gl.TEXTURE0);\n      gl.bindTexture(gl.TEXTURE_2D, maskTex);\n      gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, maskCanvas);\n      // Height map: the mask at quarter size, blurred by about a tenth of the letter height.\n      const hw = Math.max(1, Math.round(w / 4));\n      const hh = Math.max(1, Math.round(h / 4));\n      heightCanvas.width = hw;\n      heightCanvas.height = hh;\n      const hctx = heightCanvas.getContext(\"2d\", { willReadFrequently: true })!;\n      hctx.drawImage(maskCanvas, 0, 0, hw, hh);\n      const img = hctx.getImageData(0, 0, hw, hh);\n      const field = new Float32Array(hw * hh);\n      for (let i = 0; i < field.length; i++) field[i] = img.data[i * 4] / 255;\n      blur(field, hw, hh, Math.max(1, Math.round(size / 4 / 14)));\n      for (let i = 0; i < field.length; i++) {\n        const v = Math.round(Math.min(1, field[i]) * 255);\n        img.data[i * 4] = v;\n        img.data[i * 4 + 1] = v;\n        img.data[i * 4 + 2] = v;\n        img.data[i * 4 + 3] = 255;\n      }\n      gl.activeTexture(gl.TEXTURE1);\n      gl.bindTexture(gl.TEXTURE_2D, heightTex);\n      gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img);\n    };\n\n    const pointer = { x: 0.5, y: 0.5, tx: 0.5, ty: 0.5, hover: 0, thover: 0 };\n    let time = 2;\n    let last = 0;\n    let raf = 0;\n    let visible = true;\n    const draw = (now: number) => {\n      const L = live.current;\n      const dt = Math.min(0.05, last ? (now - last) / 1000 : 1 / 60);\n      last = now;\n      if (!L.still) time += dt * L.speed;\n      pointer.x += (pointer.tx - pointer.x) * (1 - Math.exp(-dt * 6));\n      pointer.y += (pointer.ty - pointer.y) * (1 - Math.exp(-dt * 6));\n      pointer.hover += ((L.interactive ? pointer.thover : 0) - pointer.hover) * (1 - Math.exp(-dt * 3));\n      gl.uniform2f(U.res, canvas.width, canvas.height);\n      gl.uniform1f(U.time, time);\n      gl.uniform2f(U.mouse, pointer.x, pointer.y);\n      gl.uniform1f(U.hover, pointer.hover);\n      gl.uniform1f(U.inflate, L.inflate);\n      gl.uniform3fv(U.bg, rgb(L.background));\n      gl.uniform3fv(U.tint, rgb(L.tint));\n      gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);\n    };\n    const frame = (now: number) => {\n      draw(now);\n      if (visible && !document.hidden && !live.current.still) raf = requestAnimationFrame(frame);\n      else last = 0;\n    };\n    const start = () => {\n      cancelAnimationFrame(raf);\n      raf = requestAnimationFrame(frame);\n    };\n    redraw.current = start;\n    const resize = () => {\n      const dpr = Math.min(window.devicePixelRatio || 1, 1.5);\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      paintMask();\n      start();\n    };\n    const ro = new ResizeObserver(resize);\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 onMove = (event: PointerEvent) => {\n      const r = root.getBoundingClientRect();\n      pointer.tx = (event.clientX - r.left) / r.width;\n      pointer.ty = 1 - (event.clientY - r.top) / r.height;\n      pointer.thover = 1;\n    };\n    const onLeave = () => (pointer.thover = 0);\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerleave\", onLeave);\n    // Fonts may still be loading on first paint: repaint the mask once they're ready.\n    document.fonts?.ready.then(() => {\n      paintMask();\n      start();\n    });\n    resize();\n    return () => {\n      cancelAnimationFrame(raf);\n      redraw.current = () => {};\n      ro.disconnect();\n      io.disconnect();\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n    };\n  }, [text, font]);\n\n  return (\n    <div ref={rootRef} role=\"img\" aria-label={text.replace(/\\n/g, \" \")} className={cn(\"relative overflow-hidden\", className)} style={{ background, ...style }} {...props}>\n      {!failed && <canvas ref={canvasRef} aria-hidden=\"true\" className=\"absolute inset-0 h-full w-full\" />}\n      {failed && (\n        <div className=\"absolute inset-0 flex items-center justify-center text-center text-[clamp(48px,12vw,140px)] leading-[0.95] font-black whitespace-pre-line\" style={{ color: tint, textShadow: \"0 2px 0 #fff8, 0 -2px 0 #0006\" }}>\n          {text}\n        </div>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}