{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scroll-scene",
  "type": "registry:component",
  "title": "Scroll Scene",
  "description": "A tall section with a pinned viewport whose children are driven by scroll progress from 0 to 1, for scroll-told sequences.",
  "categories": [
    "motion"
  ],
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "@rivier-ui/theme",
    "@rivier-ui/cn",
    "@rivier-ui/motion"
  ],
  "files": [
    {
      "path": "registry/motion/scroll-scene.tsx",
      "type": "registry:component",
      "target": "components/motion/scroll-scene.tsx",
      "content": "\"use client\";\n/**\n * @name scroll-scene\n * @category motion\n * @description A tall section with a pinned viewport whose children are driven by scroll progress from 0 to 1, for scroll-told sequences.\n * @when A product story told as the visitor scrolls: steps that replace each other, a device that turns, a diagram that builds. Use sparingly, one or two per page. For a simple entrance use reveal; for a drifting background use parallax.\n * @example\n * <ScrollScene length={3}>\n *   <ScrollSceneStep from={0} to={0.33} className=\"grid place-items-center p-6\">\n *     <h2 className=\"text-3xl font-medium\">Design</h2>\n *   </ScrollSceneStep>\n *   <ScrollSceneStep from={0.33} to={0.66} className=\"grid place-items-center p-6\">\n *     <h2 className=\"text-3xl font-medium\">Build</h2>\n *   </ScrollSceneStep>\n *   <ScrollSceneStep from={0.66} to={1} className=\"grid place-items-center p-6\">\n *     <h2 className=\"text-3xl font-medium\">Launch</h2>\n *   </ScrollSceneStep>\n * </ScrollScene>\n *\n * <ScrollScene length={2}>\n *   {(progress, active) => <Dial progress={progress} still={!active} />}\n * </ScrollScene>\n *\n * function Dial({ progress, still }: { progress: MotionValue<number>; still: boolean }) {\n *   const rotate = useTransform(progress, [0, 1], [0, 180]);\n *   return <motion.div className=\"size-40 border\" style={{ rotate: still ? 0 : rotate }} />;\n * }\n */\nimport { motion, useReducedMotion, useScroll, useTransform, type HTMLMotionProps, type MotionValue } from \"motion/react\";\nimport { createContext, useContext, useImperativeHandle, useRef, type ComponentProps, type CSSProperties, type ReactNode } from \"react\";\nimport { cn } from \"@/lib/cn\";\nimport { useMotionSafe } from \"@/lib/motion\";\n\ntype Scene = { progress: MotionValue<number>; active: boolean };\n\nconst SceneContext = createContext<Scene | null>(null);\n\nfunction useScene(): Scene {\n  const scene = useContext(SceneContext);\n  if (!scene) throw new Error(\"useSceneProgress and ScrollSceneStep must be used inside <ScrollScene>.\");\n  return scene;\n}\n\n/** The scene's scroll progress, 0 at the moment it pins to 1 at the moment it lets go, as a motion value. */\nexport function useSceneProgress(): MotionValue<number> {\n  return useScene().progress;\n}\n\n/**\n * Whether the scene is pinned and scroll-driven. False on the server, before hydration and under reduced\n * motion: then the scene is an ordinary stack, and children should show their content in full.\n */\nexport function useSceneActive(): boolean {\n  return useScene().active;\n}\n\nexport type ScrollSceneProps = Omit<ComponentProps<\"section\">, \"children\"> & {\n  /** How long the scene stays pinned, in viewport heights of scrolling (its total height). Default 3. */\n  length?: number;\n  /** Content, or a function given the progress value and whether the scene is active. */\n  children?: ReactNode | ((progress: MotionValue<number>, active: boolean) => ReactNode);\n  /** Classes for the pinned viewport that holds the children. */\n  viewportClassName?: string;\n};\n\n/**\n * Height: the section reserves `length` viewport heights with a min-height that is in the server markup, so\n * the page's layout is the same before and after the scene starts. Until it is active the children are an\n * ordinary, readable stack inside that space; once active they sit in a sticky, viewport-high box. Under\n * reduced motion the reserved height is dropped in CSS from the first paint and nothing pins.\n */\nexport function ScrollScene({ className, viewportClassName, length = 3, children, style, ref, ...props }: ScrollSceneProps) {\n  const rootRef = useRef<HTMLElement>(null);\n  useImperativeHandle(ref, () => rootRef.current as HTMLElement, []);\n  const active = useMotionSafe();\n  const reduced = useReducedMotion();\n  const { scrollYProgress } = useScroll({ target: rootRef, offset: [\"start start\", \"end end\"] });\n\n  return (\n    <section\n      ref={rootRef}\n      data-slot=\"scroll-scene\"\n      data-active={active || undefined}\n      className={cn(\"relative min-h-[calc(var(--scene-length)*100svh)] motion-reduce:min-h-0\", reduced && \"min-h-0\", className)}\n      style={{ \"--scene-length\": Math.max(1, length), ...style } as CSSProperties}\n      {...props}\n    >\n      <div data-slot=\"scroll-scene-viewport\" className={cn(\"relative\", active && \"sticky top-0 h-svh overflow-hidden\", viewportClassName)}>\n        <SceneContext value={{ progress: scrollYProgress, active }}>\n          {typeof children === \"function\" ? children(scrollYProgress, active) : children}\n        </SceneContext>\n      </div>\n    </section>\n  );\n}\n\nexport type ScrollSceneStepProps = HTMLMotionProps<\"div\"> & {\n  /** The progress (0 to 1) at which this step starts to appear. */\n  from: number;\n  /** The progress (0 to 1) by which it has gone. */\n  to: number;\n  /** How much of the scene each cross-fade takes, as progress. Default 0.06. */\n  fade?: number;\n};\n\n/**\n * A layer that is shown between two points of the scene, cross-fading at each end (opacity only). A step that\n * starts at 0 is there from the beginning, and one that ends at 1 stays. When the scene is not active every\n * step is an ordinary block, fully visible, one after another.\n */\nexport function ScrollSceneStep({ className, from, to, fade = 0.06, style, ...props }: ScrollSceneStepProps) {\n  const { progress, active } = useScene();\n  const start = Math.max(0, Math.min(1, from));\n  const end = Math.max(start, Math.min(1, to));\n  const ramp = Math.min(Math.max(fade, 0.001), (end - start) / 2);\n\n  const input: number[] = [];\n  const output: number[] = [];\n  const point = (at: number, value: number): void => {\n    if (input.length > 0 && at <= (input[input.length - 1] ?? 0)) return;\n    input.push(at);\n    output.push(value);\n  };\n  if (start > 0) {\n    point(start, 0);\n    point(start + ramp, 1);\n  } else {\n    point(0, 1);\n  }\n  if (end < 1) {\n    point(end - ramp, 1);\n    point(end, 0);\n  } else {\n    point(1, 1);\n  }\n  // A step that never fades (0 to 1) still needs two points for the range.\n  if (input.length < 2) {\n    input.push((input[0] ?? 0) + 1);\n    output.push(output[0] ?? 1);\n  }\n\n  const opacity = useTransform(progress, input, output);\n  // A faded-out layer must not take clicks meant for the one showing. It stays in the accessibility tree.\n  const pointerEvents = useTransform(opacity, (value) => (value > 0.5 ? \"auto\" : \"none\"));\n\n  return (\n    <motion.div\n      data-slot=\"scroll-scene-step\"\n      className={cn(active && \"absolute inset-0\", className)}\n      {...props}\n      style={active ? { ...style, opacity, pointerEvents } : style}\n    />\n  );\n}\n"
    }
  ],
  "meta": {
    "category": "motion",
    "when": "A product story told as the visitor scrolls: steps that replace each other, a device that turns, a diagram that builds. Use sparingly, one or two per page. For a simple entrance use reveal; for a drifting background use parallax.",
    "example": "<ScrollScene length={3}>\n  <ScrollSceneStep from={0} to={0.33} className=\"grid place-items-center p-6\">\n    <h2 className=\"text-3xl font-medium\">Design</h2>\n  </ScrollSceneStep>\n  <ScrollSceneStep from={0.33} to={0.66} className=\"grid place-items-center p-6\">\n    <h2 className=\"text-3xl font-medium\">Build</h2>\n  </ScrollSceneStep>\n  <ScrollSceneStep from={0.66} to={1} className=\"grid place-items-center p-6\">\n    <h2 className=\"text-3xl font-medium\">Launch</h2>\n  </ScrollSceneStep>\n</ScrollScene>\n\n<ScrollScene length={2}>\n  {(progress, active) => <Dial progress={progress} still={!active} />}\n</ScrollScene>\n\nfunction Dial({ progress, still }: { progress: MotionValue<number>; still: boolean }) {\n  const rotate = useTransform(progress, [0, 1], [0, 180]);\n  return <motion.div className=\"size-40 border\" style={{ rotate: still ? 0 : rotate }} />;\n}",
    "client": true
  }
}
