{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "desktop-mockup-carousel",
  "title": "Desktop Mockup Carousel",
  "description": "A realistic Studio Display-style monitor mockup with an internal video/image carousel, swipe or auto-advance, slide/fade transitions, 3D cursor tilt, ambient glow, and a progress bar.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/desktop-mockup-carousel/desktop-mockup-carousel.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, useMotionValue, useSpring, useTransform } 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\n// useLayoutEffect logs a warning when it runs server-side (no DOM to act on\n// before paint there); fall back to useEffect there and only take the\n// synchronous-before-paint behavior in the browser.\nconst useIsomorphicLayoutEffect = typeof window !== \"undefined\" ? React.useLayoutEffect : React.useEffect;\n\nexport type DesktopMockupFrameColor = \"Silver\" | \"Space Black\";\nexport type DesktopMockupTransition = \"Slide\" | \"Fade\";\nexport type DesktopMockupMediaKey = \"V1\" | \"V2\" | \"V3\" | \"I1\" | \"I2\";\n\nexport interface DesktopMockupCarouselProps {\n  video1?: string;\n  video2?: string;\n  video3?: string;\n  image1?: string;\n  image2?: string;\n  mediaOrder?: DesktopMockupMediaKey[];\n  imageDuration?: number;\n  autoplay?: boolean;\n  loop?: boolean;\n  displayWidth?: number;\n  frameColor?: DesktopMockupFrameColor;\n  frameShadow?: boolean;\n  tilt?: boolean;\n  tiltStrength?: number;\n  ambientGlow?: boolean;\n  glowColor?: string;\n  glowIntensity?: number;\n  progressBar?: boolean;\n  videoTransition?: DesktopMockupTransition;\n  background?: string;\n  className?: string;\n}\n\ninterface MediaItem {\n  type: \"video\" | \"image\";\n  src: string;\n  alt?: string;\n}\n\nconst DISPLAY_W = 1600;\nconst DISPLAY_H = 900;\nconst STAND_NECK_H = 200;\nconst STAND_BASE_H = 32;\n\nfunction getVariants(effect: DesktopMockupTransition, direction: number) {\n  if (effect === \"Fade\")\n    return {\n      mode: \"wait\" as const,\n      initial: { opacity: 0 },\n      animate: { opacity: 1 },\n      exit: { opacity: 0 },\n      transition: { duration: 0.4, ease: \"easeInOut\" as const },\n    };\n  return {\n    mode: \"sync\" as const,\n    initial: { x: direction > 0 ? \"100%\" : \"-100%\", opacity: 0.6 },\n    animate: { x: 0, opacity: 1 },\n    exit: { x: direction > 0 ? \"-100%\" : \"100%\", opacity: 0.6 },\n    transition: { duration: 0.32, ease: [0.32, 0, 0.67, 0] as [number, number, number, number] },\n  };\n}\n\ninterface StudioDisplayFrameProps {\n  width: number;\n  frameColor: DesktopMockupFrameColor;\n  showShadow: boolean;\n  glareX: ReturnType<typeof useTransform<number, number>>;\n  glareY: ReturnType<typeof useTransform<number, number>>;\n  children: React.ReactNode;\n}\n\nfunction StudioDisplayFrame({ width, frameColor, showShadow, glareX, glareY, children }: StudioDisplayFrameProps) {\n  const s = width / DISPLAY_W;\n  const dH = DISPLAY_H * s;\n  const nH = STAND_NECK_H * s;\n  const bsH = STAND_BASE_H * s;\n  const totH = dH + nH + bsH;\n\n  const silver = frameColor !== \"Space Black\";\n\n  const bOut = 18 * s;\n  const bIn = 12 * s;\n  const R = 18 * s;\n  const Rs = 8 * s;\n  const neckW = 88 * s;\n  const baseW = 600 * s;\n  const connD = 70 * s;\n\n  const frameGrad = silver\n    ? \"linear-gradient(168deg, #ececec 0%, #d6d6d6 38%, #cacaca 70%, #b8b8b8 100%)\"\n    : \"linear-gradient(168deg, #3e3e3e 0%, #2e2e2e 40%, #262626 100%)\";\n\n  const shadowStr = !showShadow\n    ? \"none\"\n    : silver\n      ? \"0 0 0 1px rgba(0,0,0,0.10), 0 40px 100px rgba(0,0,0,0.15), 0 10px 28px rgba(0,0,0,0.10), inset 0 1px 0 rgba(255,255,255,0.92), inset 0 -1px 0 rgba(0,0,0,0.04)\"\n      : \"0 0 0 1px rgba(255,255,255,0.06), 0 40px 100px rgba(0,0,0,0.55), 0 10px 28px rgba(0,0,0,0.38), inset 0 1px 0 rgba(255,255,255,0.05)\";\n\n  const m = silver ? { l: \"#c8c8c8\", m: \"#d6d6d6\", d: \"#b2b2b2\" } : { l: \"#2a2a2a\", m: \"#343434\", d: \"#1e1e1e\" };\n\n  return (\n    <div style={{ width, height: totH, position: \"relative\", flexShrink: 0 }}>\n      <div style={{ position: \"absolute\", top: 0, left: 0, width, height: dH, zIndex: 2 }}>\n        <div style={{ position: \"absolute\", inset: 0, background: frameGrad, borderRadius: R, boxShadow: shadowStr }} />\n\n        <div style={{ position: \"absolute\", inset: bOut, background: \"#0a0a0a\", borderRadius: Rs + 2, overflow: \"hidden\" }}>\n          <div style={{ position: \"absolute\", inset: bIn, background: \"#000\", borderRadius: Rs, overflow: \"hidden\" }}>\n            <div style={{ position: \"absolute\", inset: 0 }}>{children}</div>\n            <motion.div\n              style={{\n                position: \"absolute\",\n                inset: 0,\n                zIndex: 9,\n                pointerEvents: \"none\",\n                borderRadius: Rs,\n                background: useTransform([glareX, glareY], ([x, y]: number[]) => `radial-gradient(ellipse at ${x}% ${y}%, rgba(255,255,255,0.09) 0%, transparent 62%)`),\n              }}\n            />\n          </div>\n\n          <div style={{ position: \"absolute\", top: bIn / 2, left: \"50%\", transform: \"translate(-50%, -50%)\", display: \"flex\", alignItems: \"center\", gap: 3 * s, pointerEvents: \"none\" }}>\n            <div style={{ width: 5 * s, height: 5 * s, borderRadius: \"50%\", background: \"#1c1c1c\", boxShadow: \"inset 0 1px 2px rgba(0,0,0,0.9), 0 0 0 1px rgba(255,255,255,0.04)\" }} />\n            <div style={{ width: 2 * s, height: 2 * s, borderRadius: \"50%\", background: \"#222\" }} />\n          </div>\n        </div>\n      </div>\n\n      <div\n        style={{\n          position: \"absolute\",\n          top: dH,\n          left: \"50%\",\n          transform: \"translateX(-50%)\",\n          width: neckW,\n          height: nH,\n          background: `linear-gradient(90deg, ${m.d} 0%, ${m.m} 50%, ${m.l} 100%)`,\n          zIndex: 1,\n        }}\n      />\n\n      <div\n        style={{\n          position: \"absolute\",\n          top: dH - connD * 0.3,\n          left: \"50%\",\n          transform: \"translateX(-50%)\",\n          width: connD,\n          height: connD,\n          borderRadius: \"50%\",\n          background: silver ? \"radial-gradient(circle at 38% 32%, #e8e8e8, #aaaaaa)\" : \"radial-gradient(circle at 38% 32%, #3c3c3c, #1e1e1e)\",\n          boxShadow: silver ? \"inset 0 1px 4px rgba(255,255,255,0.6), 0 2px 10px rgba(0,0,0,0.18)\" : \"inset 0 1px 4px rgba(255,255,255,0.08), 0 2px 10px rgba(0,0,0,0.5)\",\n          zIndex: 3,\n        }}\n      />\n\n      <div\n        style={{\n          position: \"absolute\",\n          bottom: 0,\n          left: \"50%\",\n          transform: \"translateX(-50%)\",\n          width: baseW,\n          height: bsH,\n          background: `linear-gradient(180deg, ${m.m} 0%, ${m.d} 100%)`,\n          borderRadius: `${2 * s}px ${2 * s}px ${8 * s}px ${8 * s}px`,\n          boxShadow: showShadow ? `0 4px 20px rgba(0,0,0,${silver ? 0.13 : 0.4}), inset 0 1px 0 rgba(255,255,255,${silver ? 0.5 : 0.06})` : \"none\",\n          zIndex: 1,\n        }}\n      />\n    </div>\n  );\n}\n\ninterface VideoPlayerProps {\n  mediaItems: MediaItem[];\n  autoplay: boolean;\n  loop: boolean;\n  progressBar: boolean;\n  videoTransition: DesktopMockupTransition;\n  imageDuration: number;\n  displayWidth: number;\n}\n\nfunction VideoPlayer({ mediaItems, autoplay, loop, progressBar, videoTransition, imageDuration }: VideoPlayerProps) {\n  const [index, setIndex] = React.useState(0);\n  const [playing, setPlaying] = React.useState(autoplay);\n  const [direction, setDirection] = React.useState(1);\n  const [isVisible, setIsVisible] = React.useState(true);\n  const progress = useMotionValue(0);\n  const progressWidth = useTransform(progress, (v) => `${v * 100}%`);\n  const videoRef = React.useRef<HTMLVideoElement>(null);\n  const stageRef = React.useRef<HTMLDivElement>(null);\n  const startX = React.useRef<number | null>(null);\n  const startY = React.useRef<number | null>(null);\n  const rafRef = React.useRef<number>(0);\n  const elapsedRef = 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    const t = setTimeout(() => setPlaying(autoplay), 0);\n    return () => clearTimeout(t);\n  }, [autoplay]);\n\n  React.useEffect(() => {\n    progress.set(0);\n    elapsedRef.current = 0;\n  }, [index, progress]);\n\n  React.useEffect(() => {\n    if (!stageRef.current) return;\n    const obs = new IntersectionObserver(([entry]) => setIsVisible(entry.isIntersecting));\n    obs.observe(stageRef.current);\n    return () => obs.disconnect();\n  }, [mediaItems.length]);\n\n  React.useEffect(() => {\n    if (!current || isImage || !videoRef.current) return;\n    if (playing && isVisible) videoRef.current.play().catch(() => {});\n    else videoRef.current.pause();\n  }, [playing, index, isImage, isVisible, current]);\n\n  React.useEffect(() => {\n    if (!current || !isImage || !isVisible) return;\n    cancelAnimationFrame(rafRef.current);\n    const duration = imageDuration * 1000;\n    const start = Date.now() - elapsedRef.current;\n    const tick = () => {\n      const elapsed = Date.now() - start;\n      elapsedRef.current = elapsed;\n      const p = Math.min(elapsed / duration, 1);\n      progress.set(p);\n      if (p < 1) rafRef.current = requestAnimationFrame(tick);\n      else {\n        elapsedRef.current = 0;\n        goTo(index + 1);\n      }\n    };\n    rafRef.current = requestAnimationFrame(tick);\n    return () => cancelAnimationFrame(rafRef.current);\n  }, [index, isImage, isVisible, goTo, progress, imageDuration, current]);\n\n  const onPointerDown = (e: React.PointerEvent<HTMLDivElement>) => {\n    startX.current = e.clientX;\n    startY.current = e.clientY;\n  };\n\n  const onPointerMove = (e: React.PointerEvent<HTMLDivElement>) => {\n    if (startX.current === null || startY.current === null) return;\n    const dx = Math.abs(e.clientX - startX.current);\n    const dy = Math.abs(e.clientY - startY.current);\n    if (dx > 5 && dx > dy) {\n      e.currentTarget.setPointerCapture(e.pointerId);\n      startY.current = null;\n    }\n  };\n\n  const onPointerUp = (e: React.PointerEvent<HTMLDivElement>) => {\n    if (startX.current === null) return;\n    const delta = startX.current - e.clientX;\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 setPlaying((p) => !p);\n    } else if (delta > 50) goTo(index + 1);\n    else if (delta < -50) goTo(index - 1);\n    startX.current = null;\n    startY.current = null;\n  };\n\n  const onPointerCancel = () => {\n    startX.current = null;\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 onKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    if (mediaItems.length > 1 && e.key === \"ArrowRight\") {\n      e.preventDefault();\n      goTo(index + 1);\n    } else if (mediaItems.length > 1 && e.key === \"ArrowLeft\") {\n      e.preventDefault();\n      goTo(index - 1);\n    } else if (mediaItems.length <= 1 && (e.key === \" \" || e.key === \"Enter\")) {\n      e.preventDefault();\n      setPlaying((p) => !p);\n    }\n  };\n\n  const v = getVariants(videoTransition, direction);\n\n  return (\n    <div\n      ref={stageRef}\n      role=\"group\"\n      aria-roledescription=\"carousel\"\n      aria-label={mediaItems.length > 1 ? `Media carousel, slide ${index + 1} of ${mediaItems.length}` : \"Media player\"}\n      tabIndex={0}\n      className=\"relative h-full w-full cursor-pointer overflow-hidden bg-black\"\n      style={{ touchAction: \"pan-y\" }}\n      onPointerDown={onPointerDown}\n      onPointerMove={onPointerMove}\n      onPointerUp={onPointerUp}\n      onPointerCancel={onPointerCancel}\n      onKeyDown={onKeyDown}\n    >\n      <AnimatePresence mode={v.mode} 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            // eslint-disable-next-line @next/next/no-img-element\n            <img src={current.src} alt={current.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 vid = e.currentTarget;\n                if (vid.duration) progress.set(vid.currentTime / vid.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-[6%] left-[6%] z-[8] h-0.5 rounded-full bg-white/20\" style={{ bottom: 28 }}>\n          <motion.div className=\"h-full rounded-full bg-white\" style={{ width: progressWidth }} />\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 bottom-2.5 left-1/2 z-[6] flex -translate-x-1/2 flex-row gap-1.5\">\n          {mediaItems.map((_, i) => (\n            <div\n              key={i}\n              className=\"rounded-[3px] transition-all\"\n              style={{\n                height: 4,\n                width: i === index ? 20 : 4,\n                background: i === index ? \"#fff\" : \"rgba(255,255,255,0.4)\",\n                // Source's \"all 0.25s\" has no explicit timing function\n                // (CSS default \"ease\"), not Tailwind's transition-all\n                // default of cubic-bezier(0.4,0,0.2,1).\n                transitionDuration: \"250ms\",\n                transitionTimingFunction: \"ease\",\n              }}\n            />\n          ))}\n        </div>\n      )}\n    </div>\n  );\n}\n\nexport function DesktopMockupCarousel({\n  video1 = \"\",\n  video2 = \"\",\n  video3 = \"\",\n  image1 = \"\",\n  image2 = \"\",\n  mediaOrder = [\"V1\", \"V2\", \"V3\", \"I1\", \"I2\"],\n  imageDuration = 3,\n  autoplay = true,\n  loop = true,\n  displayWidth = 680,\n  frameColor = \"Silver\",\n  frameShadow = true,\n  tilt = false,\n  tiltStrength = 12,\n  ambientGlow = false,\n  glowColor = \"#6060FF\",\n  glowIntensity = 40,\n  progressBar = true,\n  videoTransition = \"Slide\",\n  background = \"rgba(0,0,0,0)\",\n  className,\n}: DesktopMockupCarouselProps) {\n  const srcMap: Record<DesktopMockupMediaKey, MediaItem> = {\n    V1: { type: \"video\", src: video1 },\n    V2: { type: \"video\", src: video2 },\n    V3: { type: \"video\", src: video3 },\n    I1: { type: \"image\", src: image1 },\n    I2: { type: \"image\", src: image2 },\n  };\n  const mediaItems = mediaOrder.map((k) => srcMap[k]).filter((m): m is MediaItem => Boolean(m && m.src));\n\n  const containerRef = React.useRef<HTMLDivElement>(null);\n  const [containerW, setContainerW] = React.useState(0);\n  const [containerH, setContainerH] = React.useState(0);\n\n  // useLayoutEffect (not useEffect) so the container's real size is known\n  // before first paint — otherwise the display briefly renders at displayWidth\n  // (680px default) and visibly snaps to the fitted size once the effect\n  // fires.\n  useIsomorphicLayoutEffect(() => {\n    if (!containerRef.current) return;\n    const rect = containerRef.current.getBoundingClientRect();\n    setContainerW(rect.width);\n    setContainerH(rect.height);\n    const obs = new ResizeObserver(([entry]) => {\n      setContainerW(entry.contentRect.width);\n      setContainerH(entry.contentRect.height);\n    });\n    obs.observe(containerRef.current);\n    return () => obs.disconnect();\n  }, []);\n\n  const totalAspect = DISPLAY_W / (DISPLAY_H + STAND_NECK_H + STAND_BASE_H);\n  const maxByW = containerW > 0 ? Math.max(100, containerW - 32) : displayWidth;\n  const maxByH = containerH > 0 ? Math.max(100, (containerH - 32) * totalAspect) : displayWidth;\n  const autoMax = Math.floor(Math.min(maxByW, maxByH));\n  const effectiveDisplayWidth = containerW > 0 ? Math.min(displayWidth, autoMax) : displayWidth;\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  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 ref={containerRef} className={cn(\"box-border flex h-full w-full flex-col items-center\", className)} style={{ background }}>\n      <div onMouseMove={onMouseMove} onMouseLeave={onMouseLeave} className=\"relative flex flex-1 items-center justify-center overflow-hidden\" style={{ width: \"100%\", minHeight: 0, perspective: \"1200px\" }}>\n        {ambientGlow && (\n          <div\n            className=\"pointer-events-none absolute z-0 rounded-full\"\n            style={{ width: effectiveDisplayWidth * 1.2, height: effectiveDisplayWidth * 0.5, background: glowColor, filter: `blur(${effectiveDisplayWidth * 0.25}px)`, opacity: glowIntensity / 100 }}\n          />\n        )}\n\n        <motion.div style={{ rotateX: tilt ? springRotX : 0, rotateY: tilt ? springRotY : 0, transformStyle: \"preserve-3d\", zIndex: 1 }}>\n          <StudioDisplayFrame width={effectiveDisplayWidth} frameColor={frameColor} showShadow={frameShadow} glareX={glareX} glareY={glareY}>\n            <VideoPlayer mediaItems={mediaItems} autoplay={autoplay} loop={loop} progressBar={progressBar} videoTransition={videoTransition} imageDuration={imageDuration} displayWidth={effectiveDisplayWidth} />\n          </StudioDisplayFrame>\n        </motion.div>\n      </div>\n\n      <AnimatePresence>\n              </AnimatePresence>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}