{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "parallax-layers-hero",
  "title": "Parallax Layers Hero",
  "description": "A drawn mountain range in depth layers that follow the pointer, with the headline set between the ridges so the near peaks pass in front of it. Takes your own artwork too.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/parallax-layers-hero/parallax-layers-hero.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type ParallaxTheme = \"dark\" | \"light\";\n\nexport interface ParallaxLayer {\n  /** Image to use for this layer. Transparent PNG or WebP works best. */\n  src?: string;\n  /** Anything else to draw on this layer. */\n  content?: React.ReactNode;\n  /** 0 stays still; 1 moves with the foreground. */\n  depth: number;\n  /** Put the layer in front of the title rather than behind it. */\n  front?: boolean;\n}\n\nexport interface ParallaxLayersHeroProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: ParallaxTheme;\n  /** Sits between the layers, so the near ridge passes in front of it. */\n  title?: string;\n  eyebrow?: string;\n  description?: string;\n  cta?: { label: string; href?: string; onClick?: () => void } | null;\n  /** Your own artwork. Leave it out for the drawn mountain range. */\n  layers?: ParallaxLayer[];\n  /** Multiplier for how far the layers travel. */\n  strength?: number;\n  /** Layers sway on their own when nothing is moving them. */\n  idleSway?: boolean;\n  /** Height from tablet width up, in px. */\n  minHeight?: number;\n}\n\nconst PALETTES = {\n  dark: {\n    sky: \"linear-gradient(180deg,#0A0E24 0%,#1E1745 34%,#6B2F6B 58%,#E0705F 76%,#F6B26B 90%)\",\n    sun: \"#FFD9A0\",\n    glow: \"rgba(255,190,130,0.55)\",\n    stars: \"#FFFFFF\",\n    ridges: [\"#8A4A78\", \"#4D2C63\", \"#241A42\", \"#0C0B1C\"],\n    mist: \"rgba(246,178,107,0.3)\",\n    facet: \"rgba(255,170,130,0.13)\",\n    title: \"#FFF4E4\",\n    text: \"#FFF4E4\",\n    sub: \"rgba(255,244,228,0.74)\",\n    btn: \"#FFF4E4\",\n    btnText: \"#0C0B1C\",\n  },\n  light: {\n    sky: \"linear-gradient(180deg,#8FC7E6 0%,#BFE0EA 38%,#F7E3C8 66%,#FFC998 88%)\",\n    sun: \"#FFF3D6\",\n    glow: \"rgba(255,226,170,0.8)\",\n    stars: \"transparent\",\n    ridges: [\"#A9C4CF\", \"#7FA3AE\", \"#4D7681\", \"#1C3A42\"],\n    mist: \"rgba(255,255,255,0.5)\",\n    facet: \"rgba(255,255,255,0.13)\",\n    title: \"#10303A\",\n    text: \"#F3FAFA\",\n    sub: \"rgba(243,250,250,0.8)\",\n    btn: \"#F3FAFA\",\n    btnText: \"#10303A\",\n  },\n};\n\n/** A rocky outline through the given peaks. Each span is split and nudged by a fixed integer sequence, so server and client agree. */\nfunction crags(peaks: [number, number][], rough: number, seed: number) {\n  let line = peaks;\n  let amount = rough;\n  let state = seed;\n  for (let pass = 0; pass < 5; pass++) {\n    const next: [number, number][] = [line[0]];\n    for (let i = 1; i < line.length; i++) {\n      const [ax, ay] = line[i - 1];\n      const [bx, by] = line[i];\n      state = (state * 9301 + 49297) % 233280;\n      const nudge = (state / 233280 - 0.5) * amount;\n      next.push(\n        [Math.round((ax + bx) / 2), Math.round((ay + by) / 2 + nudge)],\n        [bx, by],\n      );\n    }\n    line = next;\n    amount *= 0.56;\n  }\n  return `M-40 900L${line.map(([x, y]) => `${x} ${y}`).join(\"L\")}L1640 900Z`;\n}\n\n/** A band of pines along the bottom edge. */\nfunction pines(seed: number, base: number) {\n  let d = \"\";\n  for (let i = 0; i < 74; i++) {\n    const x = i * 22 + ((i * 37 + seed) % 13);\n    const h = 54 + ((i * 53 + seed) % 62);\n    const w = 13 + ((i * 29 + seed) % 8);\n    const y = base + ((i * 17) % 16);\n    d += `M${x} ${y - h}L${x + w} ${y}L${x - w} ${y}Z`;\n    d += `M${x} ${y - h * 0.68}L${x + w * 1.35} ${y + 12}L${x - w * 1.35} ${y + 12}Z`;\n  }\n  return `${d}M-20 ${base + 8}H1620V900H-20Z`;\n}\n\nconst STARS = Array.from({ length: 70 }, (_, i) => ({\n  x: (i * 197) % 1600,\n  y: (i * 89) % 380,\n  r: i % 5 === 0 ? 1.8 : 1.1,\n}));\n\nconst SUMMITS: [number, number][] = [\n  [172, 556],\n  [610, 262],\n  [1064, 352],\n  [1420, 520],\n];\n\nconst FAR = crags(\n  [\n    [-40, 480],\n    [120, 392],\n    [300, 476],\n    [470, 372],\n    [640, 462],\n    [820, 388],\n    [1000, 476],\n    [1180, 376],\n    [1360, 466],\n    [1520, 392],\n    [1640, 470],\n  ],\n  46,\n  7,\n);\nconst MID = crags(\n  [\n    [-40, 580],\n    [150, 462],\n    [340, 610],\n    [560, 430],\n    [760, 620],\n    [1010, 450],\n    [1230, 610],\n    [1420, 462],\n    [1640, 580],\n  ],\n  70,\n  21,\n);\nconst NEAR = crags(\n  [\n    [-40, 700],\n    [172, 556],\n    [352, 690],\n    [610, 262],\n    [846, 640],\n    [1064, 352],\n    [1240, 680],\n    [1420, 520],\n    [1640, 700],\n  ],\n  96,\n  43,\n);\nconst FRONT = pines(5, 820);\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nfunction Art({ children }: { children: React.ReactNode }) {\n  return (\n    <svg\n      viewBox=\"0 0 1600 900\"\n      preserveAspectRatio=\"xMidYMax slice\"\n      aria-hidden=\"true\"\n      className=\"absolute inset-0 size-full\"\n    >\n      {children}\n    </svg>\n  );\n}\n\nfunction drawnLayers(\n  pal: (typeof PALETTES)[\"dark\"],\n  glowId: string,\n): ParallaxLayer[] {\n  return [\n    {\n      depth: 0.05,\n      content: (\n        <Art>\n          {STARS.map((s) => (\n            <circle\n              key={`${s.x}-${s.y}`}\n              cx={s.x}\n              cy={s.y}\n              r={s.r}\n              fill={pal.stars}\n              opacity={0.7}\n            />\n          ))}\n        </Art>\n      ),\n    },\n    {\n      depth: 0.12,\n      content: (\n        <Art>\n          <defs>\n            <radialGradient id={glowId}>\n              <stop offset=\"0\" stopColor={pal.glow} />\n              <stop offset=\"1\" stopColor={pal.glow} stopOpacity=\"0\" />\n            </radialGradient>\n          </defs>\n          <circle cx=\"1130\" cy=\"430\" r=\"330\" fill={`url(#${glowId})`} />\n          <circle cx=\"1130\" cy=\"430\" r=\"82\" fill={pal.sun} />\n        </Art>\n      ),\n    },\n    {\n      depth: 0.22,\n      content: (\n        <Art>\n          <path d={FAR} fill={pal.ridges[0]} />\n        </Art>\n      ),\n    },\n    {\n      depth: 0.4,\n      content: (\n        <>\n          <Art>\n            <path d={MID} fill={pal.ridges[1]} />\n          </Art>\n          <div\n            className=\"absolute inset-x-0 top-[50%] h-[30%]\"\n            style={{\n              background: `linear-gradient(180deg, transparent, ${pal.mist} 55%, transparent)`,\n            }}\n          />\n        </>\n      ),\n    },\n    {\n      depth: 0.68,\n      front: true,\n      content: (\n        <Art>\n          <defs>\n            <clipPath id={`${glowId}-near`}>\n              <path d={NEAR} />\n            </clipPath>\n          </defs>\n          <path d={NEAR} fill={pal.ridges[2]} />\n          {/* The sunlit side of each summit. */}\n          <g clipPath={`url(#${glowId}-near)`}>\n            {SUMMITS.map(([x, y]) => (\n              <path\n                key={x}\n                d={`M${x} ${y - 20}L${x + 560} ${y + 900}L${x + 110} ${y + 900}L${x - 24} ${y + 190}Z`}\n                fill={pal.facet}\n              />\n            ))}\n          </g>\n        </Art>\n      ),\n    },\n    {\n      depth: 1,\n      front: true,\n      content: (\n        <Art>\n          <path d={FRONT} fill={pal.ridges[3]} />\n        </Art>\n      ),\n    },\n  ];\n}\n\nfunction Layer({ layer, reach }: { layer: ParallaxLayer; reach: number }) {\n  const x = -46 * layer.depth * reach;\n  const y = -20 * layer.depth * reach;\n  const lift = 0.22 * layer.depth * reach;\n  return (\n    <div\n      className=\"absolute -inset-x-[6%] -inset-y-[4%] will-change-transform\"\n      style={{\n        transform: `translate3d(calc(var(--px) * ${x}px), calc(var(--py) * ${y}px + var(--sy) * ${lift}px), 0)`,\n      }}\n    >\n      {layer.src ? (\n        // eslint-disable-next-line @next/next/no-img-element\n        <img\n          src={layer.src}\n          alt=\"\"\n          draggable={false}\n          className=\"absolute inset-0 size-full object-cover select-none\"\n        />\n      ) : (\n        layer.content\n      )}\n    </div>\n  );\n}\n\nexport function ParallaxLayersHero({\n  theme = \"dark\",\n  title = \"HIGHER\",\n  eyebrow = \"Trail season opens in May\",\n  description = \"Forty huts, six ranges and one map that works without a signal.\",\n  cta = { label: \"Plan a route\" },\n  layers,\n  strength = 1,\n  idleSway = true,\n  minHeight = 720,\n  className,\n  style,\n  ...props\n}: ParallaxLayersHeroProps) {\n  const pal = PALETTES[theme];\n  const reduce = useReducedMotion();\n  const rootRef = React.useRef<HTMLElement>(null);\n  const aim = React.useRef({ x: 0, y: 0, at: -1e9 });\n  const glowId = `parallax-glow-${React.useId().replace(/[^a-zA-Z0-9]/g, \"\")}`;\n  const list = layers ?? drawnLayers(pal, glowId);\n  const size = Math.min(19, 100 / (Math.max(title.length, 1) * 0.86));\n\n  // One loop eases the pointer position into CSS variables and only runs while the hero is on screen.\n  React.useEffect(() => {\n    const el = rootRef.current;\n    if (!el || reduce) return;\n    let raf = 0;\n    let prev = 0;\n    let x = 0;\n    let y = 0;\n    const frame = (now: number) => {\n      const dt = Math.min(0.05, prev ? (now - prev) / 1000 : 1 / 60);\n      prev = now;\n      let tx = aim.current.x;\n      let ty = aim.current.y;\n      if (idleSway && now - aim.current.at > 1400) {\n        tx = Math.sin(now / 2600) * 0.55;\n        ty = Math.cos(now / 3400) * 0.35;\n      }\n      const k = 1 - Math.exp(-dt * 4.5);\n      x += (tx - x) * k;\n      y += (ty - y) * k;\n      el.style.setProperty(\"--px\", x.toFixed(4));\n      el.style.setProperty(\"--py\", y.toFixed(4));\n      raf = requestAnimationFrame(frame);\n    };\n    const onScroll = () => {\n      const top = el.getBoundingClientRect().top;\n      el.style.setProperty(\"--sy\", Math.min(0, top).toFixed(1));\n    };\n    const io = new IntersectionObserver(([entry]) => {\n      cancelAnimationFrame(raf);\n      prev = 0;\n      if (entry.isIntersecting) raf = requestAnimationFrame(frame);\n    });\n    io.observe(el);\n    window.addEventListener(\"scroll\", onScroll, { passive: true });\n    return () => {\n      io.disconnect();\n      cancelAnimationFrame(raf);\n      window.removeEventListener(\"scroll\", onScroll);\n    };\n  }, [reduce, idleSway]);\n\n  const onMove = (e: React.PointerEvent<HTMLElement>) => {\n    if (e.pointerType !== \"mouse\") return;\n    const r = e.currentTarget.getBoundingClientRect();\n    aim.current = {\n      x: ((e.clientX - r.left) / r.width - 0.5) * 2,\n      y: ((e.clientY - r.top) / r.height - 0.5) * 2,\n      at: e.timeStamp,\n    };\n  };\n\n  const button =\n    \"inline-flex h-11 cursor-pointer items-center rounded-full px-6 text-[14px] font-semibold no-underline transition-opacity hover:opacity-85\";\n  return (\n    <section\n      ref={rootRef}\n      onPointerMove={onMove}\n      className={cn(\"@container relative w-full overflow-hidden\", className)}\n      style={\n        {\n          \"--px\": 0,\n          \"--py\": 0,\n          \"--sy\": 0,\n          \"--h\": `${minHeight}px`,\n          background: pal.sky,\n          color: pal.text,\n          fontFamily: \"Inter, -apple-system, BlinkMacSystemFont, sans-serif\",\n          ...style,\n        } as React.CSSProperties\n      }\n      {...props}\n    >\n      <div className=\"relative isolate flex min-h-[600px] flex-col @[640px]:min-h-[var(--h)]\">\n        {list\n          .filter((l) => !l.front)\n          .map((l, i) => (\n            <Layer key={i} layer={l} reach={strength} />\n          ))}\n\n        {/* The title lives between the back and front layers, at its own depth. */}\n        <div\n          className=\"absolute inset-x-0 top-[17%] text-center will-change-transform @[640px]:top-[12%]\"\n          style={{\n            color: pal.title,\n            transform: `translate3d(calc(var(--px) * ${-24 * strength}px), calc(var(--py) * ${-10 * strength}px), 0)`,\n          }}\n        >\n          {eyebrow && (\n            <p className=\"m-0 text-[13.5px] font-medium\">{eyebrow}</p>\n          )}\n          <h1\n            className=\"m-0 mt-3 font-black select-none\"\n            style={{\n              fontSize: `${size}cqw`,\n              letterSpacing: \"-0.035em\",\n              lineHeight: 0.9,\n            }}\n          >\n            {title}\n          </h1>\n        </div>\n\n        {list\n          .filter((l) => l.front)\n          .map((l, i) => (\n            <Layer key={i} layer={l} reach={strength} />\n          ))}\n\n        <div\n          aria-hidden=\"true\"\n          className=\"absolute inset-x-0 bottom-0 h-[34%]\"\n          style={{\n            background: `linear-gradient(to top, ${pal.ridges[3]} 34%, transparent)`,\n          }}\n        />\n        <div className=\"relative z-10 mt-auto flex flex-col items-start gap-4 p-6 @[640px]:flex-row @[640px]:items-end @[640px]:justify-between @[640px]:p-10\">\n          <p\n            className=\"m-0 max-w-[34ch] text-[15px] leading-snug\"\n            style={{ color: pal.sub }}\n          >\n            {description}\n          </p>\n          {cta &&\n            (cta.href ? (\n              <a\n                href={cta.href}\n                className={button}\n                style={{ background: pal.btn, color: pal.btnText }}\n              >\n                {cta.label}\n              </a>\n            ) : (\n              <button\n                type=\"button\"\n                onClick={cta.onClick}\n                className={button}\n                style={{ background: pal.btn, color: pal.btnText }}\n              >\n                {cta.label}\n              </button>\n            ))}\n        </div>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}