{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "outline-fill",
  "type": "registry:component",
  "title": "Outline Fill",
  "description": "Outlined text that fills with liquid through a wave that starts where the cursor enters, and drains when it leaves.",
  "author": "Marcelo Treviño Velázquez <https://furin.dev>",
  "dependencies": [],
  "categories": [
    "Text"
  ],
  "docs": "Installed in components/furin/outline-fill/. Docs, live controls and props table: https://furin.dev/components/outline-fill/",
  "files": [
    {
      "path": "registry/outline-fill/OutlineFill.tsx",
      "content": "\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport type { CSSProperties, ReactNode } from \"react\";\nimport \"./OutlineFill.css\";\n\nexport interface OutlineFillProps {\n  /** Texto a mostrar. */\n  children?: ReactNode;\n  /** Tamaño máximo de la letra, en px (se ajusta al ancho). */\n  fontSize?: number;\n  /** Grosor de la letra. */\n  fontWeight?: number;\n  /** Color del líquido. */\n  color?: string;\n  /** Color del contorno. */\n  strokeColor?: string;\n  /** Grosor del contorno, en px. */\n  strokeWidth?: number;\n  /** Qué tan alta es la ola al entrar y salir. */\n  waveHeight?: number;\n  /** Se llena y se vacía solo cuando nadie lo toca. */\n  autoplay?: boolean;\n  /** Clase extra para el contenedor. */\n  className?: string;\n  /** Estilos extra para el contenedor. */\n  style?: CSSProperties;\n}\n\nfunction textOf(n: ReactNode): string {\n  if (n == null || typeof n === \"boolean\") return \"\";\n  if (typeof n === \"string\" || typeof n === \"number\") return String(n);\n  if (Array.isArray(n)) return n.map(textOf).join(\"\");\n  return \"\";\n}\n\nlet colorCtx: CanvasRenderingContext2D | null = null;\nfunction rgb255(color: string): [number, number, number] {\n  colorCtx ??= document.createElement(\"canvas\").getContext(\"2d\", { willReadFrequently: true })!;\n  colorCtx.clearRect(0, 0, 1, 1);\n  colorCtx.fillStyle = \"#000\";\n  colorCtx.fillStyle = color;\n  colorCtx.fillRect(0, 0, 1, 1);\n  const d = colorCtx.getImageData(0, 0, 1, 1).data;\n  return [d[0], d[1], d[2]];\n}\nconst mix = (c: [number, number, number], t: number, to: number) =>\n  `rgb(${Math.round(c[0] + (to - c[0]) * t)},${Math.round(c[1] + (to - c[1]) * t)},${Math.round(c[2] + (to - c[2]) * t)})`;\n\n/** Texto en contorno que se llena de líquido: una ola nace donde entra el cursor y se reparte por las letras. */\nexport function OutlineFill({\n  children = \"Waves\",\n  fontSize = 132,\n  fontWeight = 900,\n  color = \"#3FA9FF\",\n  strokeColor = \"rgba(255,255,255,0.9)\",\n  strokeWidth = 1.6,\n  waveHeight = 1,\n  autoplay = false,\n  className = \"\",\n  style,\n}: OutlineFillProps) {\n  const host = useRef<HTMLDivElement>(null);\n  const text = textOf(children);\n  const live = useRef({ color, strokeColor, strokeWidth, waveHeight, autoplay });\n  live.current = { color, strokeColor, strokeWidth, waveHeight, autoplay };\n  const wakeRef = useRef<() => void>(() => {});\n\n  useEffect(() => {\n    const el = host.current;\n    if (!el) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const canvas = document.createElement(\"canvas\");\n    canvas.className = \"furin-outline-fill__canvas\";\n    canvas.setAttribute(\"aria-hidden\", \"true\");\n    el.appendChild(canvas);\n    const ctx = canvas.getContext(\"2d\")!;\n    const lq = document.createElement(\"canvas\");\n    const lctx = lq.getContext(\"2d\")!;\n\n    const lines = text.split(\"\\n\");\n    const N = 150;\n    const h = new Float32Array(N);\n    const v = new Float32Array(N);\n    let W = 0, H = 0, dpr = 1, fs = fontSize, lh = fs;\n    let family = \"system-ui, sans-serif\";\n    let L = 0, Lv = 0, T = 0, x0 = 0.5;\n    let time = 0, acc = 0, last = 0, raf = 0, visible = true;\n    let autoT = 0;\n    let inside = false;\n    let lastX = -1;\n    const bubbles = Array.from({ length: 16 }, (_, i) => ({ x: (i * 0.618 + 0.13) % 1, y: (i * 0.37) % 1, r: 1.4 + ((i * 7) % 5) * 0.7, s: 0.12 + ((i * 3) % 4) * 0.05 }));\n\n    const layout = () => {\n      W = el.clientWidth || 300;\n      dpr = Math.min(window.devicePixelRatio || 1, 2);\n      family = getComputedStyle(el).fontFamily || family;\n      ctx.font = `${fontWeight} 100px ${family}`;\n      const w100 = Math.max(...lines.map((l) => ctx.measureText(l).width), 1);\n      fs = Math.min(fontSize, (W * 0.92) / (w100 / 100));\n      lh = fs * 1.02;\n      H = Math.ceil(lines.length * lh + fs * 0.4);\n      el.style.height = `${H}px`;\n      for (const c of [canvas, lq]) {\n        c.width = Math.max(2, Math.round(W * dpr));\n        c.height = Math.max(2, Math.round(H * dpr));\n      }\n      cache.dark = cache.light = cache.ring = null;\n      cache.key = \"\";\n      draw();\n    };\n\n    const textPath = (c: CanvasRenderingContext2D, mode: \"fill\" | \"stroke\") => {\n      c.font = `${fontWeight} ${fs}px ${family}`;\n      c.textAlign = \"center\";\n      c.textBaseline = \"middle\";\n      c.lineJoin = \"round\";\n      c.miterLimit = 2;\n      lines.forEach((l, i) => {\n        const y = H / 2 + (i - (lines.length - 1) / 2) * lh + fs * 0.03;\n        if (mode === \"fill\") c.fillText(l, W / 2, y);\n        else c.strokeText(l, W / 2, y);\n      });\n    };\n\n    // Silueta \"unida\" de las letras. Las fuentes variables (San Francisco, Geist, Inter...) dibujan algunas letras con contornos que se\n    // solapan (la barra de la \"e\" cruza su ojo, la \"a\", la \"&\", el \"8\"...). Un strokeText traza CADA contorno, así que esas líneas\n    // internas aparecían dentro de la letra y la \"e\" se veía rota. Rellenar sí funciona (regla non-zero = la unión), de modo que el contorno\n    // y los bordes de volumen se derivan de la silueta rellena: nunca se traza texto para dibujarlos.\n    const K = 24;\n    const cache: { dark: HTMLCanvasElement | null; light: HTMLCanvasElement | null; ring: HTMLCanvasElement | null; key: string } = { dark: null, light: null, ring: null, key: \"\" };\n    const blank = () => {\n      const c = document.createElement(\"canvas\");\n      c.width = lq.width;\n      c.height = lq.height;\n      return c;\n    };\n    /** Silueta de las letras encogida r px hacia adentro (erosión: intersección de copias desplazadas en círculo), movida (dx, dy). */\n    const silhouette = (r: number, dx = 0, dy = 0) => {\n      const c = blank();\n      const g = c.getContext(\"2d\")!;\n      g.fillStyle = \"#fff\";\n      g.setTransform(dpr, 0, 0, dpr, dx * dpr, dy * dpr);\n      textPath(g, \"fill\");\n      if (r > 0.01) {\n        g.globalCompositeOperation = \"destination-in\";\n        for (let k = 0; k < K; k++) {\n          const a = (k / K) * Math.PI * 2;\n          g.setTransform(dpr, 0, 0, dpr, (dx + Math.cos(a) * r) * dpr, (dy + Math.sin(a) * r) * dpr);\n          textPath(g, \"fill\");\n        }\n      }\n      return c;\n    };\n    const minus = (a: HTMLCanvasElement, hole: HTMLCanvasElement) => {\n      const g = a.getContext(\"2d\")!;\n      g.setTransform(1, 0, 0, 1, 0, 0);\n      g.globalCompositeOperation = \"destination-out\";\n      g.drawImage(hole, 0, 0);\n      g.globalCompositeOperation = \"source-over\";\n      return a;\n    };\n    const tint = (a: HTMLCanvasElement, color: string) => {\n      const g = a.getContext(\"2d\")!;\n      g.setTransform(1, 0, 0, 1, 0, 0);\n      g.globalCompositeOperation = \"source-in\";\n      g.fillStyle = color;\n      g.fillRect(0, 0, a.width, a.height);\n      g.globalCompositeOperation = \"source-over\";\n      return a;\n    };\n    /** Bordes de volumen del líquido (oscuro hacia adentro y un filo de luz arriba-izquierda), siempre sobre la silueta unida. */\n    const edges = () => {\n      cache.dark ??= tint(minus(silhouette(0), silhouette(3.5)), \"rgba(0,12,40,0.38)\");\n      cache.light ??= tint(minus(silhouette(0), silhouette(1.5, 0.8, 1.4)), \"rgba(255,255,255,0.13)\");\n      return cache as { dark: HTMLCanvasElement; light: HTMLCanvasElement };\n    };\n    /** Contorno centrado en el borde de la silueta: (silueta dilatada w/2) menos (silueta erosionada w/2). */\n    const ringOf = (w: number, color: string) => {\n      const key = `${w}|${color}`;\n      if (cache.key !== key || !cache.ring) {\n        const c = blank();\n        const g = c.getContext(\"2d\")!;\n        g.setTransform(dpr, 0, 0, dpr, 0, 0);\n        g.fillStyle = \"#fff\";\n        g.strokeStyle = \"#fff\";\n        g.lineWidth = w;\n        textPath(g, \"fill\");\n        textPath(g, \"stroke\"); // dilata la silueta w/2 (las trazas internas quedan dentro y se borran abajo)\n        cache.ring = tint(minus(c, silhouette(w / 2)), color);\n        cache.key = key;\n      }\n      return cache.ring;\n    };\n\n    const surface = (i: number, lvl: number, back: boolean) => {\n      const x = (i / (N - 1)) * W;\n      const yBottom = H / 2 + (lines.length * lh) / 2 + fs * 0.05;\n      const yTop = H / 2 - (lines.length * lh) / 2 - fs * 0.5;\n      const amp = fs * 0.1 * live.current.waveHeight;\n      // El líquido se amontona donde entró el cursor y se reparte al subir.\n      const dx = (x / W - x0) / 0.24;\n      const heap = Math.exp(-dx * dx) * 4 * lvl * (1 - lvl) * fs * 0.42 * Math.min(1.4, live.current.waveHeight + 0.2);\n      const hh = back ? h[(i + 7) % N] * 0.7 : h[i];\n      const swell = Math.sin(x * 0.03 + time * (back ? 2.7 : 2.1) + (back ? 1.7 : 0)) * fs * 0.018 * Math.min(1, lvl * 6) * (back ? 1.3 : 1);\n      return yBottom + (yTop - yBottom) * lvl - hh * amp - heap + swell;\n    };\n\n    const draw = () => {\n      if (!W) return;\n      const col = rgb255(live.current.color);\n      const light = mix(col, 0.5, 255);\n      const base = mix(col, 0, 0);\n      const deep = mix(col, 0.55, 0);\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      ctx.clearRect(0, 0, W, H);\n      // Cuerpo de vidrio apenas visible: da peso a las letras vacías.\n      ctx.fillStyle = \"rgba(255,255,255,0.045)\";\n      textPath(ctx, \"fill\");\n\n      if (L > 0.004) {\n        lctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n        lctx.globalCompositeOperation = \"source-over\";\n        lctx.clearRect(0, 0, W, H);\n        const yBottom = H / 2 + (lines.length * lh) / 2 + fs * 0.05;\n        const lvl = Math.min(L, 1.02);\n        let minY = H;\n        for (let i = 0; i < N; i++) minY = Math.min(minY, surface(i, lvl, false));\n        const grad = lctx.createLinearGradient(0, minY - fs * 0.05, 0, yBottom + fs * 0.1);\n        grad.addColorStop(0, light);\n        grad.addColorStop(0.22, base);\n        grad.addColorStop(1, deep);\n        // capa de atrás: más oscura y desfasada, da profundidad al agua\n        lctx.globalAlpha = 0.65;\n        lctx.fillStyle = mix(col, 0.35, 0);\n        lctx.beginPath();\n        lctx.moveTo(0, H + 4);\n        for (let i = 0; i < N; i++) lctx.lineTo((i / (N - 1)) * W, surface(i, lvl, true));\n        lctx.lineTo(W, H + 4);\n        lctx.closePath();\n        lctx.fill();\n        lctx.globalAlpha = 1;\n        // capa frontal\n        lctx.fillStyle = grad;\n        lctx.beginPath();\n        lctx.moveTo(0, H + 4);\n        for (let i = 0; i < N; i++) lctx.lineTo((i / (N - 1)) * W, surface(i, lvl, false));\n        lctx.lineTo(W, H + 4);\n        lctx.closePath();\n        lctx.fill();\n        // menisco: el borde brillante del líquido\n        lctx.save();\n        lctx.beginPath();\n        for (let i = 0; i < N; i++) {\n          const x = (i / (N - 1)) * W;\n          const y = surface(i, lvl, false);\n          if (i === 0) lctx.moveTo(x, y);\n          else lctx.lineTo(x, y);\n        }\n        lctx.strokeStyle = \"rgba(255,255,255,0.85)\";\n        lctx.lineWidth = 2.2;\n        lctx.shadowColor = light;\n        lctx.shadowBlur = 10;\n        lctx.stroke();\n        lctx.restore();\n        // burbujas dentro del líquido\n        lctx.save();\n        lctx.lineWidth = 1;\n        for (const b of bubbles) {\n          const bx = b.x * W;\n          const yTopB = surface(Math.round(b.x * (N - 1)), lvl, false);\n          const by = yBottom - ((b.y + time * b.s) % 1) * (yBottom - yTopB);\n          if (by < yTopB + 4) continue;\n          lctx.strokeStyle = \"rgba(255,255,255,0.55)\";\n          lctx.beginPath();\n          lctx.arc(bx + Math.sin(time * 1.3 + b.x * 9) * 3, by, b.r, 0, Math.PI * 2);\n          lctx.stroke();\n          lctx.fillStyle = \"rgba(255,255,255,0.7)\";\n          lctx.beginPath();\n          lctx.arc(bx - b.r * 0.3 + Math.sin(time * 1.3 + b.x * 9) * 3, by - b.r * 0.3, b.r * 0.28, 0, Math.PI * 2);\n          lctx.fill();\n        }\n        lctx.restore();\n        // reflejo de vidrio en diagonal, como luz de ventana\n        const g2 = lctx.createLinearGradient(0, 0, W, H * 1.1);\n        g2.addColorStop(0, \"rgba(255,255,255,0)\");\n        g2.addColorStop(0.3, \"rgba(255,255,255,0)\");\n        g2.addColorStop(0.36, \"rgba(255,255,255,0.26)\");\n        g2.addColorStop(0.42, \"rgba(255,255,255,0)\");\n        g2.addColorStop(0.5, \"rgba(255,255,255,0.08)\");\n        g2.addColorStop(0.58, \"rgba(255,255,255,0)\");\n        lctx.fillStyle = g2;\n        lctx.fillRect(0, 0, W, H);\n        // recorta el líquido a las letras\n        lctx.globalCompositeOperation = \"destination-in\";\n        lctx.fillStyle = \"#fff\";\n        textPath(lctx, \"fill\");\n        // volumen de tubo: borde oscuro y luz suave hacia adentro (solo donde hay líquido). Sale de la silueta unida de las letras,\n        // no de strokeText (que dibujaría también los contornos internos de la \"e\", la \"a\"...).\n        lctx.globalCompositeOperation = \"source-atop\";\n        const e = edges();\n        lctx.setTransform(1, 0, 0, 1, 0, 0);\n        lctx.drawImage(e.dark, 0, 0);\n        lctx.drawImage(e.light, 0, 0);\n        lctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n        const g3 = lctx.createLinearGradient(0, H / 2 - (lines.length * lh) / 2, 0, H / 2 + (lines.length * lh) / 2);\n        g3.addColorStop(0, \"rgba(255,255,255,0.20)\");\n        g3.addColorStop(0.45, \"rgba(255,255,255,0)\");\n        lctx.fillStyle = g3;\n        lctx.fillRect(0, 0, W, H);\n        lctx.globalCompositeOperation = \"source-over\";\n        ctx.save();\n        ctx.setTransform(1, 0, 0, 1, 0, 0);\n        ctx.drawImage(lq, 0, 0);\n        ctx.restore();\n      }\n      // contorno: borde de la silueta unida, centrado, sin las líneas internas de las fuentes variables\n      if (live.current.strokeWidth > 0) {\n        ctx.setTransform(1, 0, 0, 1, 0, 0);\n        ctx.drawImage(ringOf(live.current.strokeWidth, live.current.strokeColor), 0, 0);\n      }\n    };\n\n    const splash = (nx: number, amount: number) => {\n      const c = nx * (N - 1);\n      for (let i = 0; i < N; i++) {\n        const d = (i - c) / 5;\n        v[i] -= amount * Math.exp(-d * d);\n      }\n    };\n\n    const stepWave = (dt: number) => {\n      acc += dt;\n      const sub = 1 / 120;\n      while (acc >= sub) {\n        acc -= sub;\n        for (let i = 0; i < N; i++) {\n          const a = h[i > 0 ? i - 1 : 0] + h[i < N - 1 ? i + 1 : N - 1] - 2 * h[i];\n          v[i] = (v[i] + a * 0.5) * 0.9935;\n        }\n        for (let i = 0; i < N; i++) h[i] += v[i];\n      }\n    };\n\n    const setTarget = (t: number, nx: number) => {\n      if (T === t) return;\n      T = t;\n      x0 = nx;\n      splash(nx, 0.9 * (t ? 1 : 0.7));\n      wake();\n    };\n\n    const frame = (now: number) => {\n      raf = 0;\n      const dt = Math.min(0.05, Math.max(0.001, (now - last) / 1000));\n      last = now;\n      time += dt;\n      // resorte del nivel con un poco de rebote, como líquido que se acomoda\n      Lv += ((T - L) * 38 - Lv * 9.5) * dt;\n      L += Lv * dt;\n      stepWave(dt);\n      if (live.current.autoplay && !inside) {\n        autoT += dt;\n        if (T === 0 && autoT > 1.1) {\n          autoT = 0;\n          setTarget(1, 0.12 + Math.random() * 0.22);\n        } else if (T === 1 && autoT > 3.2) {\n          autoT = 0;\n          setTarget(0, 0.55 + Math.random() * 0.3);\n        }\n      }\n      draw();\n      let energy = 0;\n      for (let i = 0; i < N; i++) energy += Math.abs(h[i]) + Math.abs(v[i]) * 20;\n      const moving = Math.abs(T - L) > 0.002 || Math.abs(Lv) > 0.004 || energy > 0.01 || L > 0.02;\n      if ((moving || live.current.autoplay) && visible && !reduce) raf = requestAnimationFrame(frame);\n    };\n    function wake() {\n      if (raf || !visible || reduce) return;\n      last = performance.now();\n      raf = requestAnimationFrame(frame);\n    }\n    wakeRef.current = () => {\n      draw();\n      wake();\n    };\n\n    const nxOf = (e: PointerEvent) => {\n      const r = el.getBoundingClientRect();\n      return Math.min(1, Math.max(0, (e.clientX - r.left) / r.width));\n    };\n    const onEnter = (e: PointerEvent) => {\n      inside = true;\n      lastX = e.clientX;\n      setTarget(1, nxOf(e));\n    };\n    const onMove = (e: PointerEvent) => {\n      if (!inside) onEnter(e);\n      const dx = Math.abs(e.clientX - lastX);\n      lastX = e.clientX;\n      if (dx > 0 && T === 1) {\n        splash(nxOf(e), Math.min(dx / 40, 1) * 0.16 * live.current.waveHeight);\n        wake();\n      }\n    };\n    const onLeave = (e: PointerEvent) => {\n      inside = false;\n      autoT = 0;\n      setTarget(0, nxOf(e));\n    };\n    el.addEventListener(\"pointerenter\", onEnter);\n    el.addEventListener(\"pointermove\", onMove);\n    el.addEventListener(\"pointerleave\", onLeave);\n    el.addEventListener(\"pointercancel\", onLeave);\n\n    const io = new IntersectionObserver(([en]) => {\n      visible = en.isIntersecting;\n      if (visible) wake();\n      else if (raf) {\n        cancelAnimationFrame(raf);\n        raf = 0;\n      }\n    });\n    io.observe(el);\n    let rz = 0;\n    const ro = new ResizeObserver(() => {\n      window.clearTimeout(rz);\n      rz = window.setTimeout(() => {\n        if (Math.abs(el.clientWidth - W) > 1) layout();\n      }, 60);\n    });\n    ro.observe(el);\n\n    if (reduce) L = 0.55; // estado quieto: medio lleno, sin movimiento\n    layout();\n    document.fonts?.ready.then(() => {\n      layout();\n    });\n    if (live.current.autoplay) wake();\n\n    return () => {\n      cancelAnimationFrame(raf);\n      window.clearTimeout(rz);\n      io.disconnect();\n      ro.disconnect();\n      el.removeEventListener(\"pointerenter\", onEnter);\n      el.removeEventListener(\"pointermove\", onMove);\n      el.removeEventListener(\"pointerleave\", onLeave);\n      el.removeEventListener(\"pointercancel\", onLeave);\n      wakeRef.current = () => {};\n      canvas.remove();\n    };\n  }, [text, fontSize, fontWeight]);\n\n  useEffect(() => {\n    wakeRef.current();\n  }, [color, strokeColor, strokeWidth, waveHeight, autoplay]);\n\n  return (\n    <div ref={host} className={`furin-outline-fill ${className}`} style={style}>\n      <span className=\"furin-outline-fill__sr\">{text}</span>\n    </div>\n  );\n}\n\nexport default OutlineFill;\n",
      "type": "registry:component",
      "target": "components/furin/outline-fill/OutlineFill.tsx"
    },
    {
      "path": "registry/outline-fill/OutlineFill.css",
      "content": ".furin-outline-fill {\n  position: relative;\n  display: block;\n  width: min(100%, 560px);\n  touch-action: pan-y;\n  user-select: none;\n  -webkit-user-select: none;\n  color: var(--furin-of-stroke, rgba(255, 255, 255, 0.9));\n}\n.furin-outline-fill__canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }\n.furin-outline-fill__sr {\n  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;\n  clip: rect(0 0 0 0); white-space: pre-line; border: 0;\n}\n",
      "type": "registry:file",
      "target": "components/furin/outline-fill/OutlineFill.css"
    }
  ]
}
