{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"liquid-metal","type":"registry:component","title":"Liquid Metal Logo","description":"Turns any logo into flowing liquid metal: polished mirror chrome with round, tube-like edges and twinkling star glints, whose reflections ripple like mercury and follow the pointer. An iridescent finish is one switch away.","dependencies":[],"files":[{"path":"registry/dot/liquid-metal.tsx","type":"registry:component","target":"components/dot/liquid-metal.tsx","content":"\"use client\";\n\nimport { useEffect, useRef, useState, type CSSProperties } from \"react\";\n\nexport interface LiquidMetalLogoProps {\n  /** The logo: an SVG or PNG with a transparent background (URL, data URL or object URL) */\n  src: string;\n  /** Logo size as a share of the box (0–1) */\n  size?: number;\n  /** Flow speed; 0 freezes it */\n  speed?: number;\n  /** How many chrome bands run across the logo */\n  pattern?: number;\n  /** How much the liquid bends the reflections */\n  distortion?: number;\n  /** Width of the rounded edge, as a share of the logo */\n  edge?: number;\n  /** Rainbow on the edges and highlights (0–2) */\n  dispersion?: number;\n  /** \"chrome\": polished black-and-white mirror metal with round, tube-like edges;\n   * \"iridescent\": softer liquid metal with flowing bands */\n  finish?: \"chrome\" | \"iridescent\";\n  /** Twinkling star glints on the brightest spots (0 hides them) */\n  glints?: number;\n  /** Multiplies the metal colour; white is plain chrome */\n  tint?: string;\n  /** Highlight follows the pointer */\n  interactive?: boolean;\n  /** Accessible name; defaults to \"Logo\" */\n  alt?: string;\n  className?: string;\n  style?: CSSProperties;\n}\n\nconst MAP = 512; // the logo is analysed on a square of this many pixels\n\n// ─── Logo analysis: mask, rounded height and surface normals ─────────────────\n\n/** One row or column of the exact squared Euclidean distance transform (Felzenszwalb & Huttenlocher) */\nfunction edt1d(f: Float32Array, n: number, d: Float32Array, v: Int32Array, z: Float32Array) {\n  let k = 0;\n  v[0] = 0;\n  z[0] = -Infinity;\n  z[1] = Infinity;\n  for (let q = 1; q < n; q++) {\n    let s = (f[q] + q * q - (f[v[k]] + v[k] * v[k])) / (2 * q - 2 * v[k]);\n    while (s <= z[k]) {\n      k--;\n      s = (f[q] + q * q - (f[v[k]] + v[k] * v[k])) / (2 * q - 2 * v[k]);\n    }\n    k++;\n    v[k] = q;\n    z[k] = s;\n    z[k + 1] = Infinity;\n  }\n  k = 0;\n  for (let q = 0; q < n; q++) {\n    while (z[k + 1] < q) k++;\n    d[q] = (q - v[k]) * (q - v[k]) + f[v[k]];\n  }\n}\n\n/** Exact distance (in pixels) from each inside pixel to the nearest outside pixel, so bevels round\n * off evenly instead of creasing at 45° like a cheap approximation would */\nfunction insideDistance(inside: Uint8Array, w: number, h: number) {\n  const INF = 1e20;\n  const grid = new Float32Array(w * h);\n  for (let i = 0; i < grid.length; i++) grid[i] = inside[i] ? INF : 0;\n  const n = Math.max(w, h);\n  const f = new Float32Array(n);\n  const d = new Float32Array(n);\n  const v = new Int32Array(n);\n  const z = new Float32Array(n + 1);\n  for (let x = 0; x < w; x++) {\n    for (let y = 0; y < h; y++) f[y] = grid[y * w + x];\n    edt1d(f, h, d, v, z);\n    for (let y = 0; y < h; y++) grid[y * w + x] = d[y];\n  }\n  for (let y = 0; y < h; y++) {\n    for (let x = 0; x < w; x++) f[x] = grid[y * w + x];\n    edt1d(f, w, d, v, z);\n    for (let x = 0; x < w; x++) grid[y * w + x] = Math.sqrt(d[x]);\n  }\n  return grid;\n}\n\nfunction boxBlur(src: Float32Array, w: number, h: number, r: number) {\n  const tmp = new Float32Array(src.length);\n  const out = new Float32Array(src.length);\n  const n = r * 2 + 1;\n  for (let y = 0; y < h; y++) {\n    let sum = 0;\n    for (let x = -r; x <= r; x++) sum += src[y * w + Math.min(w - 1, Math.max(0, x))];\n    for (let x = 0; x < w; x++) {\n      tmp[y * w + x] = sum / n;\n      sum += src[y * w + Math.min(w - 1, x + r + 1)] - src[y * w + Math.max(0, x - r)];\n    }\n  }\n  for (let x = 0; x < w; x++) {\n    let sum = 0;\n    for (let y = -r; y <= r; y++) sum += tmp[Math.min(h - 1, Math.max(0, y)) * w + x];\n    for (let y = 0; y < h; y++) {\n      out[y * w + x] = sum / n;\n      sum += tmp[Math.min(h - 1, y + r + 1) * w + x] - tmp[Math.max(0, y - r) * w + x];\n    }\n  }\n  return out;\n}\n\n/**\n * Turns the logo into a texture: R = rounded height, G = coverage (anti-aliased edge),\n * B/A = surface normal x/y. Worked out once per logo and edge width.\n */\nfunction analyse(img: HTMLImageElement, edge: number, round: boolean) {\n  const canvas = document.createElement(\"canvas\");\n  canvas.width = canvas.height = MAP;\n  const ctx = canvas.getContext(\"2d\", { willReadFrequently: true });\n  if (!ctx) return null;\n  // Fit with padding so the bevel is never cut off\n  const pad = MAP * 0.08;\n  const ratio = (img.naturalWidth || img.width) / Math.max(1, img.naturalHeight || img.height);\n  const box = MAP - pad * 2;\n  const w = ratio >= 1 ? box : box * ratio;\n  const h = ratio >= 1 ? box / ratio : box;\n  ctx.drawImage(img, (MAP - w) / 2, (MAP - h) / 2, w, h);\n  const pixels = ctx.getImageData(0, 0, MAP, MAP).data;\n\n  const inside = new Uint8Array(MAP * MAP);\n  const coverage = new Float32Array(MAP * MAP);\n  for (let i = 0; i < inside.length; i++) {\n    coverage[i] = pixels[i * 4 + 3] / 255;\n    inside[i] = coverage[i] > 0.5 ? 1 : 0;\n  }\n  const dist = insideDistance(inside, MAP, MAP);\n  const bevel = Math.max(2, edge * Math.min(w, h));\n  const height = new Float32Array(MAP * MAP);\n  for (let i = 0; i < height.length; i++) {\n    const t = Math.min(1, dist[i] / bevel);\n    // Chrome: a round, tube-like cross-section; iridescent: a rounded shoulder with a flatter top\n    height[i] = round ? Math.sqrt(Math.max(0, 1 - (1 - t) * (1 - t))) : 1 - (1 - t) * (1 - t);\n  }\n  // Smoothing in proportion to the bevel rounds off the ridges where edges meet, like poured metal\n  const r = Math.max(2, Math.round(bevel * 0.3));\n  const smooth = boxBlur(boxBlur(height, MAP, MAP, r), MAP, MAP, r);\n\n  const data = new Uint8Array(MAP * MAP * 4);\n  for (let y = 0; y < MAP; y++)\n    for (let x = 0; x < MAP; x++) {\n      const i = y * MAP + x;\n      const hx = smooth[y * MAP + Math.min(MAP - 1, x + 1)] - smooth[y * MAP + Math.max(0, x - 1)];\n      const hy = smooth[Math.min(MAP - 1, y + 1) * MAP + x] - smooth[Math.max(0, y - 1) * MAP + x];\n      // Steepness scaled to the bevel so thin and wide edges both read as round\n      const k = bevel / 6;\n      const nx = Math.max(-1, Math.min(1, -hx * k));\n      const ny = Math.max(-1, Math.min(1, -hy * k));\n      data[i * 4] = Math.round(smooth[i] * 255);\n      data[i * 4 + 1] = Math.round(coverage[i] * 255);\n      data[i * 4 + 2] = Math.round((nx * 0.5 + 0.5) * 255);\n      data[i * 4 + 3] = Math.round((ny * 0.5 + 0.5) * 255);\n    }\n\n  // Glints: the highest points that face the light (top left), at least a fifth of the logo apart\n  const candidates: { x: number; y: number; score: number }[] = [];\n  for (let y = 2; y < MAP - 2; y += 3)\n    for (let x = 2; x < MAP - 2; x += 3) {\n      const i = y * MAP + x;\n      if (coverage[i] < 0.95 || smooth[i] < 0.6) continue;\n      const nx = data[i * 4 + 2] / 127.5 - 1;\n      const ny = data[i * 4 + 3] / 127.5 - 1;\n      candidates.push({ x, y, score: smooth[i] + Math.max(0, -0.45 * nx - 0.9 * ny) * 0.8 });\n    }\n  candidates.sort((a, b) => b.score - a.score);\n  const glints: [number, number][] = [];\n  const apart = Math.min(w, h) * 0.22;\n  for (const c of candidates) {\n    if (glints.length >= 3) break;\n    if (glints.every(([gx, gy]) => Math.hypot(gx * MAP - c.x, gy * MAP - c.y) > apart)) glints.push([c.x / MAP, c.y / MAP]);\n  }\n  return { data, glints };\n}\n\n// ─── Shader ──────────────────────────────────────────────────────────────────\n\nconst VERTEX = `\nattribute vec2 a_pos;\nvarying vec2 v_uv;\nvoid main() {\n  v_uv = a_pos * 0.5 + 0.5;\n  gl_Position = vec4(a_pos, 0.0, 1.0);\n}`;\n\nconst FRAGMENT = `\nprecision highp float;\nvarying vec2 v_uv;\nuniform sampler2D u_map;\nuniform vec2 u_fit;      // canvas uv -> map uv scale (keeps the logo square and sized)\nuniform float u_time;\nuniform float u_pattern;\nuniform float u_distortion;\nuniform float u_dispersion;\nuniform vec3 u_tint;\nuniform vec2 u_pointer;  // -1..1\nuniform float u_finish;  // 1 = chrome, 0 = iridescent\nuniform vec3 u_glints[3]; // x, y in map uv, z = twinkle phase (-1 = none)\nuniform float u_glintAmount;\n\n// 2D simplex noise (Ashima Arts, MIT)\nvec3 permute(vec3 x) { return mod(((x * 34.0) + 1.0) * x, 289.0); }\nfloat snoise(vec2 v) {\n  const vec4 C = vec4(0.211324865405187, 0.366025403784439, -0.577350269189626, 0.024390243902439);\n  vec2 i = floor(v + dot(v, C.yy));\n  vec2 x0 = v - i + dot(i, C.xx);\n  vec2 i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n  vec4 x12 = x0.xyxy + C.xxzz;\n  x12.xy -= i1;\n  i = mod(i, 289.0);\n  vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0)) + i.x + vec3(0.0, i1.x, 1.0));\n  vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy), dot(x12.zw, x12.zw)), 0.0);\n  m = m * m;\n  m = m * m;\n  vec3 x = 2.0 * fract(p * C.www) - 1.0;\n  vec3 h = abs(x) - 0.5;\n  vec3 ox = floor(x + 0.5);\n  vec3 a0 = x - ox;\n  m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);\n  vec3 g;\n  g.x = a0.x * x0.x + h.x * x0.y;\n  g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n  return 130.0 * dot(m, g);\n}\n\n// Chrome: deep shadow, cool mid-grey, bright highlight, with crisp transitions\nvec3 chrome(float t) {\n  float b = 0.5 + 0.5 * cos(6.28318 * t);\n  vec3 dark = vec3(0.035, 0.04, 0.05);\n  vec3 mid = vec3(0.52, 0.55, 0.6);\n  vec3 light = vec3(0.98, 0.99, 1.0);\n  vec3 c = mix(dark, mid, smoothstep(0.08, 0.42, b));\n  return mix(c, light, smoothstep(0.58, 0.88, b));\n}\n\n// Polished mirror chrome: up-facing reflections see a bright sky, down-facing a near-black floor,\n// with a crisp dark horizon line between them and a few soft studio strips drifting across\nvec3 mirror(vec3 n, float flow, float t) {\n  vec3 R = reflect(vec3(0.0, 0.0, -1.0), n);\n  float a = R.y * 1.1 + R.x * 0.3 + flow * u_distortion * 0.7 - u_pointer.y * 0.18 + u_pointer.x * 0.08 + sin(t * 0.25) * 0.06;\n  float sky = mix(0.6, 1.0, smoothstep(0.0, 0.75, a));\n  float floor_ = mix(0.012, 0.14, smoothstep(-1.0, -0.05, a));\n  float c = a > 0.0 ? sky : floor_;\n  c *= smoothstep(0.0, 0.07, abs(a));\n  c += 0.3 * smoothstep(0.82, 1.0, 0.5 + 0.5 * cos(6.28318 * (a * u_pattern * 1.6 - t * 0.05)));\n  return vec3(c);\n}\n\n// Four-point star: a bright core with long horizontal and vertical streaks\nfloat star(vec2 uv, vec3 g, float t) {\n  if (g.z < 0.0) return 0.0;\n  vec2 q = (uv - g.xy) * 34.0;\n  float twinkle = 0.4 + 0.6 * pow(0.5 + 0.5 * sin(t * 1.4 + g.z), 2.0);\n  float core = exp(-dot(q, q) * 1.6);\n  float halo = exp(-dot(q, q) * 0.12) * 0.35;\n  float h = exp(-abs(q.y) * 7.0) * exp(-abs(q.x) * 0.22);\n  float v = exp(-abs(q.x) * 7.0) * exp(-abs(q.y) * 0.32);\n  return (core * 1.6 + halo + (h + v) * 0.8) * twinkle;\n}\n\nvoid main() {\n  vec2 uv = (v_uv - 0.5) * u_fit + 0.5;\n  uv.y = 1.0 - uv.y;\n  float t = u_time;\n  float glow = (star(uv, u_glints[0], t) + star(uv, u_glints[1], t) + star(uv, u_glints[2], t)) * u_glintAmount;\n  bool inside = uv.x >= 0.0 && uv.y >= 0.0 && uv.x <= 1.0 && uv.y <= 1.0;\n  vec4 m = inside ? texture2D(u_map, uv) : vec4(0.0);\n  float mask = m.g;\n  vec3 col = vec3(0.0);\n\n  if (mask > 0.004) {\n    // Chrome uses steeper normals so the rounded tube edges read strongly\n    vec3 n = normalize(vec3((m.b - 0.5) * 2.0, -(m.a - 0.5) * 2.0, mix(0.55, 0.32, u_finish)));\n    float rim = 1.0 - n.z;\n\n    // Liquid: two layers of slowly drifting noise bend where the reflections fall\n    vec2 p = uv * 2.2;\n    float flow = snoise(p + vec2(t * 0.11, -t * 0.07)) * 0.6 + snoise(p * 2.3 - vec2(t * 0.17, t * 0.05)) * 0.3;\n    float r = uv.y * 0.9 - uv.x * 0.35 + n.y * 0.9 + n.x * 0.45 + flow * u_distortion - u_pointer.y * 0.12 + u_pointer.x * 0.06;\n    r = r * u_pattern - t * 0.06;\n\n    // Dispersion: red, green and blue bands pulled apart, most on the steep edges\n    float spread = u_dispersion * 0.11 * (0.35 + rim * 1.6);\n    vec3 liquid = vec3(chrome(r - spread).r, chrome(r).g, chrome(r + spread).b);\n    vec3 polished = mirror(n, flow, t);\n    if (u_dispersion > 0.0) {\n      vec3 shifted = vec3(mirror(normalize(n + vec3(spread, 0.0, 0.0)), flow, t).r, polished.g, mirror(normalize(n - vec3(spread, 0.0, 0.0)), flow, t).b);\n      polished = shifted;\n    }\n    col = mix(liquid, polished, u_finish);\n\n    // Oil-slick iridescence on the edges and the bright bands\n    vec3 film = 0.5 + 0.5 * cos(6.28318 * (r * 0.9 + rim * 1.4 + vec3(0.0, 0.33, 0.67)));\n    float sheen = clamp(rim * 1.8 + (col.g - 0.45) * 0.6, 0.0, 1.0);\n    col = mix(col, col * 0.55 + film * 0.75, u_dispersion * 0.45 * sheen);\n\n    // Specular highlight that follows the pointer, and a rim light (bright white edges on chrome)\n    vec3 L = normalize(vec3(u_pointer.x * 0.7 - 0.35, -u_pointer.y * 0.7 + 0.55, 1.0));\n    float spec = pow(max(dot(n, normalize(L + vec3(0.0, 0.0, 1.0))), 0.0), mix(48.0, 90.0, u_finish));\n    col += spec * mix(0.75, 1.1, u_finish) + rim * mix(0.12, 0.22, u_finish);\n    col *= u_tint;\n  }\n\n  // Glints shine past the logo's edge, so they add light rather than follow the mask\n  gl_FragColor = vec4(col * mask + u_tint * glow, clamp(mask + glow, 0.0, 1.0));\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.error(\"[LiquidMetalLogo]\", gl.getShaderInfoLog(shader));\n    gl.deleteShader(shader);\n    return null;\n  }\n  return shader;\n}\n\nconst toRGB = (hex: string): [number, number, number] => {\n  const m = /^#?([\\da-f]{2})([\\da-f]{2})([\\da-f]{2})$/i.exec(hex.trim());\n  return m ? [parseInt(m[1], 16) / 255, parseInt(m[2], 16) / 255, parseInt(m[3], 16) / 255] : [1, 1, 1];\n};\n\n// ─── Component ───────────────────────────────────────────────────────────────\n\n/**\n * Turns any logo into flowing liquid metal: polished mirror chrome with round, tube-like edges and\n * twinkling star glints (or a softer iridescent finish), whose reflections ripple like mercury and\n * follow the pointer. WebGL, no dependencies; falls back to the plain\n * logo where WebGL isn't available. Fills its parent.\n */\nexport function LiquidMetalLogo({\n  src,\n  size = 0.7,\n  speed = 1,\n  pattern = 0.8,\n  distortion = 0.2,\n  edge = 0.2,\n  dispersion = 0,\n  finish = \"chrome\",\n  glints = 1,\n  tint = \"#FFFFFF\",\n  interactive = true,\n  alt = \"Logo\",\n  className,\n  style,\n}: LiquidMetalLogoProps) {\n  const wrapRef = useRef<HTMLDivElement | null>(null);\n  const canvasRef = useRef<HTMLCanvasElement | null>(null);\n  const [failed, setFailed] = useState(false);\n  const live = useRef({ size, speed, pattern, distortion, dispersion, tint, interactive, finish, glints });\n  useEffect(() => {\n    live.current = { size, speed, pattern, distortion, dispersion, tint, interactive, finish, glints };\n  });\n  // The loaded logo's texture and glint spots, rebuilt when the logo, edge width or finish changes\n  const upload = useRef<(data: Uint8Array, spots: [number, number][]) => void>(() => {});\n\n  // WebGL setup and the render loop\n  useEffect(() => {\n    const wrap = wrapRef.current;\n    const canvas = canvasRef.current;\n    if (!wrap || !canvas) return;\n    const gl = canvas.getContext(\"webgl\", { premultipliedAlpha: true, alpha: true, antialias: true });\n    if (!gl) {\n      Promise.resolve().then(() => setFailed(true));\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      Promise.resolve().then(() => setFailed(true));\n      return;\n    }\n    gl.attachShader(program, vs);\n    gl.attachShader(program, fs);\n    gl.linkProgram(program);\n    gl.useProgram(program);\n\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 pos = gl.getAttribLocation(program, \"a_pos\");\n    gl.enableVertexAttribArray(pos);\n    gl.vertexAttribPointer(pos, 2, gl.FLOAT, false, 0, 0);\n\n    const texture = gl.createTexture();\n    gl.bindTexture(gl.TEXTURE_2D, texture);\n    gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);\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.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.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4));\n    let ready = false;\n    // x, y, phase for up to three glints; phase -1 switches one off\n    const glintData = new Float32Array([0, 0, -1, 0, 0, -1, 0, 0, -1]);\n    upload.current = (data, spots) => {\n      gl.bindTexture(gl.TEXTURE_2D, texture);\n      gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, MAP, MAP, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);\n      glintData.fill(0);\n      for (let k = 0; k < 3; k++) {\n        const spot = spots[k];\n        glintData[k * 3] = spot ? spot[0] : 0;\n        glintData[k * 3 + 1] = spot ? spot[1] : 0;\n        glintData[k * 3 + 2] = spot ? k * 2.1 : -1;\n      }\n      ready = true;\n      start();\n    };\n\n    const u = (name: string) => gl.getUniformLocation(program, name);\n    const uFit = u(\"u_fit\");\n    const uTime = u(\"u_time\");\n    const uPattern = u(\"u_pattern\");\n    const uDistortion = u(\"u_distortion\");\n    const uDispersion = u(\"u_dispersion\");\n    const uTint = u(\"u_tint\");\n    const uPointer = u(\"u_pointer\");\n    const uFinish = u(\"u_finish\");\n    const uGlints = u(\"u_glints\");\n    const uGlintAmount = u(\"u_glintAmount\");\n    gl.uniform1i(u(\"u_map\"), 0);\n    gl.enable(gl.BLEND);\n    gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);\n\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    let width = 1;\n    let height = 1;\n    let frame = 0;\n    let visible = true;\n    let time = 0;\n    let last = performance.now();\n    const pointer = { x: 0, y: 0, tx: 0, ty: 0 };\n\n    const resize = () => {\n      const rect = wrap.getBoundingClientRect();\n      const dpr = Math.min(window.devicePixelRatio || 1, 2);\n      width = Math.max(1, Math.round(rect.width * dpr));\n      height = Math.max(1, Math.round(rect.height * dpr));\n      canvas.width = width;\n      canvas.height = height;\n      gl.viewport(0, 0, width, height);\n      start();\n    };\n\n    const draw = (now: number) => {\n      const s = live.current;\n      const dt = Math.min(0.05, (now - last) / 1000);\n      last = now;\n      if (!reduce.matches) time += dt * s.speed;\n      pointer.x += (pointer.tx - pointer.x) * Math.min(1, dt * 5);\n      pointer.y += (pointer.ty - pointer.y) * Math.min(1, dt * 5);\n      // Square logo map centred in the box at `size` of its shorter side\n      const short = Math.min(width, height);\n      const logo = Math.max(0.05, Math.min(1, s.size)) * short;\n      gl.uniform2f(uFit, width / logo, height / logo);\n      gl.uniform1f(uTime, time);\n      gl.uniform1f(uPattern, s.pattern);\n      gl.uniform1f(uDistortion, s.distortion);\n      gl.uniform1f(uDispersion, s.dispersion);\n      gl.uniform3fv(uTint, toRGB(s.tint));\n      gl.uniform2f(uPointer, pointer.x, pointer.y);\n      gl.uniform1f(uFinish, s.finish === \"iridescent\" ? 0 : 1);\n      gl.uniform3fv(uGlints, glintData);\n      gl.uniform1f(uGlintAmount, Math.max(0, s.glints));\n      gl.clearColor(0, 0, 0, 0);\n      gl.clear(gl.COLOR_BUFFER_BIT);\n      if (ready) gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);\n    };\n\n    const tick = (now: number) => {\n      draw(now);\n      const moving = !reduce.matches && live.current.speed > 0;\n      const settling = Math.abs(pointer.tx - pointer.x) + Math.abs(pointer.ty - pointer.y) > 0.001;\n      frame = visible && (moving || settling) ? requestAnimationFrame(tick) : 0;\n    };\n    function start() {\n      if (frame || !visible) return;\n      last = performance.now();\n      frame = requestAnimationFrame(tick);\n    }\n\n    const onMove = (e: PointerEvent) => {\n      if (!live.current.interactive) return;\n      const rect = wrap.getBoundingClientRect();\n      pointer.tx = Math.max(-1, Math.min(1, ((e.clientX - rect.left) / rect.width) * 2 - 1));\n      pointer.ty = Math.max(-1, Math.min(1, ((e.clientY - rect.top) / rect.height) * 2 - 1));\n      start();\n    };\n    const onLeave = () => {\n      pointer.tx = pointer.ty = 0;\n      start();\n    };\n\n    const ro = new ResizeObserver(resize);\n    ro.observe(wrap);\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible) start();\n    });\n    io.observe(wrap);\n    window.addEventListener(\"pointermove\", onMove, { passive: true });\n    wrap.addEventListener(\"pointerleave\", onLeave);\n    reduce.addEventListener(\"change\", start);\n    resize();\n\n    return () => {\n      cancelAnimationFrame(frame);\n      upload.current = () => {};\n      ro.disconnect();\n      io.disconnect();\n      window.removeEventListener(\"pointermove\", onMove);\n      wrap.removeEventListener(\"pointerleave\", onLeave);\n      reduce.removeEventListener(\"change\", start);\n      gl.deleteTexture(texture);\n      gl.deleteBuffer(buffer);\n      gl.deleteProgram(program);\n      gl.deleteShader(vs);\n      gl.deleteShader(fs);\n    };\n  }, []);\n\n  // Load and analyse the logo whenever it or the edge width changes\n  useEffect(() => {\n    if (!src) return;\n    let cancelled = false;\n    const img = new Image();\n    img.crossOrigin = \"anonymous\";\n    img.decoding = \"async\";\n    img.onload = () => {\n      if (cancelled) return;\n      try {\n        const result = analyse(img, edge, finish !== \"iridescent\");\n        if (result) upload.current(result.data, result.glints);\n      } catch (err) {\n        // A logo from another site without CORS headers can't be read pixel by pixel: show it plainly\n        console.error(\"[LiquidMetalLogo] Couldn't read the logo (serve it from your own site or with CORS):\", err);\n        setFailed(true);\n      }\n    };\n    img.onerror = () => console.error(\"[LiquidMetalLogo] Couldn't load the logo:\", src);\n    img.src = src;\n    return () => {\n      cancelled = true;\n    };\n  }, [src, edge, finish]);\n\n  return (\n    <div\n      ref={wrapRef}\n      role=\"img\"\n      aria-label={alt}\n      className={className}\n      style={{ position: \"relative\", width: \"100%\", height: \"100%\", ...style }}\n    >\n      {failed ? (\n        // eslint-disable-next-line @next/next/no-img-element -- any logo URL; shown when WebGL is unavailable\n        <img\n          src={src}\n          alt=\"\"\n          style={{ position: \"absolute\", inset: 0, margin: \"auto\", width: `${size * 100}%`, height: `${size * 100}%`, objectFit: \"contain\", filter: \"grayscale(1) brightness(1.4)\" }}\n        />\n      ) : (\n        <canvas ref={canvasRef} style={{ position: \"absolute\", inset: 0, width: \"100%\", height: \"100%\", display: \"block\" }} />\n      )}\n    </div>\n  );\n}\n"}],"docs":"Liquid Metal Logo is ready. Props and a live canvas: https://bydot.co/component/liquid-metal","meta":{"tier":"free","category":"3D & Effects","version":"1.0.0"}}