{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"chrome-pour-reveal","type":"registry:component","title":"Chrome Pour Reveal","description":"A reveal that casts its content in liquid chrome: molten metal pours down over the space with drips racing ahead and merging into the sheet, then cools away from the top behind a hot seam of light.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/chrome-pour-reveal.tsx","content":"\"use client\";\n\nimport { createContext, useContext, useEffect, useId, useMemo, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { ReactNode, RefObject } from \"react\";\n\n/**\n * ChromePourReveal — a reveal that casts its content in liquid chrome.\n *\n * When it scrolls into view, molten chrome pours down over the space,\n * drips racing ahead of the sheet and merging into it as it falls (an SVG\n * goo filter), reflecting a room that stays still while the liquid moves\n * through it. Once covered, the chrome cools away from the top down behind\n * a hot seam of light, and the content is there. Runs once; stagger a grid\n * with `delay`. The content is always in the DOM and is only hidden while\n * the chrome pours; reduced motion shows it at once.\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 EASE = \"cubic-bezier(0.22, 1, 0.36, 1)\";\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\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/** A small seeded random generator, so every load draws the same thing. */\nfunction mulberry32(seed: number) {\n  let a = seed >>> 0;\n  return () => {\n    a = (a + 0x6d2b79f5) >>> 0;\n    let t = a;\n    t = Math.imul(t ^ (t >>> 15), t | 1);\n    t ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;\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\nexport type ChromePourRevealProps = {\n  children: ReactNode;\n  /** Milliseconds to wait once in view (stagger a grid with it). */\n  delay?: number;\n  /** Corner radius of what is being revealed, in px, so the metal fits it. */\n  radius?: number;\n  /** How many drips lead the pour. */\n  drips?: number;\n  finish?: string;\n  className?: string;\n};\n\ntype Phase = \"wait\" | \"pour\" | \"cool\" | \"done\";\n\n/**\n * A reveal that casts its content in liquid chrome. When it scrolls into\n * view, molten chrome pours down over the space, a few drips racing ahead\n * of the sheet and merging into it as it falls (an SVG goo filter), and the\n * metal reflects a room that stays still while the liquid moves through it.\n * Once the space is covered, the chrome cools away from the top down behind\n * a hot seam of light, and the content is there. It runs once. The content\n * is always in the DOM; it is only hidden while the chrome pours, never\n * without script, and reduced motion shows it at once.\n */\nexport function ChromePourReveal({ children, delay = 0, radius = 0, drips = 6, finish = \"chrome\", className }: ChromePourRevealProps) {\n  const tint = finishHex(finish);\n  const reduced = useReducedMotion();\n  const rootRef = useContext(ScrollRootContext);\n  const ref = useRef<HTMLDivElement>(null);\n  const coverRef = useRef<HTMLDivElement>(null);\n  const seamRef = useRef<HTMLDivElement>(null);\n  const sheetRef = useRef<SVGRectElement>(null);\n  const dripRefs = useRef<(SVGRectElement | null)[]>([]);\n  const gid = useId().replace(/[^a-zA-Z0-9]/g, \"\");\n  const [box, setBox] = useState({ w: 0, h: 0 });\n  const [phase, setPhase] = useState<Phase>(\"wait\");\n\n  useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const ro = new ResizeObserver(() => setBox((b) => (b.w === el.offsetWidth && b.h === el.offsetHeight ? b : { w: el.offsetWidth, h: el.offsetHeight })));\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n\n  // Start once a third of it (or 200px of a tall one) is in view, and only once it has a size.\n  const sized = box.w > 0 && box.h > 0;\n  useEffect(() => {\n    const el = ref.current;\n    if (!el || phase !== \"wait\" || !sized) return;\n    if (reduced) {\n      const t = setTimeout(() => setPhase(\"done\"), 0);\n      return () => clearTimeout(t);\n    }\n    let timer = 0;\n    const io = new IntersectionObserver(\n      (entries) => {\n        const e = entries[entries.length - 1];\n        if (e.isIntersecting && (e.intersectionRatio >= 0.33 || (e.intersectionRect?.height ?? 0) >= 200)) {\n          io.disconnect();\n          timer = window.setTimeout(() => setPhase(\"pour\"), delay);\n        }\n      },\n      { root: rootRef?.current ?? null, threshold: [0, 0.05, 0.1, 0.2, 0.33, 0.5, 1] },\n    );\n    io.observe(el);\n    return () => {\n      io.disconnect();\n      clearTimeout(timer);\n    };\n  }, [phase, reduced, delay, rootRef, sized]);\n\n  // The choreography: drips lead, the sheet follows, then the metal cools away.\n  useEffect(() => {\n    const sheet = sheetRef.current;\n    const cover = coverRef.current;\n    const seam = seamRef.current;\n    if (!sheet || !cover || !seam || box.h <= 0) return;\n    if (phase === \"pour\") {\n      const H = box.h;\n      const timing: KeyframeAnimationOptions = { duration: 860, delay: 60, easing: \"cubic-bezier(0.45, 0, 0.55, 1)\", fill: \"both\" };\n      // The sheet's front edge (its bottom) at the start and at the end.\n      const front0 = H + 20 - H * 1.15;\n      const front1 = H + 20;\n      const anims = dripRefs.current.map((d) => {\n        if (!d) return undefined;\n        const dh = d.height.baseVal.value;\n        // Each drip hangs from the front and stretches further ahead of it as it falls.\n        const lead = (k: number) => dh * (0.25 + 0.65 * k) * Number(d.dataset.lead || 1);\n        const at = (k: number) => `translateY(${(front0 + (front1 - front0) * k + lead(k) - dh).toFixed(1)}px)`;\n        return d.animate([{ transform: at(0) }, { transform: at(0.5), offset: 0.5 }, { transform: at(1) }], timing);\n      });\n      const a = sheet.animate([{ transform: `translateY(${-H * 1.15}px)` }, { transform: \"translateY(0px)\" }], timing);\n      a.onfinish = () => setPhase(\"cool\");\n      return () => {\n        a.onfinish = null;\n        anims.forEach((x) => x?.cancel());\n        a.cancel();\n      };\n    }\n    if (phase === \"cool\") {\n      const opts: KeyframeAnimationOptions = { duration: 700, easing: EASE, fill: \"both\" };\n      const m = cover.animate(\n        [\n          { WebkitMaskPosition: \"0 100%\", maskPosition: \"0 100%\" },\n          { WebkitMaskPosition: \"0 0%\", maskPosition: \"0 0%\" },\n        ],\n        opts,\n      );\n      seam.animate(\n        [\n          { top: \"-25%\", opacity: 1 },\n          { top: \"125%\", opacity: 0.3 },\n        ],\n        opts,\n      );\n      m.onfinish = () => setPhase(\"done\");\n      return () => {\n        m.onfinish = null;\n      };\n    }\n  }, [phase, box.h]);\n\n  const { w, h } = box;\n  // Drips: evenly spread columns with a seeded jitter, each a rounded bar.\n  // Seeded from the instance's id, so neighbours in a grid never drip alike.\n  const cols = useMemo(() => {\n    const count = Math.max(1, Math.min(16, Math.round(drips)));\n    let seed = 911 + count;\n    for (const ch of gid) seed = (seed * 31 + ch.charCodeAt(0)) >>> 0;\n    const rnd = mulberry32(seed);\n    return Array.from({ length: count }, (_, i) => {\n      const f = (i + 0.5 + (rnd() - 0.5) * 0.7) / count;\n      return { f, wf: 0.04 + rnd() * 0.06, hf: 0.2 + rnd() * 0.4, lead: 0.5 + rnd() * 0.9 };\n    });\n  }, [drips, gid]);\n  const covering = phase === \"wait\" || phase === \"pour\";\n  const g = (hex: string) => tinted(hex, tint);\n\n  return (\n    <div ref={ref} className={\"relative\" + (className ? \" \" + className : \"\")}>\n      {/* Hidden only while the chrome is on its way; always there for assistive technology. */}\n      <div style={{ opacity: sized && !reduced && (phase === \"pour\" || phase === \"wait\") ? 0 : 1 }}>{children}</div>\n      {phase !== \"done\" && sized && !reduced && (\n        <div aria-hidden className=\"pointer-events-none absolute inset-0 overflow-hidden\" style={{ borderRadius: radius, visibility: phase === \"wait\" ? \"hidden\" : \"visible\" }}>\n        <div\n          ref={coverRef}\n          className=\"absolute inset-0\"\n          style={{\n            // The cooling wipe: transparent above the seam, metal below it.\n            WebkitMaskImage: \"linear-gradient(180deg, transparent 0 40%, #000 60% 100%)\",\n            maskImage: \"linear-gradient(180deg, transparent 0 40%, #000 60% 100%)\",\n            WebkitMaskSize: \"100% 250%\",\n            maskSize: \"100% 250%\",\n            WebkitMaskPosition: \"0 100%\",\n            maskPosition: \"0 100%\",\n          }}\n        >\n          <svg width={w} height={h} className=\"block overflow-visible\">\n            <defs>\n              <linearGradient id={`${gid}-c`} gradientUnits=\"userSpaceOnUse\" x1=\"0\" y1=\"0\" x2=\"0\" y2={h}>\n                <stop offset=\"0\" stopColor={g(RAMP[3])} />\n                <stop offset=\"0.38\" stopColor={g(RAMP[2])} />\n                <stop offset=\"0.52\" stopColor={g(RAMP[1])} />\n                <stop offset=\"0.56\" stopColor={g(RAMP[0])} />\n                <stop offset=\"0.72\" stopColor={g(RAMP[1])} />\n                <stop offset=\"1\" stopColor={g(RAMP[2])} />\n              </linearGradient>\n              <filter id={`${gid}-goo`} x=\"-10%\" y=\"-20%\" width=\"120%\" height=\"140%\" colorInterpolationFilters=\"sRGB\">\n                <feGaussianBlur in=\"SourceGraphic\" stdDeviation={Math.max(4, Math.min(10, w * 0.02))} result=\"b\" />\n                <feColorMatrix in=\"b\" mode=\"matrix\" values=\"1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 22 -10\" />\n              </filter>\n            </defs>\n            <g filter={`url(#${gid}-goo)`} fill={`url(#${gid}-c)`}>\n              <rect ref={sheetRef} x={-20} y={-20} width={w + 40} height={h + 40} style={{ transform: covering ? `translateY(${-h * 1.2}px)` : undefined }} />\n              {cols.map((c, i) => {\n                const dw = Math.max(10, w * c.wf);\n                const dh = Math.max(dw * 1.4, h * c.hf);\n                return (\n                  <rect\n                    key={i}\n                    ref={(n) => {\n                      dripRefs.current[i] = n;\n                    }}\n                    data-lead={c.lead}\n                    x={c.f * w - dw / 2}\n                    y={0}\n                    width={dw}\n                    height={dh}\n                    rx={dw / 2}\n                    style={{ transform: `translateY(${-dh - 10}px)` }}\n                  />\n                );\n              })}\n            </g>\n          </svg>\n        </div>\n        {/* The hot seam rides the cooling edge, outside the mask so it stays bright. */}\n        <div ref={seamRef} className=\"absolute inset-x-0 h-[2px]\" style={{ top: \"-25%\", opacity: 0, background: \"#fff\", boxShadow: \"0 0 12px 2px rgba(255,255,255,0.8)\" }} />\n        </div>\n      )}\n    </div>\n  );\n}\n","type":"registry:component","target":"components/viberdy/chrome-pour-reveal.tsx"}],"meta":{"tier":"free","tags":["reveal","scroll","animation","chrome","liquid","goo","svg filter","drip"],"href":"https://viberdy.dev/library/chrome-pour-reveal","aiPrompt":"Build a React + Tailwind wrapper, `ChromePourReveal({ children, delay, radius, drips, finish })`, that reveals its content by pouring liquid chrome over it.\n\nPhases: wait, pour, cool, done. Measure the wrapper (ResizeObserver). An IntersectionObserver (root from a scroll context if there is one) starts the pour, after `delay`, once a third is visible. While waiting or pouring, the children are at opacity 0; they are always rendered.\n\nThe overlay (aria-hidden, pointer-events none, clipped with the given radius) holds an SVG the size of the wrapper: a vertical chrome linearGradient in user space (the four-band ramp times the finish) and a goo filter (feGaussianBlur of about 2% of the width, then an feColorMatrix alpha of 22a - 10, used on its own so the bridges between drips keep their colour). Inside the filtered group: a sheet rect slightly larger than the box and `drips` rounded bars at seeded columns (seeded from the instance id), each with its own width, length and lead. Pour with the Web Animations API over 860ms (ease in-out): the sheet from translateY(-115%) to 0, and each drip keyed to the sheet's front, hanging ahead of it by a lead that grows from 25% to 90% of its length. Then cool over 700ms: animate the overlay's mask-position so a transparent-to-opaque gradient (250% tall) wipes the metal away from the top, with a glowing 2px seam, outside the mask, riding the edge. Then remove the overlay. Reduced motion: done at once.\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"}}