{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "parallax-section",
  "title": "Parallax Section",
  "description": "A section of floating photos and type that drift at different speeds as it scrolls past, so the layers separate into depth, and lean slightly toward the pointer; works with page scrolling and scroll containers alike.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/parallax-section/parallax-section.tsx",
      "content": "\"use client\";\n/* eslint-disable @next/next/no-img-element -- Registry components work in any React app. */\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 interface ParallaxLayer {\n  /** Image to show; or pass `content` for anything else. */\n  src?: string;\n  alt?: string;\n  content?: React.ReactNode;\n  /** How far the layer travels while the section crosses the screen. 0 = still, negative = against the scroll. */\n  speed: number;\n  /** How strongly the layer follows the pointer. Defaults to its speed. */\n  depth?: number;\n  className?: string;\n  style?: React.CSSProperties;\n}\n\nexport interface ParallaxSectionProps extends Omit<React.ComponentPropsWithoutRef<\"section\">, \"children\"> {\n  layers?: ParallaxLayer[];\n  /** Foreground content, drawn above the layers at speed 0. */\n  children?: React.ReactNode;\n  height?: number;\n  /** Pixels of travel per unit of speed. */\n  distance?: number;\n  /** Layers also shift a little with the pointer. */\n  pointer?: boolean;\n  theme?: \"dark\" | \"light\";\n}\n\nconst LAYERS: ParallaxLayer[] = [\n  { content: <span className=\"block text-[min(26vw,260px)] leading-none font-semibold tracking-[-0.06em] opacity-30 [-webkit-text-fill-color:transparent] [-webkit-text-stroke:1.5px_currentColor]\">Depth</span>, speed: -0.6, className: \"left-1/2 top-[14%] -translate-x-1/2\" },\n  { src: \"/demo/19.webp\", speed: 0.5, className: \"left-[6%] top-[18%] w-[24%] aspect-[3/4] rounded-[14px] overflow-hidden\" },\n  { src: \"/demo/38.webp\", speed: 1.4, className: \"right-[7%] top-[8%] w-[22%] aspect-[4/5] rounded-[14px] overflow-hidden\" },\n  { src: \"/demo/2.webp\", speed: 2.2, className: \"left-[30%] bottom-[-6%] w-[18%] aspect-square rounded-[14px] overflow-hidden\" },\n  { src: \"/demo/108.webp\", speed: 0.9, className: \"right-[24%] bottom-[10%] w-[15%] aspect-[4/3] rounded-[14px] overflow-hidden\" },\n];\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\n/** The nearest ancestor that scrolls, so the effect works inside scroll containers as well as the page. */\nfunction scrollParent(el: HTMLElement | null): HTMLElement | null {\n  for (let node = el?.parentElement; node; node = node.parentElement) {\n    const { overflowY } = getComputedStyle(node);\n    if ((overflowY === \"auto\" || overflowY === \"scroll\") && node.scrollHeight > node.clientHeight) return node;\n  }\n  return null;\n}\n\nexport function ParallaxSection({ layers = LAYERS, children, height = 560, distance = 90, pointer = true, theme = \"dark\", className, style, ...props }: ParallaxSectionProps) {\n  const reduce = useReducedMotion();\n  const rootRef = React.useRef<HTMLElement>(null);\n  const layerRefs = React.useRef<(HTMLDivElement | null)[]>([]);\n  const light = theme === \"light\";\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    if (!root || reduce) return;\n    const scroller = scrollParent(root);\n    const target = { p: 0, px: 0, py: 0 };\n    const now = { p: 0, px: 0, py: 0 };\n    let raf = 0;\n    let running = false;\n\n    const measure = () => {\n      const rect = root.getBoundingClientRect();\n      const view = scroller ? scroller.getBoundingClientRect() : { top: 0, height: window.innerHeight };\n      // -1 when the section is just below the view, 0 when centred, 1 when just above it.\n      const center = rect.top + rect.height / 2 - (view.top + view.height / 2);\n      target.p = Math.max(-1, Math.min(1, -center / ((view.height + rect.height) / 2)));\n    };\n    const tick = () => {\n      const k = 0.12;\n      now.p += (target.p - now.p) * k;\n      now.px += (target.px - now.px) * k;\n      now.py += (target.py - now.py) * k;\n      layers.forEach((layer, i) => {\n        const el = layerRefs.current[i];\n        if (!el) return;\n        const depth = layer.depth ?? layer.speed;\n        const y = now.p * layer.speed * distance + now.py * depth * 14;\n        const x = now.px * depth * 14;\n        el.style.transform = `translate3d(${x.toFixed(2)}px, ${y.toFixed(2)}px, 0)`;\n      });\n      const moving = Math.abs(target.p - now.p) + Math.abs(target.px - now.px) + Math.abs(target.py - now.py) > 0.0005;\n      if (moving) raf = requestAnimationFrame(tick);\n      else running = false;\n    };\n    const kick = () => {\n      measure();\n      if (!running) {\n        running = true;\n        raf = requestAnimationFrame(tick);\n      }\n    };\n    const onPointer = (event: PointerEvent) => {\n      if (!pointer || event.pointerType !== \"mouse\") return;\n      const rect = root.getBoundingClientRect();\n      target.px = ((event.clientX - rect.left) / rect.width) * 2 - 1;\n      target.py = ((event.clientY - rect.top) / rect.height) * 2 - 1;\n      kick();\n    };\n    const onLeave = () => {\n      target.px = 0;\n      target.py = 0;\n      kick();\n    };\n    // Capture scroll from any container, so nested scrollers count too.\n    window.addEventListener(\"scroll\", kick, { capture: true, passive: true });\n    window.addEventListener(\"resize\", kick);\n    root.addEventListener(\"pointermove\", onPointer);\n    root.addEventListener(\"pointerleave\", onLeave);\n    kick();\n    return () => {\n      cancelAnimationFrame(raf);\n      window.removeEventListener(\"scroll\", kick, { capture: true });\n      window.removeEventListener(\"resize\", kick);\n      root.removeEventListener(\"pointermove\", onPointer);\n      root.removeEventListener(\"pointerleave\", onLeave);\n    };\n  }, [layers, distance, pointer, reduce]);\n\n  return (\n    <section\n      ref={rootRef}\n      className={cn(\"relative isolate w-full overflow-hidden\", className)}\n      style={{ height, background: light ? \"#f1f0ec\" : \"#0a0a0a\", color: light ? \"#141414\" : \"#f4f4f2\", ...style }}\n      {...props}\n    >\n      {layers.map((layer, i) => (\n        <div\n          key={i}\n          ref={(el) => {\n            layerRefs.current[i] = el;\n          }}\n          aria-hidden={layer.content ? undefined : !layer.alt}\n          className={cn(\"absolute will-change-transform\", layer.className)}\n          style={{ zIndex: i, ...layer.style }}\n        >\n          {layer.src ? <img src={layer.src} alt={layer.alt ?? \"\"} draggable={false} className=\"h-full w-full object-cover\" /> : layer.content}\n        </div>\n      ))}\n      {children && <div className=\"relative z-[50] flex h-full w-full items-center justify-center\">{children}</div>}\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}