{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "motion-cutout-reveal",
  "type": "registry:component",
  "title": "Motion Cutout Reveal",
  "description": "Five paper-cut ridges start stacked over the whole frame and sink one after another as you scroll, front ridge first. The sky opens behind them, the sun rises and the headline settles above the hills.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "motion",
    "scroll",
    "parallax",
    "layers",
    "landscape",
    "reveal",
    "pinned"
  ],
  "docs": "https://hyperblur.dev/effects/motion-cutout-reveal",
  "files": [
    {
      "path": "registry/hyperblur/motion-cutout-reveal.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/motion-cutout-reveal.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface MotionCutoutRevealProps extends Omit<React.HTMLAttributes<HTMLElement>, \"title\"> {\n  eyebrow?: string;\n  title?: string;\n  hint?: string;\n  layers?: [string, string, string, string, string];\n  sky?: [string, string, string];\n  sun?: string;\n  progress?: number;\n  autoPlay?: boolean;\n  duration?: number;\n  length?: number;\n  height?: string;\n}\n\nconst W = 1200;\nconst BASE = [400, 470, 540, 610, 680];\nconst AMP = [70, 58, 46, 38, 30];\nconst STEPS = [9, 11, 8, 13, 10];\n\nfunction hash(n: number) {\n  let x = (n + 1) * 2654435761;\n  x = Math.imul(x ^ (x >>> 15), 2246822519);\n  x = Math.imul(x ^ (x >>> 13), 3266489917);\n  return (x ^ (x >>> 16)) >>> 0;\n}\n\nfunction ridge(layer: number) {\n  const count = STEPS[layer];\n  const pts: [number, number][] = [];\n  for (let i = 0; i <= count; i++) {\n    const x = (i / count) * (W + 80) - 40;\n    const h = hash(layer * 31 + i) / 4294967295;\n    const wave = Math.sin(i * 1.7 + layer * 2.1) * 0.5 + 0.5;\n    pts.push([x, BASE[layer] - AMP[layer] * (0.25 + 0.75 * (h * 0.6 + wave * 0.4))]);\n  }\n  let d = `M${pts[0][0].toFixed(1)} ${pts[0][1].toFixed(1)}`;\n  for (let i = 0; i < pts.length - 1; i++) {\n    const [x0, y0] = pts[Math.max(0, i - 1)];\n    const [x1, y1] = pts[i];\n    const [x2, y2] = pts[i + 1];\n    const [x3, y3] = pts[Math.min(pts.length - 1, i + 2)];\n    const c1x = x1 + (x2 - x0) / 6;\n    const c1y = y1 + (y2 - y0) / 6;\n    const c2x = x2 - (x3 - x1) / 6;\n    const c2y = y2 - (y3 - y1) / 6;\n    d += ` C${c1x.toFixed(1)} ${c1y.toFixed(1)} ${c2x.toFixed(1)} ${c2y.toFixed(1)} ${x2.toFixed(1)} ${y2.toFixed(1)}`;\n  }\n  d += ` L${W + 40} 1900 L-40 1900 Z`;\n  return d;\n}\n\nconst RIDGES = BASE.map((_, i) => ridge(i));\n\nconst STARS = Array.from({ length: 34 }, (_, i) => {\n  const h = hash(i + 500);\n  return { x: (h % 1200).toFixed(0), y: (((h >>> 11) % 300) + 20).toFixed(0), r: (((h >>> 22) % 3) * 0.5 + 0.8).toFixed(1) };\n});\n\nconst css = `\n.hb-wh6 {\n  position: relative;\n  width: 100%;\n  height: var(--hb-wh6-h);\n  color: #fff;\n  font-family: inherit;\n  background: #0b0a1c;\n}\n.hb-wh6[data-pinned=\"true\"] { height: calc(var(--hb-wh6-h) * var(--hb-wh6-len)); }\n.hb-wh6 *, .hb-wh6 *::before, .hb-wh6 *::after { box-sizing: border-box; }\n.hb-wh6-stage {\n  position: sticky;\n  top: 0;\n  height: var(--hb-wh6-h);\n  overflow: hidden;\n  container-type: size;\n  isolation: isolate;\n}\n.hb-wh6-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }\n.hb-wh6-stars { opacity: calc(0.9 - var(--hb-wh6-p) * 0.6); }\n.hb-wh6-fill { filter: drop-shadow(0 -10px 18px rgba(4, 3, 18, 0.55)); }\n.hb-wh6-copy {\n  position: absolute;\n  left: 0;\n  right: 0;\n  top: 8cqh;\n  z-index: 1;\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  padding: 0 6cqw;\n  text-align: center;\n  opacity: clamp(0, calc((var(--hb-wh6-p) - 0.45) * 3), 1);\n  transform: translateY(calc((1 - clamp(0, calc((var(--hb-wh6-p) - 0.45) * 2.2), 1)) * 24px));\n}\n.hb-wh6-eyebrow {\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: clamp(7px, 1.3cqw, 12px);\n  letter-spacing: 0.24em;\n  text-transform: uppercase;\n  color: rgba(255, 236, 220, 0.75);\n}\n.hb-wh6-title {\n  margin: 0.35em 0 0;\n  max-width: 18ch;\n  font-family: var(--font-grotesk, var(--font-sans, system-ui));\n  font-size: clamp(16px, min(6cqw, 9cqh), 84px);\n  font-weight: 600;\n  line-height: 1;\n  letter-spacing: -0.035em;\n  color: #fff7ef;\n  text-shadow: 0 2px 24px rgba(60, 20, 60, 0.45);\n}\n.hb-wh6-hint {\n  position: absolute;\n  left: 50%;\n  top: 50%;\n  z-index: 3;\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  gap: 0.6em;\n  transform: translate(-50%, -50%);\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: clamp(8px, 1.4cqw, 13px);\n  letter-spacing: 0.24em;\n  text-transform: uppercase;\n  white-space: nowrap;\n  color: rgba(255, 255, 255, 0.6);\n  opacity: clamp(0, calc(1 - var(--hb-wh6-p) * 5), 1);\n  pointer-events: none;\n}\n.hb-wh6-hint i {\n  width: 1px;\n  height: 2.6em;\n  background: linear-gradient(180deg, rgba(255, 255, 255, 0.6), transparent);\n}\n`;\n\nfunction clamp01(x: number) {\n  return Math.min(1, Math.max(0, x));\n}\n\nfunction inOut(x: number) {\n  return x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;\n}\n\nfunction findScroller(el: HTMLElement): HTMLElement | null {\n  let node = el.parentElement;\n  while (node && node !== document.body && node !== document.documentElement) {\n    const oy = getComputedStyle(node).overflowY;\n    if ((oy === \"auto\" || oy === \"scroll\" || oy === \"overlay\") && node.scrollHeight > node.clientHeight + 1) return node;\n    node = node.parentElement;\n  }\n  return null;\n}\n\nfunction loopAt(ms: number, duration: number) {\n  const d = Math.max(1, duration) * 1000;\n  const back = d * 0.6;\n  const hold = 1600;\n  const t = ms % (d + hold + back + 700);\n  if (t < d) return t / d;\n  if (t < d + hold) return 1;\n  if (t < d + hold + back) return 1 - inOut((t - d - hold) / back);\n  return 0;\n}\n\nfunction useProgress(\n  ref: React.RefObject<HTMLElement | null>,\n  apply: (p: number) => void,\n  progress: number | undefined,\n  autoPlay: boolean,\n  duration: number,\n) {\n  const applyRef = React.useRef(apply);\n  React.useLayoutEffect(() => {\n    applyRef.current = apply;\n  });\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const run = (p: number) => applyRef.current(clamp01(p));\n    if (typeof progress === \"number\") {\n      run(progress);\n      return;\n    }\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) {\n      run(1);\n      return;\n    }\n    let raf = 0;\n    if (autoPlay) {\n      let visible = true;\n      let last = 0;\n      let t = 0;\n      const io = new IntersectionObserver((entries) => {\n        visible = entries[0]?.isIntersecting ?? true;\n      });\n      io.observe(el);\n      const loop = (now: number) => {\n        const dt = last ? Math.min(64, now - last) : 0;\n        last = now;\n        if (visible) {\n          t += dt;\n          run(loopAt(t, duration));\n        }\n        raf = requestAnimationFrame(loop);\n      };\n      raf = requestAnimationFrame(loop);\n      return () => {\n        cancelAnimationFrame(raf);\n        io.disconnect();\n      };\n    }\n    const sc = findScroller(el);\n    const measure = () => {\n      raf = 0;\n      const r = el.getBoundingClientRect();\n      const top = sc ? r.top - sc.getBoundingClientRect().top : r.top;\n      const vh = sc ? sc.clientHeight : window.innerHeight;\n      const span = r.height - vh;\n      run(span > 1 ? -top / span : (vh - top) / (vh + r.height));\n    };\n    const onScroll = () => {\n      if (!raf) raf = requestAnimationFrame(measure);\n    };\n    measure();\n    const target: HTMLElement | Window = sc ?? window;\n    target.addEventListener(\"scroll\", onScroll, { passive: true });\n    window.addEventListener(\"resize\", onScroll);\n    return () => {\n      cancelAnimationFrame(raf);\n      target.removeEventListener(\"scroll\", onScroll);\n      window.removeEventListener(\"resize\", onScroll);\n    };\n  }, [ref, progress, autoPlay, duration]);\n}\n\nfunction layerShift(p: number, i: number) {\n  const e = inOut(clamp01((p - (4 - i) * 0.1) / 0.55));\n  return -(BASE[i] + 40) * (1 - e);\n}\n\nexport function MotionCutoutReveal({\n  eyebrow = \"Trail guide · Autumn 2027\",\n  title = \"Five ridges between you and the coast\",\n  hint = \"Scroll to open\",\n  layers = [\"#5b4a8c\", \"#40356f\", \"#2c2554\", \"#1d183d\", \"#110e27\"],\n  sky = [\"#1c1742\", \"#7a4f93\", \"#ffad7a\"],\n  sun = \"#ffd7a8\",\n  progress,\n  autoPlay = false,\n  duration = 5,\n  length = 3,\n  height = \"100vh\",\n  className,\n  style,\n  ...rest\n}: MotionCutoutRevealProps) {\n  const ref = React.useRef<HTMLElement>(null);\n  const groups = React.useRef<(SVGGElement | null)[]>([]);\n  const sunRef = React.useRef<SVGGElement>(null);\n  const uid = React.useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const pinned = progress === undefined && !autoPlay;\n  const start = typeof progress === \"number\" ? clamp01(progress) : 0;\n\n  useProgress(\n    ref,\n    (p) => {\n      const el = ref.current;\n      if (!el) return;\n      el.style.setProperty(\"--hb-wh6-p\", p.toFixed(4));\n      groups.current.forEach((g, i) => {\n        if (g) g.setAttribute(\"transform\", `translate(0 ${layerShift(p, i).toFixed(1)})`);\n      });\n      if (sunRef.current) sunRef.current.setAttribute(\"transform\", `translate(0 ${(220 * (1 - inOut(clamp01((p - 0.3) / 0.7)))).toFixed(1)})`);\n    },\n    progress,\n    autoPlay,\n    duration,\n  );\n\n  return (\n    <section\n      ref={ref}\n      className={[\"hb-wh6\", className].filter(Boolean).join(\" \")}\n      data-pinned={pinned ? \"true\" : \"false\"}\n      style={\n        {\n          \"--hb-wh6-h\": height,\n          \"--hb-wh6-len\": length,\n          \"--hb-wh6-p\": start,\n          background: layers[4],\n          ...style,\n        } as React.CSSProperties\n      }\n      {...rest}\n    >\n      <style href=\"hb-motion-cutout-reveal\" precedence=\"default\">{css}</style>\n      <div className=\"hb-wh6-stage\">\n        <svg className=\"hb-wh6-svg\" viewBox=\"0 0 1200 800\" preserveAspectRatio=\"xMidYMax slice\" aria-hidden=\"true\">\n          <defs>\n            <linearGradient id={`${uid}-sky`} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n              <stop offset=\"0\" stopColor={sky[0]} />\n              <stop offset=\"0.55\" stopColor={sky[1]} />\n              <stop offset=\"0.85\" stopColor={sky[2]} />\n            </linearGradient>\n            <radialGradient id={`${uid}-sun`}>\n              <stop offset=\"0\" stopColor={sun} stopOpacity=\"0.9\" />\n              <stop offset=\"1\" stopColor={sun} stopOpacity=\"0\" />\n            </radialGradient>\n          </defs>\n          <rect x=\"-200\" y=\"-400\" width=\"1600\" height=\"1400\" fill={`url(#${uid}-sky)`} />\n          <g className=\"hb-wh6-stars\">\n            {STARS.map((s, i) => (\n              <circle key={i} cx={s.x} cy={s.y} r={s.r} fill=\"#fff\" opacity=\"0.7\" />\n            ))}\n          </g>\n          <g ref={sunRef} transform={`translate(0 ${(220 * (1 - inOut(clamp01((start - 0.3) / 0.7)))).toFixed(1)})`}>\n            <circle cx=\"600\" cy=\"420\" r=\"230\" fill={`url(#${uid}-sun)`} />\n            <circle cx=\"600\" cy=\"420\" r=\"78\" fill={sun} />\n          </g>\n        </svg>\n        <div className=\"hb-wh6-copy\">\n          <span className=\"hb-wh6-eyebrow\">{eyebrow}</span>\n          <h2 className=\"hb-wh6-title\">{title}</h2>\n        </div>\n        <svg className=\"hb-wh6-svg\" viewBox=\"0 0 1200 800\" preserveAspectRatio=\"xMidYMax slice\" aria-hidden=\"true\" style={{ zIndex: 2 }}>\n          {RIDGES.map((d, i) => (\n            <g\n              key={i}\n              className=\"hb-wh6-layer\"\n              ref={(node) => {\n                groups.current[i] = node;\n              }}\n              transform={`translate(0 ${layerShift(start, i).toFixed(1)})`}\n            >\n              <path className=\"hb-wh6-fill\" d={d} fill={layers[i]} />\n              <path d={d} fill=\"none\" stroke=\"rgba(255,255,255,0.08)\" strokeWidth=\"1.5\" />\n            </g>\n          ))}\n        </svg>\n        {hint ? (\n          <div className=\"hb-wh6-hint\" aria-hidden=\"true\">\n            <span>{hint}</span>\n            <i />\n          </div>\n        ) : null}\n      </div>\n    </section>\n  );\n}\n"
    }
  ]
}