{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scroll-zoom-reveal",
  "type": "registry:component",
  "title": "Scroll Zoom Reveal",
  "description": "A small framed image that grows to fill the whole stage while the headline fades away. A caption fades in at the end.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "motion",
    "scroll",
    "zoom",
    "reveal",
    "image",
    "pinned",
    "hero"
  ],
  "docs": "https://hyperblur.dev/effects/scroll-zoom-reveal",
  "files": [
    {
      "path": "registry/hyperblur/scroll-zoom-reveal.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/scroll-zoom-reveal.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ScrollZoomRevealProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\"> {\n  title?: React.ReactNode;\n  subtitle?: React.ReactNode;\n  caption?: React.ReactNode;\n  src?: string;\n  alt?: string;\n  startInset?: number;\n  length?: number;\n  scroller?: React.RefObject<HTMLElement | null> | HTMLElement | null;\n  height?: number | string;\n  autoplay?: boolean;\n  accent?: string;\n}\n\ntype Scroller = React.RefObject<HTMLElement | null> | HTMLElement | null;\n\ninterface Frame {\n  sc: HTMLElement | null;\n  top: number;\n  vh: number;\n}\n\nconst css = `\n.hb-qm5 {\n  --hb-qm5-a: #ffb26b;\n  --hb-qm5-p: 0;\n  --hb-qm5-u: 100vh;\n  --hb-qm5-in: 33;\n  position: relative;\n  width: 100%;\n  color: #fff;\n  font-family: inherit;\n}\n.hb-qm5, .hb-qm5 * { box-sizing: border-box; }\n.hb-qm5-vp {\n  position: relative;\n  overflow-x: hidden;\n  overflow-y: auto;\n  overflow-anchor: none;\n  scrollbar-width: thin;\n  scrollbar-color: #2e2e2e transparent;\n  outline: none;\n}\n.hb-qm5-vp:focus-visible { outline: 2px solid var(--hb-qm5-a); outline-offset: -2px; }\n.hb-qm5-track { position: relative; width: 100%; }\n.hb-qm5-stage {\n  --hb-qm5-t: clamp(0, calc(var(--hb-qm5-p) / 0.85), 1);\n  --hb-qm5-e: calc(var(--hb-qm5-t) * var(--hb-qm5-t) * (3 - 2 * var(--hb-qm5-t)));\n  position: sticky;\n  top: 0;\n  height: var(--hb-qm5-u);\n  overflow: hidden;\n  container-type: inline-size;\n  background: var(--hb-qm5-bg, #0a0a0a);\n}\n.hb-qm5-frame {\n  position: absolute;\n  inset: 0;\n  overflow: hidden;\n  clip-path: inset(calc((1 - var(--hb-qm5-e)) * var(--hb-qm5-in) * 1%) round calc((1 - var(--hb-qm5-e)) * 16px));\n}\n.hb-qm5-media {\n  position: absolute;\n  inset: 0;\n  transform: scale(calc(1.45 - 0.45 * var(--hb-qm5-e)));\n  will-change: transform;\n}\n.hb-qm5-media svg {\n  display: block;\n  width: 100%;\n  height: 100%;\n}\n.hb-qm5-pic {\n  width: 100%;\n  height: 100%;\n  background-position: center;\n  background-size: cover;\n}\n.hb-qm5-ring {\n  position: absolute;\n  inset: calc((1 - var(--hb-qm5-e)) * var(--hb-qm5-in) * 1%);\n  z-index: 1;\n  border: 1px solid rgba(255, 255, 255, 0.22);\n  border-radius: calc((1 - var(--hb-qm5-e)) * 16px);\n  opacity: calc(1 - var(--hb-qm5-e) * 1.6);\n  pointer-events: none;\n}\n.hb-qm5-head {\n  position: absolute;\n  left: 0;\n  right: 0;\n  top: 6%;\n  z-index: 2;\n  padding: 0 1em;\n  text-align: center;\n  opacity: clamp(0, calc(1 - var(--hb-qm5-p) * 3.2), 1);\n  transform: translate3d(0, calc(var(--hb-qm5-p) * -30px), 0) scale(calc(1 + var(--hb-qm5-p) * 0.14));\n  pointer-events: none;\n}\n.hb-qm5-title {\n  margin: 0;\n  font-size: clamp(1.4em, 8.5cqw, 4.6em);\n  font-weight: 500;\n  line-height: 1;\n  letter-spacing: -0.02em;\n  color: #f4f4f4;\n}\n.hb-qm5-sub {\n  margin: 0.45em 0 0;\n  font-size: 0.78em;\n  letter-spacing: 0.06em;\n  text-transform: uppercase;\n  color: #8f8f8f;\n}\n.hb-qm5-hint {\n  position: absolute;\n  left: 0;\n  right: 0;\n  bottom: 7%;\n  z-index: 2;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  gap: 0.5em;\n  font-size: 0.72em;\n  letter-spacing: 0.1em;\n  text-transform: uppercase;\n  color: #8f8f8f;\n  opacity: clamp(0, calc(1 - var(--hb-qm5-p) * 7), 1);\n  pointer-events: none;\n}\n.hb-qm5-hint svg {\n  width: 1.3em;\n  height: 1.3em;\n  fill: none;\n  stroke: currentColor;\n  stroke-width: 1.8;\n  stroke-linecap: round;\n  stroke-linejoin: round;\n}\n.hb-qm5-cap {\n  position: absolute;\n  left: 0;\n  right: 0;\n  bottom: 0;\n  z-index: 2;\n  padding: 2.6em 1.3em 1.1em;\n  font-size: 0.95em;\n  background: linear-gradient(180deg, transparent, rgba(6, 6, 16, 0.7));\n  opacity: clamp(0, calc((var(--hb-qm5-p) - 0.72) * 5), 1);\n  transform: translate3d(0, calc((1 - clamp(0, (var(--hb-qm5-p) - 0.72) * 5, 1)) * 12px), 0);\n  pointer-events: none;\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-qm5-media, .hb-qm5-head { will-change: auto; }\n}\n`;\n\nfunction clamp(n: number) {\n  return Math.min(1, Math.max(0, n));\n}\n\nfunction pick(scroller: Scroller | undefined): HTMLElement | null {\n  if (!scroller) return null;\n  return \"current\" in scroller ? scroller.current : scroller;\n}\n\nfunction useScrollFrame(\n  rootRef: React.RefObject<HTMLElement | null>,\n  viewportRef: React.RefObject<HTMLElement | null>,\n  scroller: Scroller | undefined,\n  own: boolean,\n  unit: string,\n  onFrame: (frame: Frame) => void,\n) {\n  const latest = React.useRef(onFrame);\n\n  React.useEffect(() => {\n    latest.current = onFrame;\n  });\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    if (!root) return;\n    const sc = own ? viewportRef.current : pick(scroller);\n    const host: HTMLElement | Window = sc ?? window;\n    const run = () => {\n      const top = sc ? sc.getBoundingClientRect().top : 0;\n      const vh = sc ? sc.clientHeight : window.innerHeight;\n      if (sc && !own) root.style.setProperty(unit, `${vh}px`);\n      latest.current({ sc, top, vh });\n    };\n    host.addEventListener(\"scroll\", run, { passive: true });\n    window.addEventListener(\"resize\", run);\n    const ro = new ResizeObserver(run);\n    ro.observe(root);\n    if (sc) ro.observe(sc);\n    return () => {\n      host.removeEventListener(\"scroll\", run);\n      window.removeEventListener(\"resize\", run);\n      ro.disconnect();\n    };\n  }, [rootRef, viewportRef, scroller, own, unit]);\n}\n\nfunction useAutoScroll(viewportRef: React.RefObject<HTMLElement | null>, active: boolean) {\n  React.useEffect(() => {\n    const el = viewportRef.current;\n    if (!el || !active) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) {\n      el.scrollTop = (el.scrollHeight - el.clientHeight) * 0.45;\n      return;\n    }\n    let raf = 0;\n    let last = 0;\n    let pos = 0;\n    let dir = 1;\n    let hold = 700;\n    let idle = 0;\n    const touch = () => {\n      idle = performance.now() + 3200;\n    };\n    const tick = (now: number) => {\n      raf = requestAnimationFrame(tick);\n      const dt = Math.min(now - last, 50);\n      last = now;\n      const max = el.scrollHeight - el.clientHeight;\n      if (max <= 0) return;\n      if (now < idle) {\n        pos = el.scrollTop / max;\n        return;\n      }\n      if (hold > 0) {\n        hold -= dt;\n        return;\n      }\n      pos += (dir * dt) / 9000;\n      if (pos >= 1) {\n        pos = 1;\n        dir = -1;\n        hold = 900;\n      } else if (pos <= 0) {\n        pos = 0;\n        dir = 1;\n        hold = 900;\n      }\n      el.scrollTop = pos * max;\n    };\n    const io = new IntersectionObserver(([entry]) => {\n      if (entry.isIntersecting) {\n        if (!raf) {\n          last = performance.now();\n          raf = requestAnimationFrame(tick);\n        }\n      } else {\n        cancelAnimationFrame(raf);\n        raf = 0;\n      }\n    });\n    io.observe(el);\n    const events = [\"wheel\", \"touchstart\", \"pointerdown\", \"keydown\"] as const;\n    for (const name of events) el.addEventListener(name, touch, { passive: true });\n    return () => {\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      for (const name of events) el.removeEventListener(name, touch);\n    };\n  }, [viewportRef, active]);\n}\n\nfunction Scene({ uid }: { uid: string }) {\n  return (\n    <svg viewBox=\"0 0 400 240\" preserveAspectRatio=\"xMidYMid slice\" aria-hidden=\"true\">\n      <defs>\n        <linearGradient id={`${uid}s`} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n          <stop offset=\"0\" stopColor=\"#1a1b4d\" />\n          <stop offset=\"0.45\" stopColor=\"#7a3f8f\" />\n          <stop offset=\"0.72\" stopColor=\"#f07a6a\" />\n          <stop offset=\"1\" stopColor=\"#ffc47a\" />\n        </linearGradient>\n        <linearGradient id={`${uid}w`} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n          <stop offset=\"0\" stopColor=\"#3b2a73\" />\n          <stop offset=\"1\" stopColor=\"#0f0d2e\" />\n        </linearGradient>\n        <radialGradient id={`${uid}g`}>\n          <stop offset=\"0\" stopColor=\"#ffe0a8\" stopOpacity=\"0.8\" />\n          <stop offset=\"1\" stopColor=\"#ffe0a8\" stopOpacity=\"0\" />\n        </radialGradient>\n      </defs>\n      <rect width=\"400\" height=\"240\" fill={`url(#${uid}s)`} />\n      <circle cx=\"200\" cy=\"138\" r=\"86\" fill={`url(#${uid}g)`} />\n      <circle cx=\"200\" cy=\"138\" r=\"26\" fill=\"#fff1cf\" />\n      <path d=\"M0 150L52 112L96 140L150 100L210 146L262 118L318 146L360 124L400 148L400 160L0 160Z\" fill=\"#53307a\" opacity=\"0.8\" />\n      <path d=\"M0 160L40 140L84 158L132 132L186 160L248 140L300 162L352 146L400 160L400 170L0 170Z\" fill=\"#2f2063\" />\n      <rect y=\"156\" width=\"400\" height=\"84\" fill={`url(#${uid}w)`} />\n      <rect x=\"176\" y=\"164\" width=\"48\" height=\"2.5\" rx=\"1.25\" fill=\"#ffd9a0\" opacity=\"0.8\" />\n      <rect x=\"168\" y=\"174\" width=\"64\" height=\"2.5\" rx=\"1.25\" fill=\"#ffd9a0\" opacity=\"0.6\" />\n      <rect x=\"158\" y=\"185\" width=\"84\" height=\"2.5\" rx=\"1.25\" fill=\"#ffd9a0\" opacity=\"0.42\" />\n      <rect x=\"146\" y=\"197\" width=\"108\" height=\"2.5\" rx=\"1.25\" fill=\"#ffd9a0\" opacity=\"0.26\" />\n      <rect x=\"134\" y=\"210\" width=\"132\" height=\"2.5\" rx=\"1.25\" fill=\"#ffd9a0\" opacity=\"0.14\" />\n    </svg>\n  );\n}\n\nexport function ScrollZoomReveal({\n  title = \"Wide open\",\n  subtitle = \"Scroll to step inside\",\n  caption,\n  src,\n  alt = \"\",\n  startInset = 33,\n  length = 1.5,\n  scroller,\n  height,\n  autoplay = false,\n  accent = \"#ffb26b\",\n  className = \"\",\n  style,\n  ...rest\n}: ScrollZoomRevealProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const viewportRef = React.useRef<HTMLDivElement>(null);\n  const trackRef = React.useRef<HTMLDivElement>(null);\n  const uid = React.useId().replace(/:/g, \"\");\n  const own = height !== undefined;\n\n  useAutoScroll(viewportRef, own && autoplay);\n  useScrollFrame(rootRef, viewportRef, scroller, own, \"--hb-qm5-u\", ({ top, vh }) => {\n    const track = trackRef.current;\n    if (!track) return;\n    const rect = track.getBoundingClientRect();\n    const span = rect.height - vh;\n    const p = span > 0 ? clamp((top - rect.top) / span) : 0;\n    rootRef.current?.style.setProperty(\"--hb-qm5-p\", p.toFixed(4));\n  });\n\n  const body = (\n    <div\n      ref={trackRef}\n      className=\"hb-qm5-track\"\n      style={{ height: `calc(var(--hb-qm5-u) * ${(1 + Math.max(0.2, length)).toFixed(3)})` }}\n    >\n      <div className=\"hb-qm5-stage\">\n        <div className=\"hb-qm5-head\">\n          <h3 className=\"hb-qm5-title\">{title}</h3>\n          {subtitle ? <p className=\"hb-qm5-sub\">{subtitle}</p> : null}\n        </div>\n        <div className=\"hb-qm5-ring\" />\n        <div className=\"hb-qm5-frame\">\n          <div className=\"hb-qm5-media\">\n            {src ? (\n              <div\n                className=\"hb-qm5-pic\"\n                role={alt ? \"img\" : undefined}\n                aria-label={alt || undefined}\n                aria-hidden={alt ? undefined : true}\n                style={{ backgroundImage: `url(\"${src.replace(/\"/g, \"%22\")}\")` }}\n              />\n            ) : (\n              <Scene uid={uid} />\n            )}\n          </div>\n        </div>\n        <div className=\"hb-qm5-hint\" aria-hidden=\"true\">\n          <svg viewBox=\"0 0 24 24\">\n            <path d=\"M12 5v14M6 13l6 6 6-6\" />\n          </svg>\n          Scroll\n        </div>\n        {caption ? <div className=\"hb-qm5-cap\">{caption}</div> : null}\n      </div>\n    </div>\n  );\n\n  return (\n    <div\n      ref={rootRef}\n      className={`hb-qm5 ${className}`.trim()}\n      style={\n        {\n          \"--hb-qm5-a\": accent,\n          \"--hb-qm5-in\": Math.min(45, Math.max(0, startInset)),\n          ...(own ? { \"--hb-qm5-u\": typeof height === \"number\" ? `${height}px` : height } : null),\n          ...style,\n        } as React.CSSProperties\n      }\n      {...rest}\n    >\n      <style href=\"hb-scroll-zoom-reveal\" precedence=\"default\">\n        {css}\n      </style>\n      {own ? (\n        <div\n          ref={viewportRef}\n          className=\"hb-qm5-vp\"\n          style={{ height }}\n          tabIndex={0}\n          role=\"region\"\n          aria-label=\"Scrollable content\"\n        >\n          {body}\n        </div>\n      ) : (\n        body\n      )}\n    </div>\n  );\n}\n"
    }
  ]
}