{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"pointer-parallax-scene","type":"registry:component","title":"Pointer Parallax Scene","description":"A depth system where layers separate under the pointer from one shared motion source.","dependencies":["framer-motion"],"registryDependencies":[],"files":[{"path":"components/viberdy/pointer-parallax-scene.tsx","content":"\"use client\";\n\nimport { createContext, useContext, useRef, type ReactNode } from \"react\";\nimport {\n  motion,\n  useMotionValue,\n  useSpring,\n  useTransform,\n  type MotionValue,\n} from \"framer-motion\";\n\nexport function PointerParallaxScene({\n  children,\n  intensity = 1,\n  stiffness = 140,\n  tiltCard = true,\n}: {\n  children: ReactNode;\n  /** Multiplies every layer's depth. 0 pins the whole scene flat. */\n  intensity?: number;\n  stiffness?: number;\n  /** Bank the scene contents in 3D as well as offsetting them. */\n  tiltCard?: boolean;\n}) {\n  const boxRef = useRef<HTMLDivElement>(null);\n\n  // ONE normalised -0.5..0.5 pointer source, shared by every layer. Parallax\n  // is just this value times each layer's own depth factor.\n  const px = useMotionValue(0);\n  const py = useMotionValue(0);\n  const sx = useSpring(px, { stiffness, damping: 22, mass: 0.6 });\n  const sy = useSpring(py, { stiffness, damping: 22, mass: 0.6 });\n\n  const rotateY = useTransform(sx, [-0.5, 0.5], [-8, 8]);\n  const rotateX = useTransform(sy, [-0.5, 0.5], [6, -6]);\n\n  return (\n    <ParallaxContext.Provider value={{ sx, sy, intensity }}>\n      <div\n        ref={boxRef}\n        onMouseMove={(e) => {\n          const rect = boxRef.current?.getBoundingClientRect();\n          if (!rect) return;\n          px.set((e.clientX - rect.left) / rect.width - 0.5);\n          py.set((e.clientY - rect.top) / rect.height - 0.5);\n        }}\n        onMouseLeave={() => {\n          px.set(0);\n          py.set(0);\n        }}\n        className=\"relative overflow-hidden\"\n        style={{ perspective: 800 }}\n      >\n        <motion.div\n          style={tiltCard ? { rotateX, rotateY } : undefined}\n          className=\"relative h-full w-full\"\n        >\n          {children}\n        </motion.div>\n      </div>\n    </ParallaxContext.Provider>\n  );\n}\n\nconst ParallaxContext = createContext<{\n  sx: MotionValue<number>;\n  sy: MotionValue<number>;\n  intensity: number;\n} | null>(null);\n\nexport function ParallaxLayer({\n  depth,\n  className,\n  children,\n}: {\n  /** Negative = behind, positive = in front. 0 is pinned to the screen plane. */\n  depth: number;\n  className?: string;\n  children?: ReactNode;\n}) {\n  const ctx = useContext(ParallaxContext);\n  if (!ctx) throw new Error(\"ParallaxLayer must be inside PointerParallaxScene\");\n\n  // useTransform has to run at a component's top level, which is why a layer\n  // is its own component rather than a callback inside a .map().\n  // The scene's intensity scales every layer from one place, so a single\n  // control flattens or exaggerates the whole composition.\n  const scaled = depth * ctx.intensity;\n  const x = useTransform(ctx.sx, (v) => v * scaled * 2);\n  const y = useTransform(ctx.sy, (v) => v * scaled * 2);\n\n  return (\n    <motion.div aria-hidden style={{ x, y }} className={\"absolute \" + className}>\n      {children}\n    </motion.div>\n  );\n}\n","type":"registry:component","target":"components/viberdy/pointer-parallax-scene.tsx"}],"meta":{"tier":"free","tags":["parallax","pointer","depth","framer-motion"],"href":"https://viberdy.dev/library/pointer-parallax-scene","aiPrompt":"Create a React + Tailwind + Framer Motion parallax system: PointerParallaxScene (the container) plus ParallaxLayer (a child).\n\nBehavior:\n- The container tracks the pointer and normalises its position to -0.5..0.5 on each axis, stored in TWO motion values and smoothed with springs (damping 22, mass 0.6, configurable stiffness). On mouse leave both return to 0.\n- Each ParallaxLayer takes a `depth` prop and translates by (pointer * depth * 2). Negative depth sits behind, positive in front, 0 is pinned to the screen plane.\n- The container sets perspective so a tilted child reads as 3D.\n\nArchitecture requirements:\n- There must be exactly ONE pointer source shared by all layers via context — not per-layer mouse tracking. Parallax is that single value multiplied by each layer's depth.\n- ParallaxLayer must be its own component, not a callback inside a .map(), because useTransform has to be called at a component's top level. Calling hooks inside a map callback is a rules-of-hooks violation the moment the layer list is dynamic.\n- Pointer position rides motion values, NEVER React state — layers must update without re-rendering the scene.\n\nProps: PointerParallaxScene { children, stiffness }. ParallaxLayer { depth, className, children }.\n\nOutput self-contained \"use client\" components (remember to import createContext/useContext).\n\nOutput a single self-contained \"use client\" module.","license":"https://viberdy.dev/license"}}