{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "venom",
  "title": "Venom",
  "description": "A living symbiote covers your text or SVG, crawls over it and sends writhing tendrils after the pointer. WebGL 2, no dependencies.",
  "files": [
    {
      "path": "registry/mewo/ui/venom.tsx",
      "content": "\"use client\"\n\nimport { useEffect, useRef, type ComponentProps, type ReactNode } from \"react\"\nimport { cn } from \"@/lib/utils\"\n\nexport interface VenomProps extends Omit<ComponentProps<\"div\">, \"color\" | \"children\"> {\n  /** The word the symbiote covers. Leave it out to cover `children` instead. */\n  text?: string\n  /** An `<svg>` to cover when there is no `text`. Only its shape is used. */\n  children?: ReactNode\n  /** Colour of the dark matter. */\n  color?: string\n  /** Colour of the wet highlights. */\n  highlight?: string\n  /** How many tendrils reach for the pointer. 0 keeps the symbiote on the shape. */\n  tendrils?: number\n  /** How far from the shape the pointer can be and still be reached, in pixels. */\n  reach?: number\n  /** Width of a tendril at its root, in pixels. */\n  thickness?: number\n  /** How much the tendrils writhe. */\n  writhe?: number\n  /** How much the surface crawls and its edge boils. */\n  boil?: number\n  /** Share of the box the shape fills, 0 to 1. */\n  scale?: number\n  /** Font for `text`. Defaults to the font the component inherits. */\n  fontFamily?: string\n  fontWeight?: number | string\n  /** 0 freezes the surface; the tendrils still reach. */\n  speed?: number\n  /** Freeze everything; the last frame stays. */\n  paused?: boolean\n  /** Override the device pixel ratio, which is capped at 2. */\n  dpr?: number\n}\n\ntype Settings = {\n  text: string\n  svg: string\n  color: string\n  highlight: string\n  tendrils: number\n  reach: number\n  thickness: number\n  writhe: number\n  boil: number\n  scale: number\n  fontFamily?: string\n  fontWeight: number | string\n  speed: number\n  paused: boolean\n  dpr?: number\n}\n\ntype Tendril = {\n  planted: boolean\n  /** Where it grows from, on the shape's edge, and the edge's outward normal. */\n  ax: number\n  ay: number\n  nx: number\n  ny: number\n  /** The tip, on a spring towards the pointer. */\n  tipX: number\n  tipY: number\n  vx: number\n  vy: number\n  /** The last place the pointer was seen, so a tendril retracts from where it was reaching. */\n  aimX: number\n  aimY: number\n  /** 0 retracted, 1 fully out. */\n  ext: number\n  wait: number\n  letGo: boolean\n  /** How far past its length the pointer is pulling it, 0 to 1. */\n  strain: number\n  seed: number\n  spin: number\n  orbit: number\n  vigor: number\n  twigAt: number\n  twigSide: number\n}\n\nconst PIXEL_BUDGET = 4.5e6\n/** The goo field is smooth, so it is computed at CSS-pixel density at most, and within this budget. */\nconst FIELD_BUDGET = 1.2e6\n/** The shape's distance field is rebuilt on the CPU when the shape or the box changes; this caps its cost. */\nconst SHAPE_BUDGET = 1.6e5\n/** Edge points a tendril can grow from. */\nconst EDGE_POINTS = 720\nconst MAX_TENDRILS = 16\nconst SEGMENTS = 44\nconst TWIG_SEGMENTS = 18\nconst MAX_CAPSULES = MAX_TENDRILS * (SEGMENTS + TWIG_SEGMENTS - 2)\n/** Per capsule: start x, y, end x, y, start radius, end radius. */\nconst FLOATS = 6\nconst TAU = Math.PI * 2\nconst INF = 1e20\n\nconst FULLSCREEN = `#version 300 es\nvoid main() {\n  vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));\n  gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);\n}`\n\nconst NOISE = `\nuvec3 pcg3(uvec3 v) {\n  v = v * 1664525u + 1013904223u;\n  v.x += v.y * v.z; v.y += v.z * v.x; v.z += v.x * v.y;\n  v ^= v >> 16u;\n  v.x += v.y * v.z; v.y += v.z * v.x; v.z += v.x * v.y;\n  return v;\n}\nvec3 grad(vec3 cell) {\n  uvec3 h = pcg3(uvec3(ivec3(cell) + 32768));\n  return vec3(h & 0xffffu) / 32767.5 - 1.0;\n}\nfloat corner(vec3 i, vec3 f, vec3 o) {\n  return dot(grad(i + o), f - o);\n}\nfloat noise(vec3 p) {\n  vec3 i = floor(p);\n  vec3 f = p - i;\n  vec3 u = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n  return mix(\n    mix(mix(corner(i, f, vec3(0, 0, 0)), corner(i, f, vec3(1, 0, 0)), u.x),\n        mix(corner(i, f, vec3(0, 1, 0)), corner(i, f, vec3(1, 1, 0)), u.x), u.y),\n    mix(mix(corner(i, f, vec3(0, 0, 1)), corner(i, f, vec3(1, 0, 1)), u.x),\n        mix(corner(i, f, vec3(0, 1, 1)), corner(i, f, vec3(1, 1, 1)), u.x), u.y),\n    u.z);\n}`\n\n// The body: the shape's distance field, its edge boiling with noise and swelling towards the pointer.\n// R is the goo field (0.5 at the surface), G the crawl that rides on top of it, A the height of the surface:\n// a rounded profile `uDome` pixels wide, plus a swell under the pointer when it is over the shape.\nconst FIELD = `#version 300 es\nprecision highp float;\nuniform sampler2D uSdf;\nuniform vec2 uView;\nuniform vec2 uField;\nuniform float uTime;\nuniform float uUnit;\nuniform float uBoil;\nuniform float uSoft;\nuniform float uDome;\nuniform vec4 uPull;\nout vec4 outField;\n${NOISE}\nvoid main() {\n  vec2 p = vec2(gl_FragCoord.x, uField.y - gl_FragCoord.y) / uField * uView;\n  float d = texture(uSdf, p / uView).r;\n  float bound = uBoil * 3.0 + uSoft * 1.2 + uPull.z;\n  if (d > bound) {\n    outField = vec4(0.0, 0.5, 0.0, 0.0);\n    return;\n  }\n  vec2 q = p / uUnit;\n  float t = uTime;\n  float edge = noise(vec3(q * 0.022, t * 0.35)) + 0.5 * noise(vec3(q * 0.05 + 7.1, t * 0.6))\n    + 1.2 * noise(vec3(q * 0.008 + 3.7, t * 0.15));\n  float body = d - uBoil * edge;\n  vec2 toPull = p - uPull.xy;\n  float swell = uPull.z * exp(-dot(toPull, toPull) / (uPull.w * uPull.w));\n  body -= swell;\n  float field = 1.0 - smoothstep(-uSoft, uSoft, body);\n  float rise = min(max(-body, 0.0) / uDome, 1.0);\n  float height = sqrt(1.0 - (rise - 1.0) * (rise - 1.0)) * (1.0 + 0.6 * swell / uDome);\n  vec2 warp = vec2(noise(vec3(q * 0.012, t * 0.2)), noise(vec3(q * 0.012 + 19.3, t * 0.2)));\n  float crawl = noise(vec3(q * 0.035 + warp * 2.5, t * 0.45));\n  crawl *= 1.0 - smoothstep(bound * 0.5, bound, d);\n  outField = vec4(field, crawl * 0.5 + 0.5, 0.0, height);\n}`\n\n// A tendril is a chain of tapered capsules, one instance per segment, each measuring its exact distance so the\n// tube stays round through every bend. Into B goes a soft falloff that the shading pass adds to the body's\n// field, so the two melt together; into A a round profile. Both blend with MAX, so the chain has no seams.\nconst TENDRIL_VERTEX = `#version 300 es\nlayout(location = 0) in vec2 aCorner;\nlayout(location = 1) in vec4 aSegment;\nlayout(location = 2) in vec2 aRadius;\nuniform vec2 uView;\nuniform float uSoft;\nout vec2 vPoint;\nflat out vec4 vSegment;\nflat out vec2 vRadius;\nvoid main() {\n  vec2 axis = aSegment.zw - aSegment.xy;\n  float len = length(axis);\n  vec2 dir = len > 1e-4 ? axis / len : vec2(1.0, 0.0);\n  float pad = max(aRadius.x, aRadius.y) + uSoft;\n  vec2 point = (aSegment.xy + aSegment.zw) * 0.5 + dir * aCorner.x * (len * 0.5 + pad)\n    + vec2(-dir.y, dir.x) * aCorner.y * pad;\n  vPoint = point;\n  vSegment = aSegment;\n  vRadius = aRadius;\n  vec2 clip = point / uView * 2.0 - 1.0;\n  gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);\n}`\n\nconst TENDRIL_FRAGMENT = `#version 300 es\nprecision highp float;\nuniform float uSoft;\nuniform float uDome;\nin vec2 vPoint;\nflat in vec4 vSegment;\nflat in vec2 vRadius;\nout vec4 outField;\nvoid main() {\n  vec2 pa = vPoint - vSegment.xy;\n  vec2 ba = vSegment.zw - vSegment.xy;\n  float h = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-4), 0.0, 1.0);\n  float r = mix(vRadius.x, vRadius.y, h);\n  float d = length(pa - ba * h);\n  // A tube no thicker than the body's rounded edge is lower than it; a thicker one rises to the same top.\n  float height = sqrt(max(r * r - d * d, 0.0)) / max(uDome, r);\n  outField = vec4(0.0, 0.0, 1.0 - smoothstep(r - uSoft, r + uSoft, d), height);\n}`\n\n// The surface: wherever body and tendrils together pass 0.5, shaded as wet black with a hard key light and a\n// rim that is brighter on the lit side. Where a tendril melts into the body the field's slope stands in for\n// height.\nconst SHADE = `#version 300 es\nprecision highp float;\nuniform sampler2D uField;\nuniform vec2 uCanvas;\nuniform vec2 uTexel;\nuniform vec3 uColor;\nuniform vec3 uHighlight;\nuniform float uRelief;\nuniform float uCrawl;\nout vec4 outColor;\nfloat height(vec4 v) {\n  float f = v.r + v.b;\n  return max(v.a, smoothstep(0.5, 1.0, f) * 0.35) + (v.g - 0.5) * uCrawl * smoothstep(0.55, 0.95, f);\n}\nvoid main() {\n  vec2 uv = gl_FragCoord.xy / uCanvas;\n  vec4 c = texture(uField, uv);\n  float f = c.r + c.b;\n  float aa = fwidth(f) * 0.7 + 1e-4;\n  float alpha = smoothstep(0.5 - aa, 0.5 + aa, f);\n  if (alpha <= 0.0) {\n    outColor = vec4(0.0);\n    return;\n  }\n  vec2 dx = vec2(uTexel.x, 0.0);\n  vec2 dy = vec2(0.0, uTexel.y);\n  vec2 g = vec2(\n    height(texture(uField, uv + dx)) - height(texture(uField, uv - dx)),\n    height(texture(uField, uv + dy)) - height(texture(uField, uv - dy)));\n  vec3 n = normalize(vec3(-g * uRelief, 1.0));\n  vec3 key = normalize(normalize(vec3(-0.5, 0.65, 0.6)) + vec3(0.0, 0.0, 1.0));\n  vec3 fill = normalize(normalize(vec3(0.6, -0.45, 0.65)) + vec3(0.0, 0.0, 1.0));\n  float spec = pow(max(dot(n, key), 0.0), 70.0);\n  float sheen = pow(max(dot(n, key), 0.0), 10.0);\n  float back = pow(max(dot(n, fill), 0.0), 28.0);\n  vec2 side = n.xy / max(length(n.xy), 1e-4);\n  float rim = pow(1.0 - n.z, 3.0) * (0.3 + 0.7 * max(dot(side, vec2(-0.6, 0.8)), 0.0));\n  vec3 color = uColor + uHighlight * (spec * 1.1 + sheen * 0.07 + back * 0.25 + rim * 0.35);\n  outColor = vec4(min(color, vec3(1.0)) * alpha, alpha);\n}`\n\nconst clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value))\n\nconst compile = (gl: WebGL2RenderingContext, 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)) return shader\n  gl.deleteShader(shader)\n  return null\n}\n\nconst link = (gl: WebGL2RenderingContext, vertexSource: string, fragmentSource: string) => {\n  const vertex = compile(gl, gl.VERTEX_SHADER, vertexSource)\n  const fragment = compile(gl, gl.FRAGMENT_SHADER, fragmentSource)\n  const program = gl.createProgram()\n  if (!vertex || !fragment || !program) return null\n  gl.attachShader(program, vertex)\n  gl.attachShader(program, fragment)\n  gl.linkProgram(program)\n  gl.deleteShader(vertex)\n  gl.deleteShader(fragment)\n  if (gl.getProgramParameter(program, gl.LINK_STATUS)) return program\n  gl.deleteProgram(program)\n  return null\n}\n\nconst locate = (gl: WebGL2RenderingContext, program: WebGLProgram, names: string[]) =>\n  Object.fromEntries(names.map((name) => [name, gl.getUniformLocation(program, name)]))\n\n/** One row or column of the Felzenszwalb–Huttenlocher squared distance transform, in place. */\nconst transform1d = (\n  grid: Float64Array,\n  offset: number,\n  stride: number,\n  length: number,\n  f: Float64Array,\n  v: Uint32Array,\n  z: Float64Array,\n) => {\n  v[0] = 0\n  z[0] = -INF\n  z[1] = INF\n  for (let q = 0; q < length; q++) f[q] = grid[offset + q * stride]\n  for (let q = 1, k = 0, s = 0; q < length; q++) {\n    do {\n      const r = v[k]\n      s = (f[q] - f[r] + q * q - r * r) / (q - r) / 2\n    } while (s <= z[k] && --k > -1)\n    k++\n    v[k] = q\n    z[k] = s\n    z[k + 1] = INF\n  }\n  for (let q = 0, k = 0; q < length; q++) {\n    while (z[k + 1] < q) k++\n    const r = v[k]\n    grid[offset + q * stride] = f[r] + (q - r) * (q - r)\n  }\n}\n\nconst transform2d = (grid: Float64Array, width: number, height: number) => {\n  const size = Math.max(width, height)\n  const f = new Float64Array(size)\n  const v = new Uint32Array(size)\n  const z = new Float64Array(size + 1)\n  for (let x = 0; x < width; x++) transform1d(grid, x, width, height, f, v, z)\n  for (let y = 0; y < height; y++) transform1d(grid, y * width, 1, width, f, v, z)\n}\n\n/** A box blur along rows, then columns, in place. Run on a distance field it rounds the creases at inner corners. */\nconst blur = (grid: Float32Array, width: number, height: number, radius: number) => {\n  const line = new Float32Array(Math.max(width, height))\n  const pass = (count: number, length: number, at: (i: number, k: number) => number) => {\n    for (let i = 0; i < count; i++) {\n      for (let k = 0; k < length; k++) line[k] = grid[at(i, k)]\n      let sum = 0\n      for (let k = -radius; k <= radius; k++) sum += line[clamp(k, 0, length - 1)]\n      for (let k = 0; k < length; k++) {\n        grid[at(i, k)] = sum / (radius * 2 + 1)\n        sum += line[Math.min(k + radius + 1, length - 1)] - line[Math.max(k - radius, 0)]\n      }\n    }\n  }\n  pass(height, width, (y, x) => y * width + x)\n  pass(width, height, (x, y) => y * width + x)\n}\n\n/** Signed distance from an anti-aliased mask, in mask pixels: negative inside. Edge pixels use their coverage. */\nconst signedDistance = (pixels: Uint8ClampedArray, width: number, height: number) => {\n  const size = width * height\n  const outer = new Float64Array(size)\n  const inner = new Float64Array(size)\n  for (let i = 0; i < size; i++) {\n    const a = pixels[i * 4 + 3] / 255\n    const d = 0.5 - a\n    outer[i] = a === 1 ? 0 : a === 0 ? INF : d > 0 ? d * d : 0\n    inner[i] = a === 0 ? 0 : a === 1 ? INF : d < 0 ? d * d : 0\n  }\n  transform2d(outer, width, height)\n  transform2d(inner, width, height)\n  const out = new Float32Array(size)\n  for (let i = 0; i < size; i++) out[i] = Math.sqrt(outer[i]) - Math.sqrt(inner[i])\n  return out\n}\n\nconst makeTendril = (): Tendril => ({\n  planted: false,\n  ax: 0,\n  ay: 0,\n  nx: 0,\n  ny: 0,\n  tipX: 0,\n  tipY: 0,\n  vx: 0,\n  vy: 0,\n  aimX: 0,\n  aimY: 0,\n  ext: 0,\n  wait: Math.random() * 0.4,\n  letGo: false,\n  strain: 0,\n  seed: Math.random(),\n  spin: (Math.random() < 0.5 ? -1 : 1) * (0.8 + Math.random() * 1.6),\n  orbit: 6 + Math.random() * 22,\n  vigor: 0.7 + Math.random() * 0.6,\n  twigAt: 0.35 + Math.random() * 0.3,\n  twigSide: Math.random() < 0.5 ? -1 : 1,\n})\n\nexport function Venom({\n  text,\n  children,\n  color = \"#050507\",\n  highlight = \"#ffffff\",\n  tendrils = 8,\n  reach = 200,\n  thickness = 6,\n  writhe = 1,\n  boil = 1,\n  scale = 0.7,\n  fontFamily,\n  fontWeight = 300,\n  speed = 1,\n  paused = false,\n  dpr,\n  className,\n  style,\n  ...rest\n}: VenomProps) {\n  const rootRef = useRef<HTMLDivElement>(null)\n  const holderRef = useRef<HTMLDivElement>(null)\n  const settings: Settings = {\n    text: text ?? \"\",\n    svg: \"\",\n    color,\n    highlight,\n    tendrils,\n    reach,\n    thickness,\n    writhe,\n    boil,\n    scale,\n    fontFamily,\n    fontWeight,\n    speed: Math.max(0, speed),\n    paused,\n    dpr,\n  }\n  const settingsRef = useRef(settings)\n  const wakeRef = useRef<(() => void) | null>(null)\n\n  useEffect(() => {\n    const root = rootRef.current\n    if (!root) return\n\n    // The canvas is made here, not in JSX: React Strict Mode runs this effect twice in development, and the\n    // context the first cleanup loses would come straight back from getContext() on the same element.\n    const canvas = document.createElement(\"canvas\")\n    canvas.className = \"pointer-events-none absolute inset-0 block h-full w-full\"\n    canvas.setAttribute(\"aria-hidden\", \"true\")\n    const gl = canvas.getContext(\"webgl2\", {\n      alpha: true,\n      premultipliedAlpha: true,\n      antialias: false,\n      depth: false,\n      stencil: false,\n    })\n    if (!gl) return\n    // The shape is rasterised here once per change, and read back for its distance field.\n    const mask = document.createElement(\"canvas\")\n    const ctx = mask.getContext(\"2d\", { willReadFrequently: true })\n    if (!ctx) return\n\n    const fieldProgram = link(gl, FULLSCREEN, FIELD)\n    const tendrilProgram = link(gl, TENDRIL_VERTEX, TENDRIL_FRAGMENT)\n    const shadeProgram = link(gl, FULLSCREEN, SHADE)\n    if (!fieldProgram || !tendrilProgram || !shadeProgram) return\n    root.appendChild(canvas)\n\n    const fieldUniforms = locate(gl, fieldProgram, [\n      \"uSdf\",\n      \"uView\",\n      \"uField\",\n      \"uTime\",\n      \"uUnit\",\n      \"uBoil\",\n      \"uSoft\",\n      \"uDome\",\n      \"uPull\",\n    ])\n    const tendrilUniforms = locate(gl, tendrilProgram, [\"uView\", \"uSoft\", \"uDome\"])\n    const shadeUniforms = locate(gl, shadeProgram, [\n      \"uField\",\n      \"uCanvas\",\n      \"uTexel\",\n      \"uColor\",\n      \"uHighlight\",\n      \"uRelief\",\n      \"uCrawl\",\n    ])\n\n    // Half floats keep the relief smooth; plain bytes are the fallback where they cannot be rendered to.\n    const floatField = Boolean(gl.getExtension(\"EXT_color_buffer_float\"))\n    const fieldTexture = gl.createTexture()\n    const sdfTexture = gl.createTexture()\n    const framebuffer = gl.createFramebuffer()\n    for (const texture of [fieldTexture, sdfTexture]) {\n      gl.bindTexture(gl.TEXTURE_2D, texture)\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    }\n    gl.texImage2D(gl.TEXTURE_2D, 0, gl.R16F, 1, 1, 0, gl.RED, gl.FLOAT, new Float32Array([4096]))\n\n    const emptyVao = gl.createVertexArray()\n    const tendrilVao = gl.createVertexArray()\n    const instances = new Float32Array(MAX_CAPSULES * FLOATS)\n    const cornerBuffer = gl.createBuffer()\n    const instanceBuffer = gl.createBuffer()\n    gl.bindVertexArray(tendrilVao)\n    gl.bindBuffer(gl.ARRAY_BUFFER, cornerBuffer)\n    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW)\n    gl.enableVertexAttribArray(0)\n    gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0)\n    gl.bindBuffer(gl.ARRAY_BUFFER, instanceBuffer)\n    gl.bufferData(gl.ARRAY_BUFFER, instances.byteLength, gl.DYNAMIC_DRAW)\n    gl.enableVertexAttribArray(1)\n    gl.vertexAttribPointer(1, 4, gl.FLOAT, false, FLOATS * 4, 0)\n    gl.vertexAttribDivisor(1, 1)\n    gl.enableVertexAttribArray(2)\n    gl.vertexAttribPointer(2, 2, gl.FLOAT, false, FLOATS * 4, 16)\n    gl.vertexAttribDivisor(2, 1)\n    gl.bindVertexArray(null)\n\n    const reduced = window.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches ?? false\n    const view = { width: 1, height: 1 }\n    const field = { width: 1, height: 1, ratio: 1 }\n    const shape = {\n      key: \"\",\n      generation: 0,\n      sdf: new Float32Array([INF]),\n      width: 1,\n      height: 1,\n      edge: new Float32Array(0),\n      edges: 0,\n      unit: 1,\n      /** Half the width of the shape's thickest stroke, which sets how round the surface is. */\n      depth: 20,\n    }\n    const pointer = { x: 0, y: 0, inside: false }\n    const pull = { x: 0, y: 0, amount: 0 }\n    const swarm = Array.from({ length: MAX_TENDRILS }, makeTendril)\n    const line = new Float32Array(SEGMENTS * 2)\n    const widths = new Float32Array(SEGMENTS)\n    const colors = { key: \"\", body: [0, 0, 0], light: [1, 1, 1] }\n    let presence = 0\n    let capsules = 0\n    let time = 0\n    let clock = 0\n    let raf = 0\n    let last = 0\n    let visible = true\n\n    const parseColor = (value: string) => {\n      ctx.fillStyle = \"#000\"\n      ctx.fillStyle = value\n      const hex = String(ctx.fillStyle)\n      if (!hex.startsWith(\"#\")) return [1, 1, 1]\n      const n = parseInt(hex.slice(1), 16)\n      return [((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255]\n    }\n\n    const sampleShape = (x: number, y: number) => {\n      const { sdf, width, height } = shape\n      const gx = clamp((x / view.width) * width - 0.5, 0, width - 1)\n      const gy = clamp((y / view.height) * height - 0.5, 0, height - 1)\n      const x0 = Math.floor(gx)\n      const y0 = Math.floor(gy)\n      const x1 = Math.min(x0 + 1, width - 1)\n      const y1 = Math.min(y0 + 1, height - 1)\n      const fx = gx - x0\n      const fy = gy - y0\n      const top = sdf[y0 * width + x0] + (sdf[y0 * width + x1] - sdf[y0 * width + x0]) * fx\n      const bottom = sdf[y1 * width + x0] + (sdf[y1 * width + x1] - sdf[y1 * width + x0]) * fx\n      return top + (bottom - top) * fy\n    }\n\n    // The mask becomes a distance field in CSS pixels, the edge points tendrils grow from, and a size unit\n    // that keeps the boil and the crawl in proportion to the shape.\n    const measureShape = (width: number, height: number) => {\n      const sdf = signedDistance(ctx.getImageData(0, 0, width, height).data, width, height)\n      const toCss = view.width / width\n      for (let i = 0; i < sdf.length; i++) sdf[i] = clamp(sdf[i] * toCss, -4096, 4096)\n      // Liquid has no sharp inside corners: two passes of about 4 CSS pixels round them off.\n      const radius = Math.max(1, Math.round(4 / toCss))\n      blur(sdf, width, height, radius)\n      blur(sdf, width, height, radius)\n      const points: number[] = []\n      let depth = 0\n      let minX = Infinity\n      let maxX = -Infinity\n      let minY = Infinity\n      let maxY = -Infinity\n      for (let y = 1; y < height - 1; y++) {\n        for (let x = 1; x < width - 1; x++) {\n          const i = y * width + x\n          if (sdf[i] > 0) continue\n          depth = Math.max(depth, -sdf[i])\n          minX = Math.min(minX, x)\n          maxX = Math.max(maxX, x)\n          minY = Math.min(minY, y)\n          maxY = Math.max(maxY, y)\n          if (sdf[i - 1] > 0 || sdf[i + 1] > 0 || sdf[i - width] > 0 || sdf[i + width] > 0) {\n            const gx = sdf[i + 1] - sdf[i - 1]\n            const gy = sdf[i + width] - sdf[i - width]\n            const length = Math.hypot(gx, gy) || 1\n            points.push(((x + 0.5) / width) * view.width, ((y + 0.5) / height) * view.height, gx / length, gy / length)\n          }\n        }\n      }\n      const total = points.length / 4\n      const stride = Math.max(1, Math.ceil(total / EDGE_POINTS))\n      const edge = new Float32Array(Math.ceil(total / stride) * 4)\n      for (let i = 0, j = 0; i < total; i += stride, j += 4) {\n        for (let k = 0; k < 4; k++) edge[j + k] = points[i * 4 + k]\n      }\n      const size = total ? Math.sqrt((maxX - minX + 1) * (maxY - minY + 1)) * toCss : 200\n      Object.assign(shape, {\n        sdf,\n        width,\n        height,\n        edge,\n        edges: edge.length / 4,\n        unit: clamp(size / 200, 0.5, 2.5),\n        depth: depth || 20,\n      })\n      for (const tendril of swarm) tendril.letGo = tendril.planted\n      gl.bindTexture(gl.TEXTURE_2D, sdfTexture)\n      gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1)\n      gl.texImage2D(gl.TEXTURE_2D, 0, gl.R16F, width, height, 0, gl.RED, gl.FLOAT, sdf)\n    }\n\n    const rebuildShape = () => {\n      const s = settingsRef.current\n      const key = [view.width, view.height, s.scale, s.text, s.fontFamily, s.fontWeight, s.text ? \"\" : s.svg].join(\"|\")\n      if (key === shape.key) return\n      shape.key = key\n      const generation = ++shape.generation\n      const ratio = Math.min(1, Math.sqrt(SHAPE_BUDGET / (view.width * view.height)))\n      const width = Math.max(8, Math.round(view.width * ratio))\n      const height = Math.max(8, Math.round(view.height * ratio))\n      const fit = clamp(s.scale, 0.05, 1)\n      const prepare = () => {\n        mask.width = width\n        mask.height = height\n        ctx.clearRect(0, 0, width, height)\n        ctx.fillStyle = \"#000\"\n      }\n\n      if (s.text) {\n        prepare()\n        const family = s.fontFamily || getComputedStyle(root).fontFamily || \"sans-serif\"\n        ctx.font = `${s.fontWeight} 100px ${family}`\n        const m = ctx.measureText(s.text)\n        const glyphWidth = m.actualBoundingBoxLeft + m.actualBoundingBoxRight\n        const glyphHeight = m.actualBoundingBoxAscent + m.actualBoundingBoxDescent\n        if (glyphWidth > 0 && glyphHeight > 0) {\n          const k = Math.min((width * fit) / glyphWidth, (height * fit) / glyphHeight)\n          ctx.font = `${s.fontWeight} ${100 * k}px ${family}`\n          const x = width / 2 - ((m.actualBoundingBoxRight - m.actualBoundingBoxLeft) * k) / 2\n          const y = height / 2 + ((m.actualBoundingBoxAscent - m.actualBoundingBoxDescent) * k) / 2\n          ctx.fillText(s.text, x, y)\n        }\n        measureShape(width, height)\n        return\n      }\n\n      const svg = holderRef.current?.querySelector(\"svg\")\n      if (!svg) {\n        prepare()\n        measureShape(width, height)\n        return\n      }\n      const box = svg.viewBox?.baseVal\n      const aspect =\n        box && box.width > 0 && box.height > 0\n          ? box.width / box.height\n          : Number(svg.getAttribute(\"width\")) / Number(svg.getAttribute(\"height\")) || 1\n      const drawWidth = Math.min(width * fit, height * fit * aspect)\n      const drawHeight = drawWidth / aspect\n      const clone = svg.cloneNode(true) as SVGSVGElement\n      clone.setAttribute(\"width\", String(drawWidth))\n      clone.setAttribute(\"height\", String(drawHeight))\n      const image = new Image()\n      image.onload = () => {\n        if (generation !== shape.generation) return\n        prepare()\n        ctx.drawImage(image, (width - drawWidth) / 2, (height - drawHeight) / 2, drawWidth, drawHeight)\n        measureShape(width, height)\n        wake()\n      }\n      image.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(new XMLSerializer().serializeToString(clone))}`\n    }\n\n    /** The edge point nearest the pointer, and its distance. */\n    const nearestEdge = () => {\n      const { edge, edges } = shape\n      let nearest = -1\n      let closest = Infinity\n      for (let i = 0; i < edges; i++) {\n        const d = Math.hypot(edge[i * 4] - pointer.x, edge[i * 4 + 1] - pointer.y)\n        if (d < closest) {\n          closest = d\n          nearest = i\n        }\n      }\n      return [nearest, closest] as const\n    }\n\n    /** How directly the edge a tendril grows from faces the pointer, -1 to 1. */\n    const facing = (x: number, y: number, nx: number, ny: number) => {\n      const d = Math.hypot(pointer.x - x, pointer.y - y)\n      return d > 0.001 ? ((pointer.x - x) * nx + (pointer.y - y) * ny) / d : 1\n    }\n\n    const plant = (tendril: Tendril, nearest: number, closest: number, band: number) => {\n      const { edge, edges } = shape\n      if (nearest < 0) return\n      // Grow from near the pointer, on an edge that faces it, as far from the other tendrils as possible.\n      let pick = nearest\n      let best = -Infinity\n      for (let i = 0; i < edges; i++) {\n        const ex = edge[i * 4]\n        const ey = edge[i * 4 + 1]\n        const d = Math.hypot(ex - pointer.x, ey - pointer.y)\n        if (d > closest + band) continue\n        if (facing(ex, ey, edge[i * 4 + 2], edge[i * 4 + 3]) < 0.1) continue\n        let spacing = 120\n        for (const other of swarm) {\n          if (other !== tendril && other.planted) spacing = Math.min(spacing, Math.hypot(other.ax - ex, other.ay - ey))\n        }\n        const score = spacing + Math.random() * 30 - (d - closest) * 0.25\n        if (score > best) {\n          best = score\n          pick = i\n        }\n      }\n      Object.assign(tendril, {\n        planted: true,\n        ax: edge[pick * 4],\n        ay: edge[pick * 4 + 1],\n        nx: edge[pick * 4 + 2],\n        ny: edge[pick * 4 + 3],\n        tipX: edge[pick * 4],\n        tipY: edge[pick * 4 + 1],\n        vx: 0,\n        vy: 0,\n        ext: 0,\n        strain: 0,\n        letGo: false,\n      })\n    }\n\n    // Moves the swarm one step. Returns whether anything is still moving.\n    const update = (dt: number) => {\n      const s = settingsRef.current\n      const count = reduced ? 0 : clamp(Math.round(s.tendrils), 0, MAX_TENDRILS)\n      const reachPx = Math.max(1, s.reach)\n      const longest = reachPx * 1.5\n      const distance = pointer.inside && shape.edges ? sampleShape(pointer.x, pointer.y) : Infinity\n      const near = !reduced && distance < reachPx\n      // Over the shape the symbiote already has the pointer: the tendrils go back in and the surface swells.\n      const active = near && distance > 0\n      presence += ((active ? 1 : 0) - presence) * (1 - Math.exp(-dt / 0.3))\n\n      // The body swells towards the pointer from the point of its edge nearest to it, or under it.\n      let pullTarget = 0\n      if (near) {\n        const gx = sampleShape(pointer.x + 2, pointer.y) - sampleShape(pointer.x - 2, pointer.y)\n        const gy = sampleShape(pointer.x, pointer.y + 2) - sampleShape(pointer.x, pointer.y - 2)\n        const length = Math.hypot(gx, gy) || 1\n        const lean = Math.max(0, distance)\n        const qx = pointer.x - (gx / length) * lean\n        const qy = pointer.y - (gy / length) * lean\n        const follow = pull.amount < 0.05 ? 1 : 1 - Math.exp(-dt / 0.08)\n        pull.x += (qx - pull.x) * follow\n        pull.y += (qy - pull.y) * follow\n        pullTarget = s.thickness * 1.6 * (0.35 + 0.65 * (1 - clamp(distance / reachPx, 0, 1)))\n      }\n      pull.amount += (pullTarget - pull.amount) * (1 - Math.exp(-dt / 0.25))\n\n      const [nearest, closest] = active ? nearestEdge() : [-1, Infinity]\n      const band = Math.max(40, reachPx * 0.45)\n      let busy = near || presence > 0.002 || pull.amount > 0.05\n      for (let i = 0; i < MAX_TENDRILS; i++) {\n        const tendril = swarm[i]\n        const wanted = active && i < count && !tendril.letGo\n        if (!tendril.planted) {\n          if (!wanted) continue\n          tendril.wait -= dt\n          if (tendril.wait <= 0) plant(tendril, nearest, closest, band)\n          if (!tendril.planted) continue\n        }\n        if (active) {\n          tendril.aimX = pointer.x\n          tendril.aimY = pointer.y\n          // Rooted somewhere that no longer faces the pointer, or far from where it could grow now: let go,\n          // then grow again from a better place.\n          const from = Math.hypot(pointer.x - tendril.ax, pointer.y - tendril.ay)\n          if (from > closest + band * 1.6 || facing(tendril.ax, tendril.ay, tendril.nx, tendril.ny) < -0.2) {\n            tendril.letGo = true\n          }\n        }\n        const out = active && i < count && !tendril.letGo\n        tendril.ext = out\n          ? Math.min(1, tendril.ext + dt * 1.4 * tendril.vigor)\n          : Math.max(0, tendril.ext - dt * 2.2)\n        if (!out && tendril.ext === 0) {\n          tendril.planted = false\n          tendril.letGo = false\n          tendril.wait = Math.random() * 0.35\n          continue\n        }\n        busy = true\n\n        // The tips circle the pointer, as if trying to close around it, and strain when it is out of reach.\n        const angle = tendril.seed * TAU + clock * tendril.spin\n        let tx = tendril.aimX + Math.cos(angle) * tendril.orbit\n        let ty = tendril.aimY + Math.sin(angle) * tendril.orbit\n        const length = Math.hypot(tx - tendril.ax, ty - tendril.ay)\n        tendril.strain = clamp((length - longest) / longest, 0, 1)\n        if (length > longest) {\n          tx = tendril.ax + ((tx - tendril.ax) / length) * longest\n          ty = tendril.ay + ((ty - tendril.ay) / length) * longest\n        }\n        const stiffness = 70 * tendril.vigor\n        const damping = 0.9 * Math.sqrt(stiffness)\n        const steps = Math.ceil(dt * 120)\n        const h = dt / steps\n        for (let n = 0; n < steps; n++) {\n          tendril.vx += (stiffness * (tx - tendril.tipX) - damping * tendril.vx) * h\n          tendril.vy += (stiffness * (ty - tendril.tipY) - damping * tendril.vy) * h\n          tendril.tipX += tendril.vx * h\n          tendril.tipY += tendril.vy * h\n        }\n      }\n      return busy\n    }\n\n    // Writes the polyline in `line` and `widths` as one capsule per segment.\n    const emit = (points: number) => {\n      for (let j = 0; j < points - 1; j++) {\n        const o = capsules * FLOATS\n        instances[o] = line[j * 2]\n        instances[o + 1] = line[j * 2 + 1]\n        instances[o + 2] = line[j * 2 + 2]\n        instances[o + 3] = line[j * 2 + 3]\n        instances[o + 4] = widths[j]\n        instances[o + 5] = widths[j + 1]\n        capsules++\n      }\n    }\n\n    // A cubic from (x0, y0) leaving along (dx0, dy0), to (x3, y3) arriving along (dx3, dy3), with a travelling\n    // wave along its own normal so it is never a straight line.\n    const curve = (\n      points: number,\n      x0: number,\n      y0: number,\n      x1: number,\n      y1: number,\n      x2: number,\n      y2: number,\n      x3: number,\n      y3: number,\n      amplitude: number,\n      phase: number,\n      pace: number,\n    ) => {\n      for (let j = 0; j < points; j++) {\n        const s = j / (points - 1)\n        const u = 1 - s\n        const bx = u * u * u * x0 + 3 * u * u * s * x1 + 3 * u * s * s * x2 + s * s * s * x3\n        const by = u * u * u * y0 + 3 * u * u * s * y1 + 3 * u * s * s * y2 + s * s * s * y3\n        const dx = 3 * u * u * (x1 - x0) + 6 * u * s * (x2 - x1) + 3 * s * s * (x3 - x2)\n        const dy = 3 * u * u * (y1 - y0) + 6 * u * s * (y2 - y1) + 3 * s * s * (y3 - y2)\n        const length = Math.hypot(dx, dy) || 1\n        const wave =\n          (Math.sin(s * 9 - clock * 5 * pace + phase * 20) + 0.5 * Math.sin(s * 17 + clock * 3.3 + phase * 7)) *\n          amplitude *\n          Math.sin(Math.PI * s) ** 0.8\n        line[j * 2] = bx - (dy / length) * wave\n        line[j * 2 + 1] = by + (dx / length) * wave\n      }\n    }\n\n    const buildTendrils = () => {\n      const s = settingsRef.current\n      const thick = Math.max(1, s.thickness)\n      const writheAmount = Math.max(0, s.writhe)\n      capsules = 0\n      for (const tendril of swarm) {\n        if (!tendril.planted || tendril.ext <= 0.001) continue\n        const e = 1 - (1 - tendril.ext) ** 3\n        // The root starts inside the body so the two melt together.\n        const x0 = tendril.ax - tendril.nx * thick * 0.8\n        const y0 = tendril.ay - tendril.ny * thick * 0.8\n        const x3 = tendril.ax + (tendril.tipX - tendril.ax) * e\n        const y3 = tendril.ay + (tendril.tipY - tendril.ay) * e\n        const length = Math.hypot(x3 - x0, y3 - y0) || 0.001\n        const dx = (x3 - x0) / length\n        const dy = (y3 - y0) / length\n        const bend =\n          Math.sin(clock * 1.1 * tendril.spin + tendril.seed * 9) * 0.3 +\n          tendril.strain * Math.sin(clock * 13 + tendril.seed * 40) * 0.12\n        curve(\n          SEGMENTS,\n          x0,\n          y0,\n          x0 + tendril.nx * length * 0.4,\n          y0 + tendril.ny * length * 0.4,\n          x3 - dx * length * 0.35 - dy * length * bend,\n          y3 - dy * length * 0.35 + dx * length * bend,\n          x3,\n          y3,\n          Math.min(length * 0.08, thick * 2.4) * writheAmount * (1 + tendril.strain),\n          tendril.seed,\n          tendril.vigor,\n        )\n        // Tapers to a point, flares where it leaves the body as if pulled out of it, and pulses along its length.\n        for (let j = 0; j < SEGMENTS; j++) {\n          const s = j / (SEGMENTS - 1)\n          const taper = (1 - s) ** 0.8 + 0.35 * (1 - s) ** 6\n          widths[j] = thick * (0.3 + 0.7 * e) * taper * (1 + 0.22 * Math.sin(s * 12 - clock * 7 + tendril.seed * 5))\n        }\n        // The branch is read off the parent before the parent's line is overwritten.\n        const at = Math.round(tendril.twigAt * (SEGMENTS - 1))\n        const sx = line[at * 2]\n        const sy = line[at * 2 + 1]\n        const tx = line[at * 2 + 2] - line[at * 2 - 2]\n        const ty = line[at * 2 + 3] - line[at * 2 - 1]\n        const tangent = Math.hypot(tx, ty) || 1\n        const rootWidth = widths[at] * 0.75\n        emit(SEGMENTS)\n\n        const grown = clamp((tendril.ext - 0.35) / 0.65, 0, 1)\n        if (grown <= 0.01) continue\n        const twigLength = length * (1 - tendril.twigAt) * 0.6 * (1 - (1 - grown) ** 3)\n        const turn = tendril.twigSide * (0.75 + 0.3 * Math.sin(clock * 1.7 + tendril.seed * 3))\n        const ux = tx / tangent\n        const uy = ty / tangent\n        const vx = ux * Math.cos(turn) - uy * Math.sin(turn)\n        const vy = ux * Math.sin(turn) + uy * Math.cos(turn)\n        const ex = sx + vx * twigLength\n        const ey = sy + vy * twigLength\n        const sway = Math.sin(clock * 2.1 + tendril.seed * 11) * 0.2\n        curve(\n          TWIG_SEGMENTS,\n          sx,\n          sy,\n          sx + ux * twigLength * 0.45,\n          sy + uy * twigLength * 0.45,\n          ex - vx * twigLength * 0.3 - vy * twigLength * sway,\n          ey - vy * twigLength * 0.3 + vx * twigLength * sway,\n          ex,\n          ey,\n          Math.min(twigLength * 0.1, thick * 1.5) * writheAmount,\n          tendril.seed + 0.5,\n          tendril.vigor * 1.3,\n        )\n        for (let j = 0; j < TWIG_SEGMENTS; j++) widths[j] = rootWidth * (1 - j / (TWIG_SEGMENTS - 1)) ** 0.8\n        emit(TWIG_SEGMENTS)\n      }\n    }\n\n    const render = () => {\n      const s = settingsRef.current\n      if (s.color + s.highlight !== colors.key) {\n        colors.key = s.color + s.highlight\n        colors.body = parseColor(s.color)\n        colors.light = parseColor(s.highlight)\n      }\n      const thick = Math.max(1, s.thickness)\n      const soft = Math.max(4, thick * 0.8)\n      const boilAmount = reduced ? 0 : Math.max(0, s.boil)\n      const dome = clamp(shape.depth * 0.55, 4, 28)\n\n      gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer)\n      gl.viewport(0, 0, field.width, field.height)\n      gl.disable(gl.BLEND)\n      gl.useProgram(fieldProgram)\n      gl.activeTexture(gl.TEXTURE0)\n      gl.bindTexture(gl.TEXTURE_2D, sdfTexture)\n      gl.uniform1i(fieldUniforms.uSdf, 0)\n      gl.uniform2f(fieldUniforms.uView, view.width, view.height)\n      gl.uniform2f(fieldUniforms.uField, field.width, field.height)\n      gl.uniform1f(fieldUniforms.uTime, time)\n      gl.uniform1f(fieldUniforms.uUnit, shape.unit)\n      gl.uniform1f(fieldUniforms.uBoil, boilAmount * 2.6 * shape.unit)\n      gl.uniform1f(fieldUniforms.uSoft, soft)\n      gl.uniform1f(fieldUniforms.uDome, dome)\n      gl.uniform4f(fieldUniforms.uPull, pull.x, pull.y, pull.amount, thick * 3.5 + 18)\n      gl.bindVertexArray(emptyVao)\n      gl.drawArrays(gl.TRIANGLES, 0, 3)\n\n      if (capsules) {\n        // Overlapping capsules keep the larger value, so a chain reads as one smooth tube. The body is in R,\n        // which this pass leaves alone; the shading pass adds the two so they melt together.\n        gl.enable(gl.BLEND)\n        gl.blendFunc(gl.ONE, gl.ONE)\n        gl.blendEquation(gl.MAX)\n        gl.colorMask(false, false, true, true)\n        gl.useProgram(tendrilProgram)\n        gl.uniform2f(tendrilUniforms.uView, view.width, view.height)\n        gl.uniform1f(tendrilUniforms.uSoft, soft)\n        gl.uniform1f(tendrilUniforms.uDome, dome)\n        gl.bindVertexArray(tendrilVao)\n        gl.bindBuffer(gl.ARRAY_BUFFER, instanceBuffer)\n        gl.bufferSubData(gl.ARRAY_BUFFER, 0, instances, 0, capsules * FLOATS)\n        gl.drawArraysInstanced(gl.TRIANGLE_STRIP, 0, 4, capsules)\n        gl.colorMask(true, true, true, true)\n        gl.blendEquation(gl.FUNC_ADD)\n        gl.disable(gl.BLEND)\n      }\n\n      gl.bindFramebuffer(gl.FRAMEBUFFER, null)\n      gl.viewport(0, 0, canvas.width, canvas.height)\n      gl.useProgram(shadeProgram)\n      gl.bindTexture(gl.TEXTURE_2D, fieldTexture)\n      gl.uniform1i(shadeUniforms.uField, 0)\n      gl.uniform2f(shadeUniforms.uCanvas, canvas.width, canvas.height)\n      gl.uniform2f(shadeUniforms.uTexel, 1 / field.width, 1 / field.height)\n      gl.uniform3f(shadeUniforms.uColor, colors.body[0], colors.body[1], colors.body[2])\n      gl.uniform3f(shadeUniforms.uHighlight, colors.light[0], colors.light[1], colors.light[2])\n      // Height is in units of the dome, so this makes the slope at its middle about 45 degrees at any size.\n      gl.uniform1f(shadeUniforms.uRelief, dome * field.ratio * 0.5)\n      gl.uniform1f(shadeUniforms.uCrawl, 0.6 * boilAmount)\n      gl.bindVertexArray(emptyVao)\n      gl.drawArrays(gl.TRIANGLES, 0, 3)\n      gl.bindVertexArray(null)\n    }\n\n    const frame = (now: number) => {\n      raf = 0\n      if (!visible || document.hidden) return\n      const s = settingsRef.current\n      // dt is clamped so a tab switch does not jump the animation.\n      const dt = last ? clamp((now - last) / 1000, 1 / 240, 0.05) : 1 / 60\n      last = now\n      rebuildShape()\n      const crawling = !s.paused && !reduced && s.speed > 0\n      if (crawling) time += dt * s.speed\n      let busy = false\n      if (!s.paused) {\n        busy = update(dt)\n        if (busy) clock += dt * (s.speed > 0 ? s.speed : 1)\n      }\n      buildTendrils()\n      render()\n      // Keep looping only while something moves: the surface, or a tendril, or the pull of the pointer.\n      if (crawling || busy) raf ||= requestAnimationFrame(frame)\n      else last = 0\n    }\n\n    const wake = () => {\n      // Never schedule while off-screen or in a hidden tab.\n      if (!raf && visible && !document.hidden) raf = requestAnimationFrame(frame)\n    }\n\n    const resize = () => {\n      const s = settingsRef.current\n      view.width = Math.max(1, root.clientWidth)\n      view.height = Math.max(1, root.clientHeight)\n      const area = view.width * view.height\n      const ratio = Math.min(s.dpr || window.devicePixelRatio || 1, 2, Math.sqrt(PIXEL_BUDGET / area))\n      canvas.width = Math.max(1, Math.round(view.width * ratio))\n      canvas.height = Math.max(1, Math.round(view.height * ratio))\n      field.ratio = Math.min(ratio, 1, Math.sqrt(FIELD_BUDGET / area))\n      field.width = Math.max(1, Math.round(view.width * field.ratio))\n      field.height = Math.max(1, Math.round(view.height * field.ratio))\n      gl.bindTexture(gl.TEXTURE_2D, fieldTexture)\n      if (floatField) {\n        gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA16F, field.width, field.height, 0, gl.RGBA, gl.HALF_FLOAT, null)\n      } else {\n        gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, field.width, field.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null)\n      }\n      gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer)\n      gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fieldTexture, 0)\n      gl.bindFramebuffer(gl.FRAMEBUFFER, null)\n      wake()\n    }\n\n    const onMove = (event: PointerEvent) => {\n      if (reduced) return\n      const rect = root.getBoundingClientRect()\n      const x = event.clientX - rect.left\n      const y = event.clientY - rect.top\n      const inside = x >= 0 && y >= 0 && x <= rect.width && y <= rect.height\n      if (!inside && !pointer.inside) return\n      // The root may be scaled by CSS; the field lives in its layout pixels.\n      pointer.x = (x / rect.width) * view.width\n      pointer.y = (y / rect.height) * view.height\n      pointer.inside = inside\n      // Only a pointer within reach starts the loop; one leaving it finds the loop running and lets it settle.\n      if (inside && sampleShape(pointer.x, pointer.y) < settingsRef.current.reach) wake()\n    }\n\n    // A running loop sees this and lets the tendrils go back in; an idle one has nothing to undo.\n    const onLeave = () => {\n      pointer.inside = false\n    }\n\n    const onOut = (event: PointerEvent) => {\n      if (!event.relatedTarget) onLeave()\n    }\n\n    const onVisibility = () => {\n      last = 0\n      wake()\n    }\n\n    const onFonts = () => {\n      // A web font that finishes loading changes the shape of the text.\n      shape.key = \"\"\n      wake()\n    }\n\n    window.addEventListener(\"pointermove\", onMove, { passive: true })\n    window.addEventListener(\"pointerdown\", onMove, { passive: true })\n    window.addEventListener(\"pointerout\", onOut, { passive: true })\n    window.addEventListener(\"blur\", onLeave)\n    document.addEventListener(\"visibilitychange\", onVisibility)\n    document.fonts?.addEventListener(\"loadingdone\", onFonts)\n    const resizeObserver = new ResizeObserver(resize)\n    resizeObserver.observe(root)\n    const intersection = new IntersectionObserver((entries) => {\n      visible = entries.some((entry) => entry.isIntersecting)\n      if (visible) {\n        last = 0\n        wake()\n      }\n    })\n    intersection.observe(root)\n    resize()\n    wakeRef.current = wake\n\n    return () => {\n      cancelAnimationFrame(raf)\n      shape.generation++\n      wakeRef.current = null\n      resizeObserver.disconnect()\n      intersection.disconnect()\n      window.removeEventListener(\"pointermove\", onMove)\n      window.removeEventListener(\"pointerdown\", onMove)\n      window.removeEventListener(\"pointerout\", onOut)\n      window.removeEventListener(\"blur\", onLeave)\n      document.removeEventListener(\"visibilitychange\", onVisibility)\n      document.fonts?.removeEventListener(\"loadingdone\", onFonts)\n      gl.deleteBuffer(cornerBuffer)\n      gl.deleteBuffer(instanceBuffer)\n      gl.deleteVertexArray(tendrilVao)\n      gl.deleteVertexArray(emptyVao)\n      gl.deleteFramebuffer(framebuffer)\n      gl.deleteTexture(fieldTexture)\n      gl.deleteTexture(sdfTexture)\n      gl.deleteProgram(fieldProgram)\n      gl.deleteProgram(tendrilProgram)\n      gl.deleteProgram(shadeProgram)\n      gl.getExtension(\"WEBGL_lose_context\")?.loseContext()\n      canvas.remove()\n    }\n  }, [])\n\n  // Props reach the loop through a ref written here, never in render. The SVG is read from the hidden copy\n  // React keeps of it, so a changed icon is picked up like any other prop.\n  useEffect(() => {\n    settingsRef.current = { ...settings, svg: settings.text ? \"\" : (holderRef.current?.innerHTML ?? \"\") }\n    wakeRef.current?.()\n  })\n\n  return (\n    <div\n      ref={rootRef}\n      data-slot=\"venom\"\n      className={cn(\"relative h-full w-full overflow-hidden\", className)}\n      style={style}\n      {...rest}\n    >\n      {settings.text ? <span className=\"sr-only\">{settings.text}</span> : null}\n      {settings.text ? null : (\n        <div ref={holderRef} hidden>\n          {children}\n        </div>\n      )}\n    </div>\n  )\n}\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "added": "2026-10-23"
  },
  "categories": [
    "text"
  ],
  "type": "registry:ui"
}