{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"pour-fill-heading","type":"registry:component","title":"Pour Fill Heading","description":"A heading that starts as an empty mould and fills with liquid chrome as it scrolls into view, its surface a meniscus with a hot line of light that sloshes with scroll speed and settles.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/pour-fill-heading.tsx","content":"\"use client\";\n\nimport { createContext, useContext, useEffect, useRef, useSyncExternalStore } from \"react\";\nimport type { CSSProperties, RefObject } from \"react\";\n\n/**\n * PourFillHeading — a heading that fills with liquid chrome.\n *\n * At rest the letters are an empty mould (a hairline outline). As the\n * heading scrolls up the viewport, molten chrome rises inside them; its\n * surface is a meniscus, a wave with a hot line of light along it that\n * drifts slowly and sloshes with scroll speed before settling. Pass\n * `level` (0-1) to drive it yourself. Pure CSS masks and background clip:\n * no canvas. Reduced motion shows it filled.\n *\n * Part of the Liquid Chrome kit: a graphite room, a four-band chrome ramp\n * (#08090b, #4b4f58, #c9ced6, #ffffff) multiplied by a finish (chrome, gold,\n * rose, cobalt or any #rrggbb), foil colour only as a thin film. Fonts come\n * from CSS variables with Archivo and Geist fallbacks. Respects\n * prefers-reduced-motion. No dependencies beyond React. Paste it as its own\n * file: it repeats the kit's small helpers, which would clash in one module.\n */\n\nconst DISPLAY = 'var(--font-display, \"Archivo\", \"Helvetica Neue\", Arial, sans-serif)';\n\nconst LINE_2 = \"rgba(255,255,255,0.16)\";\n\nconst HEX = /^#[0-9a-fA-F]{6}$/;\n\n/** The reflected room, darkest to hottest. Every chrome surface in the kit reflects these four bands. */\nconst RAMP = [\"#08090b\", \"#4b4f58\", \"#c9ced6\", \"#ffffff\"] as const;\n\n/** Metal finishes: the colour the room is multiplied by. */\nexport const LC_FINISHES = {\n  chrome: \"#ffffff\",\n  gold: \"#f2cf92\",\n  rose: \"#f1bcb4\",\n  cobalt: \"#b9cbff\",\n} as const;\n\nfunction own<T extends object>(map: T, key: string): key is Extract<keyof T, string> {\n  return Object.prototype.hasOwnProperty.call(map, key);\n}\n\n/** A named finish or a #rrggbb tint; anything else falls back to chrome. */\nfunction finishHex(value: string): string {\n  if (own(LC_FINISHES, value)) return LC_FINISHES[value];\n  return HEX.test(value) ? value : LC_FINISHES.chrome;\n}\n\nfunction rgbOf(hex: string): [number, number, number] {\n  const n = parseInt(hex.slice(1), 16);\n  return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n}\n\n/** A ramp colour multiplied by the finish, as rgb(). */\nfunction tinted(hex: string, tint: string): string {\n  const a = rgbOf(hex);\n  const b = rgbOf(tint);\n  return `rgb(${Math.round((a[0] * b[0]) / 255)} ${Math.round((a[1] * b[1]) / 255)} ${Math.round((a[2] * b[2]) / 255)})`;\n}\n\n/** The finished ramp as the CSS variables every chrome gradient and the focus ring read. */\nfunction finishVars(tint: string): CSSProperties {\n  return {\n    \"--lc-0\": tinted(RAMP[0], tint),\n    \"--lc-1\": tinted(RAMP[1], tint),\n    \"--lc-2\": tinted(RAMP[2], tint),\n    \"--lc-3\": tinted(RAMP[3], tint),\n  } as CSSProperties;\n}\n\n/**\n * Chrome as a CSS gradient: bright sky, a hard dark horizon, a lit floor.\n * `--lc-h` moves the horizon (0-100), so a surface can turn in the room.\n */\nconst CHROME_BG =\n  \"linear-gradient(180deg, var(--lc-3) 0%, var(--lc-2) calc(var(--lc-h, 50) * 1% - 16%), var(--lc-1) calc(var(--lc-h, 50) * 1% - 2%), var(--lc-0) calc(var(--lc-h, 50) * 1%), var(--lc-1) calc(var(--lc-h, 50) * 1% + 14%), var(--lc-2) calc(var(--lc-h, 50) * 1% + 34%), var(--lc-3) 100%)\";\n\nfunction subscribeMotion(cb: () => void) {\n  const m = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n  m.addEventListener(\"change\", cb);\n  return () => m.removeEventListener(\"change\", cb);\n}\n\n/** True when the visitor asked for reduced motion. False on the server. */\nfunction useReducedMotion(): boolean {\n  return useSyncExternalStore(\n    subscribeMotion,\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\n/** The element that scrolls: null for the window, or the site itself in \"self\" mode. */\nconst ScrollRootContext = createContext<RefObject<HTMLElement | null> | null>(null);\n\nconst svgUrl = (svg: string) => `url(\"data:image/svg+xml,${encodeURIComponent(svg)}\")`;\n\n/** One period of the meniscus, 240 x 24, filled below the wave. */\nconst WAVE_FILL = svgUrl(\n  \"<svg xmlns='http://www.w3.org/2000/svg' width='240' height='24' viewBox='0 0 240 24' preserveAspectRatio='none'><path d='M0 12 Q30 3 60 12 T120 12 T180 12 T240 12 V24 H0 Z' fill='black'/></svg>\",\n);\n\n/** The same wave as a hot line of light, for the meniscus itself. */\nconst WAVE_LINE = svgUrl(\n  \"<svg xmlns='http://www.w3.org/2000/svg' width='240' height='24' viewBox='0 0 240 24' preserveAspectRatio='none'><path d='M0 13.5 Q30 4.5 60 13.5 T120 13.5 T180 13.5 T240 13.5' fill='none' stroke='white' stroke-width='2.5' vector-effect='non-scaling-stroke'/></svg>\",\n);\n\nexport type PourFillHeadingProps = {\n  text: string;\n  as?: \"h1\" | \"h2\" | \"h3\" | \"p\";\n  finish?: string;\n  /** Fill level 0-1. Leave unset and the heading fills as it scrolls up the viewport. */\n  level?: number;\n  align?: \"left\" | \"center\";\n  className?: string;\n  style?: CSSProperties;\n};\n\n/**\n * A heading that fills with liquid chrome. At rest the letters are an empty\n * mould (a hairline outline); as the heading scrolls up the viewport, molten\n * chrome rises inside them. The surface is a meniscus: a wave with a hot line\n * of light along it that drifts slowly and sloshes with scroll speed, then\n * settles. Every line of a wrapped heading reflects the same room. Pass\n * `level` to drive it yourself (a progress, a countdown). Reduced motion\n * shows it filled.\n */\nexport function PourFillHeading({ text, as: Tag = \"h2\", finish = \"chrome\", level, align = \"left\", className, style }: PourFillHeadingProps) {\n  const tint = finishHex(finish);\n  const reduced = useReducedMotion();\n  const rootRef = useContext(ScrollRootContext);\n  const ref = useRef<HTMLElement | null>(null);\n  const metalRef = useRef<HTMLSpanElement>(null);\n  // The surface survives prop changes: a new level eases from where the metal is.\n  const sim = useRef({ lv: 0, vel: 0, amp: 0.35, wx: 0 });\n  const levelRef = useRef(level);\n  const kickRef = useRef<() => void>(() => {});\n\n  useEffect(() => {\n    levelRef.current = level;\n    kickRef.current();\n  }, [level]);\n\n  useEffect(() => {\n    const el = ref.current;\n    const metal = metalRef.current;\n    if (!el || !metal) return;\n    const scroller: HTMLElement | Window = rootRef?.current ?? window;\n    const m = sim.current;\n    let raf = 0;\n    let last = 0;\n    let visible = false;\n    const goal = () => {\n      if (reduced) return 1;\n      const level = levelRef.current;\n      if (level !== undefined) return Math.max(0, Math.min(1, level));\n      const r = el.getBoundingClientRect();\n      const top = scroller instanceof Window ? 0 : scroller.getBoundingClientRect().top;\n      const vh = scroller instanceof Window ? window.innerHeight : scroller.clientHeight;\n      return Math.max(0, Math.min(1, (vh * 0.92 - (r.top - top)) / (vh * 0.55)));\n    };\n    const paint = () => {\n      const h = metal.offsetHeight;\n      metal.style.setProperty(\"--fy\", `${(h * (1 - m.lv)).toFixed(1)}px`);\n      metal.style.setProperty(\"--amp\", m.amp.toFixed(3));\n      metal.style.setProperty(\"--wx\", `${m.wx.toFixed(1)}px`);\n    };\n    const step = (now: number) => {\n      raf = 0;\n      const dt = last ? Math.min(0.05, (now - last) / 1000) : 0.016;\n      last = now;\n      const g = goal();\n      m.vel += ((g - m.lv) * 60 - m.vel * 11) * dt;\n      m.lv += m.vel * dt;\n      // Speed sloshes the surface; it settles back to a slow swell.\n      m.amp += (0.35 + Math.min(1.1, Math.abs(m.vel) * 2.4) - m.amp) * (1 - Math.exp(-dt * 6));\n      m.wx = (m.wx + dt * (8 + Math.abs(m.vel) * 260)) % 240;\n      paint();\n      const showing = m.lv > 0.002 && m.lv < 1.02;\n      const settling = Math.abs(g - m.lv) > 0.001 || Math.abs(m.vel) > 0.001;\n      if (visible && (settling || showing)) raf = requestAnimationFrame(step);\n      else last = 0;\n    };\n    const kick = () => {\n      if (!raf && visible) raf = requestAnimationFrame(step);\n    };\n    if (reduced) {\n      m.lv = 1;\n      m.vel = 0;\n      m.amp = 0;\n      paint();\n      return;\n    }\n    kickRef.current = kick;\n    const io = new IntersectionObserver((entries) => {\n      visible = entries[entries.length - 1].isIntersecting;\n      if (visible) kick();\n    });\n    io.observe(el);\n    scroller.addEventListener(\"scroll\", kick, { passive: true });\n    window.addEventListener(\"resize\", kick);\n    paint();\n    return () => {\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      scroller.removeEventListener(\"scroll\", kick);\n      window.removeEventListener(\"resize\", kick);\n      kickRef.current = () => {};\n    };\n  }, [reduced, rootRef]);\n\n  const strip = \"calc(var(--fy) - var(--amp) * 12px)\";\n  return (\n    <Tag\n      ref={(n: HTMLElement | null) => {\n        ref.current = n;\n      }}\n      className={\"lc-scope relative m-0\" + (className ? \" \" + className : \"\")}\n      style={{\n        ...finishVars(tint),\n        fontFamily: DISPLAY,\n        fontWeight: 800,\n        fontStretch: \"125%\",\n        fontSize: \"clamp(40px, 6.5cqw, 92px)\",\n        lineHeight: 1.02,\n        letterSpacing: \"-0.02em\",\n        textAlign: align,\n        textWrap: \"balance\",\n        ...style,\n      }}\n    >\n      {/* The empty mould. */}\n      <span className=\"block\" style={{ color: \"rgba(255,255,255,0.035)\", WebkitTextStroke: `1px ${LINE_2}` }}>\n        {text}\n      </span>\n      {/* The metal, masked below a moving meniscus. */}\n      <span\n        ref={metalRef}\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 block select-none\"\n        style={\n          {\n            \"--fy\": \"200%\",\n            \"--amp\": \"0.35\",\n            \"--wx\": \"0px\",\n            color: \"transparent\",\n            backgroundImage: `${WAVE_LINE}, ${CHROME_BG}`,\n            backgroundSize: \"240px calc(var(--amp) * 24px + 2px), 100% 1.02em\",\n            backgroundRepeat: \"repeat-x, repeat-y\",\n            backgroundPosition: `var(--wx) ${strip}, 0 0`,\n            WebkitBackgroundClip: \"text\",\n            backgroundClip: \"text\",\n            WebkitMaskImage: `${WAVE_FILL}, linear-gradient(#000, #000)`,\n            maskImage: `${WAVE_FILL}, linear-gradient(#000, #000)`,\n            WebkitMaskSize: \"240px calc(var(--amp) * 24px + 1px), 100% 100%\",\n            maskSize: \"240px calc(var(--amp) * 24px + 1px), 100% 100%\",\n            WebkitMaskRepeat: \"repeat-x, no-repeat\",\n            maskRepeat: \"repeat-x, no-repeat\",\n            WebkitMaskPosition: `var(--wx) ${strip}, 0 calc(var(--fy) + var(--amp) * 12px)`,\n            maskPosition: `var(--wx) ${strip}, 0 calc(var(--fy) + var(--amp) * 12px)`,\n          } as CSSProperties\n        }\n      >\n        {text}\n      </span>\n    </Tag>\n  );\n}\n","type":"registry:component","target":"components/viberdy/pour-fill-heading.tsx"}],"meta":{"tier":"free","tags":["text","heading","scroll","chrome","liquid","mask","css","y2k"],"href":"https://viberdy.dev/library/pour-fill-heading","aiPrompt":"Build a React + Tailwind heading, `PourFillHeading({ text, as, finish, level, align })`, that fills with liquid chrome.\n\nRender the heading (Archivo 800, expanded, 1.02 line height, balanced) with two spans: the visible text as an empty mould (transparent-ish fill, -webkit-text-stroke 1px at 16% white), and an aria-hidden absolute copy with transparent text and two background layers clipped to text: a wave line SVG (a stroked quadratic wave, 240x24, preserveAspectRatio none, non-scaling stroke) sized 240px by var(--amp)*24px at x var(--wx), y var(--fy) minus half the wave, repeating in x; and the chrome room gradient sized 100% by 1.02em, repeating per line. Mask the copy with the same wave filled below it, plus a solid gradient from the bottom of the wave down.\n\nOne spring loop (only while visible and while partly filled or moving): the goal is `level` if given, else scroll progress (the element's top from 92% to 37% of the viewport, or of the scroll container); velocity += ((goal - level) * 60 - velocity * 11) * dt; amplitude eases toward 0.35 + min(1.1, |velocity| * 2.4); the wave drifts 8px/s plus speed. Write --fy (height * (1 - level)), --amp and --wx. Reduced motion: filled and still.\n\nLiquid Chrome grammar: a graphite room (ground #0c0d10, panels #141519 and #1b1c21, hairlines white 7% and 16% drawn as inset box-shadows or SVG strokes, never border colours), ink #f4f5f7 at 94/62/40%. Chrome is a reflected room, never a flat grey gradient: four bands (#08090b, #4b4f58, #c9ced6, #ffffff) arranged as a bright sky over a hard dark horizon over a lit floor, multiplied by a finish (chrome #ffffff, gold #f2cf92, rose #f1bcb4, cobalt #b9cbff, or any #rrggbb validated against /^#[0-9a-fA-F]{6}$/) and handed to CSS as --lc-0 to --lc-3 with the horizon position in --lc-h. Colour appears only as a thin film on Newton's series (silver #d8dce2, champagne #eadfc4, magenta #d68fc7, cyan #8fd6d1, green #a8d68f, gold #d6b98f, violet #b48fd6, unevenly spaced), never a hue-rotate rainbow. Chrome goes only on heavy, curved forms (display type, pills, discs), never on hairlines. Display type is Archivo at 800 with font-stretch 125% and -0.02em tracking through var(--font-display, \"Archivo\", ...); UI in Geist; captions in Geist Mono, uppercase. Pills and 26px radii. The room eases toward the pointer in about 220ms, ambient drift runs 40s or slower, presses squash about 4% in 130ms. Keyframes and a focus ring (a .lc-scope rule with border-radius: revert-layer) live in a small static <style> the component renders itself; nothing is interpolated into it. Respect prefers-reduced-motion. No dependencies beyond React.","license":"https://viberdy.dev/license"}}