{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "motion-in-view",
  "title": "In view",
  "description": "A component that triggers animations when elements enter the viewport.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json"
  ],
  "files": [
    {
      "path": "components/core/in-view.tsx",
      "content": "'use client';\nimport { ReactNode, useRef, useState } from 'react';\nimport {\n  MotionConfig,\n  useInView,\n  Variant,\n  Transition,\n  UseInViewOptions,\n} from 'motion/react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\n\nimport { motionElementOf } from './motion-elements';\n\nexport type InViewProps = {\n  children: ReactNode;\n  variants?: {\n    hidden: Variant;\n    visible: Variant;\n  };\n  transition?: Transition;\n  viewOptions?: UseInViewOptions;\n  as?: React.ElementType;\n  once?: boolean;\n};\n\nconst defaultVariants = {\n  hidden: { opacity: 0 },\n  visible: { opacity: 1 },\n};\n\nfunction ReducedMotionConfig({ children }: { children: ReactNode }) {\n  const prefersReducedMotion = usePrefersReducedMotion();\n  if (!prefersReducedMotion) {\n    return children;\n  }\n  return <MotionConfig reducedMotion='always'>{children}</MotionConfig>;\n}\n\nexport function InView({\n  children,\n  variants = defaultVariants,\n  transition,\n  viewOptions,\n  as = 'div',\n  once,\n}: InViewProps) {\n  const ref = useRef(null);\n  const isInView = useInView(ref, viewOptions);\n\n  const [isViewed, setIsViewed] = useState(false);\n\n  const MotionComponent = motionElementOf(as) as typeof as;\n\n  return (\n    <ReducedMotionConfig>\n      <MotionComponent\n        ref={ref}\n        initial='hidden'\n        onAnimationComplete={() => {\n          if (once) setIsViewed(true);\n        }}\n        animate={isInView || isViewed ? 'visible' : 'hidden'}\n\n        variants={variants}\n        transition={transition}\n      >\n        {children}\n      </MotionComponent>\n    </ReducedMotionConfig>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/core/in-view.tsx"
    },
    {
      "path": "components/core/motion-elements.ts",
      "content": "import { motion } from 'motion/react';\n\nconst MOTION_ELEMENTS = {\n  a: motion.a,\n  article: motion.article,\n  aside: motion.aside,\n  blockquote: motion.blockquote,\n  button: motion.button,\n  code: motion.code,\n  div: motion.div,\n  em: motion.em,\n  figure: motion.figure,\n  footer: motion.footer,\n  h1: motion.h1,\n  h2: motion.h2,\n  h3: motion.h3,\n  h4: motion.h4,\n  h5: motion.h5,\n  h6: motion.h6,\n  header: motion.header,\n  label: motion.label,\n  li: motion.li,\n  main: motion.main,\n  nav: motion.nav,\n  ol: motion.ol,\n  p: motion.p,\n  pre: motion.pre,\n  section: motion.section,\n  small: motion.small,\n  span: motion.span,\n  strong: motion.strong,\n  ul: motion.ul,\n};\n\ntype MotionElementTag = keyof typeof MOTION_ELEMENTS;\n\nfunction isMotionElementTag(tag: unknown): tag is MotionElementTag {\n  const isString = typeof tag === 'string';\n  return isString && tag in MOTION_ELEMENTS;\n}\n\n/**\n * The motion version of an HTML tag. A lookup such as `motion[tag]` is invisible to the bundler,\n * which drops the tags it never sees and breaks the production build, so every tag is listed here.\n */\nexport function motionElementOf(tag: unknown) {\n  if (isMotionElementTag(tag)) {\n    return MOTION_ELEMENTS[tag];\n  }\n  return MOTION_ELEMENTS.div;\n}\n",
      "type": "registry:component",
      "target": "components/core/motion-elements.ts"
    }
  ],
  "categories": [
    "motion"
  ],
  "type": "registry:component"
}