{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "phone-mockup",
  "title": "Phone Mockup",
  "description": "A realistic iPhone frame with 3D cursor tilt, a screen glare that tracks the tilt, ambient glow, and a story-style video/image player with swipe navigation and a progress bar.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/phone-mockup/phone-mockup.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, useMotionValue, useSpring, useTransform, type MotionValue } from \"motion/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 PhoneMockupMediaItem {\n  type: \"video\" | \"image\";\n  src: string;\n}\n\nexport type PhoneMockupFrameColor = \"titanium\" | \"black\";\nexport type PhoneMockupTransition = \"slide\" | \"fade\";\n\nexport interface PhoneMockupProps extends Omit<React.ComponentPropsWithoutRef<\"div\">, \"children\"> {\n  media?: PhoneMockupMediaItem[];\n  imageDuration?: number;\n  autoplay?: boolean;\n  loop?: boolean;\n  phoneWidth?: number;\n  frameColor?: PhoneMockupFrameColor;\n  tilt?: boolean;\n  tiltStrength?: number;\n  ambientGlow?: boolean;\n  glowColor?: string;\n  glowIntensity?: number;\n  progressBar?: boolean;\n  videoTransition?: PhoneMockupTransition;\n  background?: string;\n}\n\n// The same clips the site preview uses. (The video used to be a Big Buck Bunny test file on a\n// third-party test host, which a real project shouldn't depend on.)\nconst DEFAULT_MEDIA: PhoneMockupMediaItem[] = [\n  { type: \"video\", src: \"/demo/SocialMedia05.mp4\" },\n  { type: \"video\", src: \"/demo/SocialMedia03.mp4\" },\n  { type: \"video\", src: \"/demo/SocialMedia06.mp4\" },\n];\n\nfunction IPhoneFrame({\n  width,\n  frameColor,\n  glareX,\n  glareY,\n  children,\n}: {\n  width: number;\n  frameColor: PhoneMockupFrameColor;\n  glareX: MotionValue<number>;\n  glareY: MotionValue<number>;\n  children: React.ReactNode;\n}) {\n  const scale = width / 393;\n  const h = 852;\n\n  const isBlack = frameColor === \"black\";\n  const frameGrad = isBlack\n    ? \"linear-gradient(175deg, #2a2a2a 0%, #1a1a1a 40%, #0d0d0d 100%)\"\n    : \"linear-gradient(175deg, #d0d0d0 0%, #b8b8b8 30%, #c8c8c8 60%, #a8a8a8 100%)\";\n  const btnGrad = isBlack ? \"linear-gradient(90deg, #1a1a1a, #2e2e2e)\" : \"linear-gradient(90deg, #b0b0b0, #d0d0d0)\";\n  const btnR = isBlack ? \"linear-gradient(270deg, #1a1a1a, #2e2e2e)\" : \"linear-gradient(270deg, #b0b0b0, #d0d0d0)\";\n  const outerShadow = isBlack\n    ? [\"0 0 0 1px rgba(255,255,255,0.08)\", \"0 28px 70px rgba(0,0,0,0.6)\", \"0 8px 24px rgba(0,0,0,0.4)\", \"inset 0 1px 0 rgba(255,255,255,0.06)\"].join(\", \")\n    : [\"0 0 0 1px rgba(255,255,255,0.6)\", \"0 28px 70px rgba(0,0,0,0.35)\", \"0 8px 24px rgba(0,0,0,0.2)\", \"inset 0 1px 0 rgba(255,255,255,0.8)\", \"inset 0 -1px 0 rgba(0,0,0,0.1)\"].join(\", \");\n\n  const glareBg = useTransform([glareX, glareY], ([x, y]: number[]) => `radial-gradient(ellipse at ${x}% ${y}%, rgba(255,255,255,0.12) 0%, transparent 60%)`);\n\n  return (\n    <div className=\"relative shrink-0\" style={{ width, height: h * scale }}>\n      <div className=\"absolute inset-0\" style={{ background: frameGrad, borderRadius: 56 * scale, boxShadow: outerShadow }} />\n\n      <div className=\"absolute\" style={{ left: -4 * scale, top: 100 * scale, width: 5 * scale, height: 36 * scale, background: btnGrad, borderRadius: \"4px 0 0 4px\", boxShadow: \"-2px 0 6px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.5)\" }} />\n      <div className=\"absolute\" style={{ left: -4 * scale, top: 158 * scale, width: 5 * scale, height: 72 * scale, background: btnGrad, borderRadius: \"4px 0 0 4px\", boxShadow: \"-2px 0 6px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.5)\" }} />\n      <div className=\"absolute\" style={{ left: -4 * scale, top: 246 * scale, width: 5 * scale, height: 72 * scale, background: btnGrad, borderRadius: \"4px 0 0 4px\", boxShadow: \"-2px 0 6px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.5)\" }} />\n      <div className=\"absolute\" style={{ right: -4 * scale, top: 180 * scale, width: 5 * scale, height: 90 * scale, background: btnR, borderRadius: \"0 4px 4px 0\", boxShadow: \"2px 0 6px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.5)\" }} />\n\n      <div className=\"absolute\" style={{ inset: 6 * scale, background: \"#0a0a0a\", borderRadius: 51 * scale }} />\n\n      <div className=\"absolute overflow-hidden\" style={{ inset: 10 * scale, background: \"#000\", borderRadius: 47 * scale }}>\n        <div className=\"absolute inset-0\">{children}</div>\n        <motion.div className=\"pointer-events-none absolute inset-0 z-[9]\" style={{ borderRadius: 47 * scale, background: glareBg }} />\n      </div>\n    </div>\n  );\n}\n\nfunction getVariants(effect: PhoneMockupTransition, direction: number) {\n  if (effect === \"fade\") {\n    return { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.4, ease: \"easeInOut\" as const } };\n  }\n  return {\n    initial: { y: direction > 0 ? \"100%\" : \"-100%\", opacity: 0.6 },\n    animate: { y: 0, opacity: 1 },\n    exit: { y: direction > 0 ? \"-100%\" : \"100%\", opacity: 0.6 },\n    transition: { duration: 0.32, ease: [0.32, 0, 0.67, 0] as const },\n  };\n}\n\nfunction MediaPlayer({\n  mediaItems,\n  autoplay,\n  loop,\n  progressBar,\n  videoTransition,\n  imageDuration,\n}: {\n  mediaItems: PhoneMockupMediaItem[];\n  autoplay: boolean;\n  loop: boolean;\n  progressBar: boolean;\n  videoTransition: PhoneMockupTransition;\n  imageDuration: number;\n}) {\n  const [index, setIndex] = React.useState(0);\n  const [playing, setPlaying] = React.useState(autoplay);\n  const [direction, setDirection] = React.useState(1);\n  const [progress, setProgress] = React.useState(0);\n  const videoRef = React.useRef<HTMLVideoElement>(null);\n  const startY = React.useRef<number | null>(null);\n  const rafRef = React.useRef(0);\n\n  const current = mediaItems[index];\n  const isImage = current?.type === \"image\";\n\n  const goTo = React.useCallback(\n    (next: number) => {\n      const wrapped = (next + mediaItems.length) % mediaItems.length;\n      setDirection(next > index ? 1 : -1);\n      setIndex(wrapped);\n      setPlaying(autoplay);\n    },\n    [index, mediaItems.length, autoplay],\n  );\n\n  React.useEffect(() => {\n    setProgress(0);\n  }, [index]);\n\n  React.useEffect(() => {\n    if (!current || isImage || !videoRef.current) return;\n    if (playing) videoRef.current.play().catch(() => {});\n    else videoRef.current.pause();\n  }, [playing, current, isImage]);\n\n  React.useEffect(() => {\n    if (!current || !isImage) return;\n    cancelAnimationFrame(rafRef.current);\n    const duration = imageDuration * 1000;\n    const start = Date.now();\n    const tick = () => {\n      const p = Math.min((Date.now() - start) / duration, 1);\n      setProgress(p);\n      if (p < 1) rafRef.current = requestAnimationFrame(tick);\n      else goTo(index + 1);\n    };\n    rafRef.current = requestAnimationFrame(tick);\n    return () => cancelAnimationFrame(rafRef.current);\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [index, isImage]);\n\n  const onTouchStart = (e: React.TouchEvent) => {\n    startY.current = e.touches[0].clientY;\n  };\n  const onTouchEnd = (e: React.TouchEvent) => {\n    if (startY.current === null) return;\n    const delta = startY.current - e.changedTouches[0].clientY;\n    if (delta > 50) goTo(index + 1);\n    else if (delta < -50) goTo(index - 1);\n    startY.current = null;\n  };\n\n  const onMouseDown = (e: React.MouseEvent) => {\n    startY.current = e.clientY;\n  };\n  const onMouseUp = (e: React.MouseEvent) => {\n    if (startY.current === null) return;\n    const delta = startY.current - e.clientY;\n    if (Math.abs(delta) < 8) {\n      const rect = e.currentTarget.getBoundingClientRect();\n      const isRight = e.clientX - rect.left > rect.width / 2;\n      if (mediaItems.length > 1) {\n        if (isRight) goTo(index + 1);\n        else goTo(index - 1);\n      } else {\n        setPlaying((p) => !p);\n      }\n    } else if (delta > 50) goTo(index + 1);\n    else if (delta < -50) goTo(index - 1);\n    startY.current = null;\n  };\n\n  if (!current || !current.src) {\n    return (\n      <div className=\"flex h-full w-full flex-col items-center justify-center gap-2 bg-[#111]\">\n        <div className=\"text-[28px]\">🎬</div>\n        <span className=\"text-xs text-white/40\">Add media</span>\n      </div>\n    );\n  }\n\n  const v = getVariants(videoTransition, direction);\n\n  return (\n    <div className=\"h-full w-full cursor-pointer overflow-hidden bg-black\" onTouchStart={onTouchStart} onTouchEnd={onTouchEnd} onMouseDown={onMouseDown} onMouseUp={onMouseUp}>\n      <AnimatePresence mode=\"wait\" initial={false}>\n        <motion.div key={index} initial={v.initial} animate={v.animate} exit={v.exit} transition={v.transition} className=\"absolute inset-0\">\n          {isImage ? (\n            <img src={current.src} alt=\"\" className=\"h-full w-full object-cover\" />\n          ) : (\n            <video\n              ref={videoRef}\n              src={current.src}\n              className=\"h-full w-full object-cover\"\n              loop={loop}\n              muted\n              playsInline\n              autoPlay={autoplay}\n              onTimeUpdate={(e) => {\n                const el = e.currentTarget;\n                if (el.duration) setProgress(el.currentTime / el.duration);\n              }}\n              onEnded={() => {\n                if (!loop) goTo(index + 1);\n              }}\n            />\n          )}\n        </motion.div>\n      </AnimatePresence>\n\n      {progressBar && (\n        <div className=\"pointer-events-none absolute right-[8%] bottom-7 left-[8%] z-[8] h-0.5 rounded-full bg-white/20\">\n          <div className=\"h-full rounded-full bg-white transition-[width] duration-[250ms] ease-linear\" style={{ width: `${progress * 100}%` }} />\n        </div>\n      )}\n\n      {!playing && (\n        <motion.div initial={{ opacity: 0, scale: 0.7 }} animate={{ opacity: 1, scale: 1 }} className=\"pointer-events-none absolute inset-0 z-[5] flex items-center justify-center\">\n          <div className=\"flex h-14 w-14 items-center justify-center rounded-full bg-black/50\">\n            <div style={{ width: 0, height: 0, borderTop: \"10px solid transparent\", borderBottom: \"10px solid transparent\", borderLeft: \"16px solid white\", marginLeft: 3 }} />\n          </div>\n        </motion.div>\n      )}\n\n      {mediaItems.length > 1 && (\n        <div className=\"absolute top-1/2 right-2.5 z-[6] flex -translate-y-1/2 flex-col gap-1.5\">\n          {mediaItems.map((_, i) => (\n            <div key={i} className=\"w-1 rounded-[3px] transition-all duration-[250ms]\" style={{ height: i === index ? 20 : 4, background: i === index ? \"#fff\" : \"rgba(255,255,255,0.4)\" }} />\n          ))}\n        </div>\n      )}\n    </div>\n  );\n}\n\nexport function PhoneMockup({\n  media = DEFAULT_MEDIA,\n  imageDuration = 3,\n  autoplay = true,\n  loop = true,\n  phoneWidth = 280,\n  frameColor = \"titanium\",\n  tilt = true,\n  tiltStrength = 18,\n  ambientGlow = true,\n  glowColor = \"#6060FF\",\n  glowIntensity = 50,\n  progressBar = true,\n  videoTransition = \"slide\",\n  background = \"transparent\",\n  className,\n  ...props\n}: PhoneMockupProps) {\n  const containerRef = React.useRef<HTMLDivElement>(null);\n  const mediaItems = media.filter((m) => m.src);\n\n  const rotX = useMotionValue(0);\n  const rotY = useMotionValue(0);\n  const springRotX = useSpring(rotX, { stiffness: 160, damping: 22 });\n  const springRotY = useSpring(rotY, { stiffness: 160, damping: 22 });\n\n  const glareX = useTransform(springRotY, [-tiltStrength, tiltStrength], [20, 80]);\n  const glareY = useTransform(springRotX, [-tiltStrength, tiltStrength], [80, 20]);\n\n  const onMouseMove = (e: React.MouseEvent) => {\n    if (!tilt || !containerRef.current) return;\n    const rect = containerRef.current.getBoundingClientRect();\n    const dx = (e.clientX - rect.left - rect.width / 2) / (rect.width / 2);\n    const dy = (e.clientY - rect.top - rect.height / 2) / (rect.height / 2);\n    rotY.set(dx * tiltStrength);\n    rotX.set(-dy * tiltStrength);\n  };\n  const onMouseLeave = () => {\n    rotX.set(0);\n    rotY.set(0);\n  };\n\n  return (\n    <div className={cn(\"box-border flex h-full w-full flex-col items-center\", className)} style={{ background }} {...props}>\n      <div ref={containerRef} onMouseMove={onMouseMove} onMouseLeave={onMouseLeave} className=\"relative flex min-h-0 w-full flex-1 items-center justify-center\" style={{ perspective: \"900px\" }}>\n        {ambientGlow && (\n          <div\n            className=\"pointer-events-none absolute z-0 rounded-full\"\n            style={{ width: phoneWidth * 1.4, height: phoneWidth * 0.7, background: glowColor, filter: `blur(${phoneWidth * 0.28}px)`, opacity: glowIntensity / 100 }}\n          />\n        )}\n\n        <motion.div className=\"z-[1]\" style={{ rotateX: tilt ? springRotX : 0, rotateY: tilt ? springRotY : 0, transformStyle: \"preserve-3d\" }}>\n          <IPhoneFrame width={phoneWidth} frameColor={frameColor} glareX={glareX} glareY={glareY}>\n            <MediaPlayer mediaItems={mediaItems} autoplay={autoplay} loop={loop} progressBar={progressBar} videoTransition={videoTransition} imageDuration={imageDuration} />\n          </IPhoneFrame>\n        </motion.div>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}