{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"clip-reveal","type":"registry:ui","title":"Clip reveal","description":"Uncovers an image or section with a wipe as it scrolls into view, the content settling from a slight zoom behind the edge. From any side or as an iris from the middle, once or every time.","dependencies":["clsx","tailwind-merge"],"registryDependencies":["https://caliperui.site/r/styles.json"],"files":[{"path":"ui/clip-reveal.tsx","type":"registry:ui","target":"components/ui/clip-reveal.tsx","content":"\"use client\";\nimport { useEffect, useRef, useState, type ComponentProps } from \"react\";\nimport { cn } from \"./lib/cn\";\nimport \"./clip-reveal.css\";\n\nexport type ClipRevealProps = ComponentProps<\"div\"> & {\n  /** The edge the wipe starts from, or an iris that opens from the middle. */\n  from?: \"bottom\" | \"top\" | \"left\" | \"right\" | \"iris\";\n  /** Hides again when scrolled out of view, so the wipe plays each time. */\n  repeat?: boolean;\n  /** Extra wait before the wipe, in ms, for staggering neighbours. */\n  delay?: number;\n};\n\n/**\n * Uncovers an image or section with a wipe as it scrolls into view, the content settling from a slight zoom behind\n * the edge. It never changes layout. Anything already on screen when the page loads is left as it is, so nothing\n * flashes away and back, and under reduced motion everything simply shows.\n */\nexport function ClipReveal({ from = \"bottom\", repeat = false, delay = 0, className, style, children, ...props }: ClipRevealProps) {\n  const root = useRef<HTMLDivElement>(null);\n  const [state, setState] = useState<\"idle\" | \"hidden\" | \"shown\">(\"idle\");\n\n  useEffect(() => {\n    const element = root.current;\n    if (!element || matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    let armed = false;\n    const observer = new IntersectionObserver(\n      ([entry]) => {\n        if (!entry) return;\n        if (!armed) {\n          armed = true;\n          // Only arm what starts out of view; content already visible stays put.\n          if (entry.isIntersecting) {\n            if (!repeat) observer.disconnect();\n            return;\n          }\n          setState(\"hidden\");\n          return;\n        }\n        if (entry.isIntersecting) {\n          setState(\"shown\");\n          if (!repeat) observer.disconnect();\n        } else if (repeat) setState(\"hidden\");\n      },\n      { threshold: 0.2 },\n    );\n    observer.observe(element);\n    return () => observer.disconnect();\n  }, [repeat]);\n\n  return (\n    <div\n      ref={root}\n      data-slot=\"clip-reveal\"\n      data-from={from}\n      data-state={state}\n      className={cn(\"relative overflow-hidden\", className)}\n      style={style}\n      {...props}\n    >\n      <div data-slot=\"cr-inner\" style={{ transitionDelay: `${delay}ms` }}>\n        {children}\n      </div>\n    </div>\n  );\n}\n"},{"path":"ui/lib/cn.ts","type":"registry:ui","target":"components/ui/lib/cn.ts","content":"import { clsx, type ClassValue } from \"clsx\";\nimport { extendTailwindMerge } from \"tailwind-merge\";\n\nconst twMerge = extendTailwindMerge({\n  extend: { theme: { radius: [\"control\", \"surface\", \"overlay\"], shadow: [\"overlay\"] } },\n});\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n"},{"path":"ui/clip-reveal.css","type":"registry:file","target":"components/ui/clip-reveal.css","content":"/* clip-reveal.tsx's styles; it imports this file. Edit freely. */\n@layer theme, base, components, utilities;\n\n@layer components {\n  /* Clip reveal: only parts armed below the fold start hidden; the content settles from a slight zoom behind the edge. */\n  /* The wipe is on the inner layer: a box clipped to nothing never reports itself in view, so the observed root stays whole. */\n  [data-slot=\"clip-reveal\"] > [data-slot=\"cr-inner\"] { height: 100%; clip-path: inset(0); transition: clip-path 0.95s var(--ease-showcase), scale 1.2s var(--ease-showcase); }\n  [data-slot=\"clip-reveal\"][data-state=\"hidden\"] > [data-slot=\"cr-inner\"] { scale: 1.08; transition: none; }\n  [data-slot=\"clip-reveal\"][data-state=\"hidden\"][data-from=\"bottom\"] > [data-slot=\"cr-inner\"] { clip-path: inset(100% 0 0 0); }\n  [data-slot=\"clip-reveal\"][data-state=\"hidden\"][data-from=\"top\"] > [data-slot=\"cr-inner\"] { clip-path: inset(0 0 100% 0); }\n  [data-slot=\"clip-reveal\"][data-state=\"hidden\"][data-from=\"left\"] > [data-slot=\"cr-inner\"] { clip-path: inset(0 100% 0 0); }\n  [data-slot=\"clip-reveal\"][data-state=\"hidden\"][data-from=\"right\"] > [data-slot=\"cr-inner\"] { clip-path: inset(0 0 0 100%); }\n  [data-slot=\"clip-reveal\"][data-state=\"hidden\"][data-from=\"iris\"] > [data-slot=\"cr-inner\"] { clip-path: inset(50% 50% 50% 50% round 999px); }\n  [data-slot=\"clip-reveal\"][data-from=\"iris\"][data-state=\"shown\"] > [data-slot=\"cr-inner\"] { clip-path: inset(0 0 0 0 round 0); }\n  @media (prefers-reduced-motion: reduce) {\n    [data-slot=\"clip-reveal\"], [data-slot=\"clip-reveal\"] > [data-slot=\"cr-inner\"] { transition: none; }\n  }\n}\n"}],"categories":["motion"],"meta":{"tier":"free","license":"MIT","family":"media","docs":"/docs/components/clip-reveal"}}