{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "video-glow-lightbox",
  "title": "Video Glow Lightbox",
  "description": "A single video card with a pulsing glow-blob frame that morphs into a fullscreen lightbox on click, supports direct URL, YouTube, Vimeo, or uploaded files, a cursor-following watch label, hover preview loop, and a Web Audio sound-reactive glow.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/video-glow-lightbox/video-glow-lightbox.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, useMotionValue, useSpring } 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\nfunction getYouTubeId(url: string): string | null {\n  const m = url.match(/(?:youtube\\.com\\/(?:watch\\?v=|embed\\/|shorts\\/)|youtu\\.be\\/)([^&\\n?#]+)/);\n  return m?.[1] ?? null;\n}\n\nfunction getVimeoId(url: string): string | null {\n  const m = url.match(/vimeo\\.com\\/(?:.*\\/)?(?:video\\/)?(\\d+)/);\n  return m?.[1] ?? null;\n}\n\nconst PlayIcon = React.memo(function PlayIcon({ size, color }: { size: number; color: string }) {\n  return (\n    <svg aria-hidden=\"true\" width={size} height={size} viewBox=\"0 0 80 80\" fill=\"none\">\n      <circle cx=\"40\" cy=\"40\" r=\"40\" fill=\"rgba(0,0,0,0.42)\" />\n      <circle cx=\"40\" cy=\"40\" r=\"38.5\" stroke=\"rgba(255,255,255,0.16)\" strokeWidth=\"1\" />\n      <path d=\"M32 26l22 14-22 14V26z\" fill={color} />\n    </svg>\n  );\n});\n\nconst CloseIcon = React.memo(function CloseIcon() {\n  return (\n    <svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\">\n      <path d=\"M1 1l14 14M15 1L1 15\" stroke=\"white\" strokeWidth=\"1.8\" strokeLinecap=\"round\" />\n    </svg>\n  );\n});\n\n\n\n\nexport type VideoGlowLightboxType = \"url\" | \"youtube\" | \"vimeo\" | \"file\";\nexport type VideoGlowLightboxTransition = \"morph\" | \"fade\";\n\nexport interface VideoGlowLightboxProps {\n  videoType?: VideoGlowLightboxType;\n  videoUrl?: string;\n  videoFile?: string;\n  thumbnailImage?: string;\n  glowColor?: string;\n  glowIntensity?: number;\n  glowBlur?: number;\n  glowSpread?: number;\n  glowAnimation?: boolean;\n  glowAnimationSpeed?: number;\n  borderRadius?: number;\n  borderWidth?: number;\n  borderColor?: string;\n  frameBackground?: string;\n  overlayColor?: string;\n  lightboxBorderRadius?: number;\n  lightboxMaxWidth?: number;\n  lightboxGlow?: boolean;\n  lightboxTransition?: VideoGlowLightboxTransition;\n  aspectRatio?: string;\n  innerGlowSize?: number;\n  showPlayButton?: boolean;\n  playButtonSize?: number;\n  playButtonColor?: string;\n  showCursorLabel?: boolean;\n  cursorLabelText?: string;\n  cursorLabelBg?: string;\n  cursorLabelColor?: string;\n  enableHoverPreview?: boolean;\n  hoverPreviewDelay?: number;\n  soundReactiveGlow?: boolean;\n  soundReactiveIntensity?: number;\n  className?: string;\n}\n\nfunction FrameWrapper({ layoutId, style, children }: { layoutId: string | undefined; style: React.CSSProperties; children: React.ReactNode }) {\n  return (\n    <motion.div layoutId={layoutId} style={style}>\n      {children}\n    </motion.div>\n  );\n}\n\nexport function VideoGlowLightbox({\n  videoType = \"url\",\n  videoUrl = \"\",\n  videoFile = \"\",\n  thumbnailImage,\n  glowColor = \"#3633FF\",\n  glowIntensity = 55,\n  glowBlur = 48,\n  glowSpread = 20,\n  glowAnimation = true,\n  glowAnimationSpeed = 3,\n  borderRadius = 16,\n  borderWidth = 1.5,\n  borderColor = \"rgba(107, 51, 255, 0.5)\",\n  frameBackground = \"#000000\",\n  overlayColor = \"rgba(0,0,0,0.88)\",\n  lightboxBorderRadius = 14,\n  lightboxMaxWidth = 900,\n  lightboxGlow = true,\n  lightboxTransition = \"morph\",\n  aspectRatio = \"16/9\",\n  innerGlowSize = 18,\n  showPlayButton = true,\n  playButtonSize = 64,\n  playButtonColor = \"#ffffff\",\n  showCursorLabel = false,\n  cursorLabelText = \"Watch\",\n  cursorLabelBg = \"#ffffff\",\n  cursorLabelColor = \"#0a0a0a\",\n  enableHoverPreview = false,\n  hoverPreviewDelay = 400,\n  soundReactiveGlow = false,\n  soundReactiveIntensity = 3.5,\n  className,\n}: VideoGlowLightboxProps) {\n  const [prefersReduced, setPrefersReduced] = React.useState(false);\n  React.useEffect(() => {\n    const mq = window.matchMedia?.(\"(prefers-reduced-motion: reduce)\");\n    if (!mq) return;\n    const t = setTimeout(() => setPrefersReduced(mq.matches), 0);\n    const handleChange = (e: MediaQueryListEvent) => setPrefersReduced(e.matches);\n    mq.addEventListener(\"change\", handleChange);\n    return () => {\n      clearTimeout(t);\n      mq.removeEventListener(\"change\", handleChange);\n    };\n  }, []);\n\n  const overlayRef = React.useRef<HTMLDivElement>(null);\n  const videoRef = React.useRef<HTMLVideoElement>(null);\n  const triggerRef = React.useRef<HTMLDivElement>(null);\n  const previewTimerRef = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n  const wasOpenRef = React.useRef(false);\n  const reactId = React.useId().replace(/[^a-zA-Z0-9-]/g, \"\");\n\n  const [isOpen, setIsOpen] = React.useState(false);\n  const [hovered, setHovered] = React.useState(false);\n  const [previewActive, setPreviewActive] = React.useState(false);\n\n  const cursorX = useMotionValue(0);\n  const cursorY = useMotionValue(0);\n  const labelX = useSpring(cursorX, { stiffness: 300, damping: 30, mass: 0.4 });\n  const labelY = useSpring(cursorY, { stiffness: 300, damping: 30, mass: 0.4 });\n\n  const audioLevel = useMotionValue(0);\n\n  const thumbSrc = thumbnailImage;\n\n  const rawSrc = videoType === \"file\"\n      ? videoFile\n      : videoUrl;\n\n  const open = React.useCallback(() => {\n    if (!rawSrc) return;\n    setIsOpen(true);\n    setPreviewActive(false);\n    if (previewTimerRef.current) {\n      clearTimeout(previewTimerRef.current);\n      previewTimerRef.current = null;\n    }\n  }, [rawSrc]);\n  const close = React.useCallback(() => setIsOpen(false), []);\n\n  React.useEffect(() => {\n    if (isOpen) {\n      overlayRef.current?.focus();\n      wasOpenRef.current = true;\n    } else if (wasOpenRef.current) {\n      triggerRef.current?.focus();\n      wasOpenRef.current = false;\n    }\n  }, [isOpen]);\n\n  React.useEffect(() => {\n    if (!isOpen) return;\n    const el = overlayRef.current;\n    if (!el) return;\n    const getFocusable = () =>\n      Array.from(el.querySelectorAll<HTMLElement>('button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])')).filter((n) => !n.hasAttribute(\"disabled\"));\n    const handleTab = (e: KeyboardEvent) => {\n      if (e.key !== \"Tab\") return;\n      const nodes = getFocusable();\n      if (!nodes.length) return;\n      const first = nodes[0];\n      const last = nodes[nodes.length - 1];\n      if (e.shiftKey) {\n        if (document.activeElement === first) {\n          e.preventDefault();\n          last.focus();\n        }\n      } else {\n        if (document.activeElement === last) {\n          e.preventDefault();\n          first.focus();\n        }\n      }\n    };\n    el.addEventListener(\"keydown\", handleTab);\n    return () => el.removeEventListener(\"keydown\", handleTab);\n  }, [isOpen]);\n\n  const handleMouseEnter = React.useCallback(() => {\n    setHovered(true);\n    if (enableHoverPreview) {\n      previewTimerRef.current = setTimeout(() => setPreviewActive(true), hoverPreviewDelay);\n    }\n  }, [enableHoverPreview, hoverPreviewDelay]);\n\n  const handleMouseLeave = React.useCallback(() => {\n    setHovered(false);\n    if (previewTimerRef.current) {\n      clearTimeout(previewTimerRef.current);\n      previewTimerRef.current = null;\n    }\n    setPreviewActive(false);\n  }, []);\n\n  const handleMouseMove = React.useCallback(\n    (e: React.MouseEvent<HTMLDivElement>) => {\n      if (!showCursorLabel) return;\n      const rect = e.currentTarget.getBoundingClientRect();\n      cursorX.set(e.clientX - rect.left);\n      cursorY.set(e.clientY - rect.top);\n    },\n    [showCursorLabel, cursorX, cursorY]\n  );\n\n  React.useEffect(() => {\n    return () => {\n      if (previewTimerRef.current) clearTimeout(previewTimerRef.current);\n    };\n  }, []);\n\n  const ytId = getYouTubeId(rawSrc || \"\");\n  const vimeoId = getVimeoId(rawSrc || \"\");\n  const isYouTube = videoType === \"youtube\" || (videoType === \"url\" && !!ytId);\n  const isVimeo = videoType === \"vimeo\" || (videoType === \"url\" && !isYouTube && !!vimeoId);\n  const isEmbed = isYouTube || isVimeo;\n\n  const playbackSrc = isYouTube\n    ? `https://www.youtube.com/embed/${ytId}?autoplay=1&rel=0&modestbranding=1&color=white`\n    : isVimeo\n      ? `https://player.vimeo.com/video/${vimeoId}?autoplay=1&title=0&byline=0&portrait=0`\n      : rawSrc;\n\n  const previewSrc = isYouTube\n    ? `https://www.youtube.com/embed/${ytId}?autoplay=1&mute=1&loop=1&playlist=${ytId}&controls=0&modestbranding=1&playsinline=1&rel=0`\n    : isVimeo\n      ? `https://player.vimeo.com/video/${vimeoId}?autoplay=1&muted=1&loop=1&background=1&controls=0`\n      : rawSrc;\n\n  const glowAlpha = Math.max(0, Math.min(1, glowIntensity / 100));\n  const showPreview = previewActive && !isOpen && !!rawSrc;\n  const useMorph = lightboxTransition === \"morph\";\n  const frameLayoutId = `vgl-frame-${reactId}`;\n\n  React.useEffect(() => {\n    if (!isOpen || !soundReactiveGlow || isEmbed) return;\n    const videoEl = videoRef.current;\n    if (!videoEl) return;\n\n    let rafId = 0;\n    let cancelled = false;\n    let audioCtx: AudioContext | null = null;\n\n    try {\n      const Ctx = window.AudioContext || (window as unknown as { webkitAudioContext: typeof AudioContext }).webkitAudioContext;\n      audioCtx = new Ctx();\n      const source = audioCtx.createMediaElementSource(videoEl);\n      const analyser = audioCtx.createAnalyser();\n      analyser.fftSize = 256;\n      analyser.smoothingTimeConstant = 0.82;\n      source.connect(analyser);\n      analyser.connect(audioCtx.destination);\n\n      const data = new Uint8Array(analyser.frequencyBinCount);\n      const tick = () => {\n        if (cancelled) return;\n        analyser.getByteFrequencyData(data);\n        let sum = 0;\n        for (let i = 0; i < data.length; i++) sum += data[i];\n        const level = (sum / data.length / 255) * soundReactiveIntensity;\n        audioLevel.set(Math.min(1, level));\n        rafId = requestAnimationFrame(tick);\n      };\n      tick();\n    } catch {\n      // Cross-origin audio or unsupported API — glow stays static\n    }\n\n    return () => {\n      cancelled = true;\n      if (rafId) cancelAnimationFrame(rafId);\n      audioLevel.set(0);\n      if (audioCtx) audioCtx.close().catch(() => {});\n    };\n  }, [isOpen, soundReactiveGlow, isEmbed, soundReactiveIntensity, audioLevel]);\n\n  return (\n    <div className={cn(\"relative flex h-full w-full flex-col\", className)}>\n      <div\n        ref={triggerRef}\n        className=\"relative w-full flex-1\"\n        style={{ minHeight: 0, cursor: rawSrc ? \"pointer\" : \"default\" }}\n        role=\"button\"\n        tabIndex={rawSrc ? 0 : -1}\n        aria-label=\"Play video\"\n        aria-disabled={!rawSrc ? true : undefined}\n        onClick={open}\n        onKeyDown={(e) => {\n          if (e.key === \"Enter\" || e.key === \" \") {\n            e.preventDefault();\n            open();\n          }\n        }}\n        onMouseEnter={handleMouseEnter}\n        onMouseLeave={handleMouseLeave}\n        onMouseMove={handleMouseMove}\n      >\n        <motion.div\n          aria-hidden=\"true\"\n          className=\"pointer-events-none absolute z-0\"\n          style={{ inset: -glowSpread, background: glowColor, borderRadius: borderRadius + glowSpread, filter: `blur(${glowBlur}px)` }}\n          animate={{\n            opacity: hovered\n              ? Math.min(glowAlpha * 1.85, 0.95)\n              : glowAnimation && !prefersReduced\n                ? [glowAlpha * 0.6, glowAlpha * 1.05, glowAlpha * 0.6]\n                : glowAlpha * 0.8,\n          }}\n          transition={hovered ? { duration: 0.3, ease: \"easeOut\" } : glowAnimation && !prefersReduced ? { duration: glowAnimationSpeed, repeat: Infinity, ease: \"easeInOut\" } : { duration: 0.3 }}\n        />\n\n        <FrameWrapper layoutId={useMorph ? frameLayoutId : undefined} style={{ position: \"relative\", width: \"100%\", height: \"100%\", borderRadius, border: `${borderWidth}px solid ${borderColor}`, overflow: \"hidden\", background: frameBackground, zIndex: 1 }}>\n          <div\n            aria-hidden=\"true\"\n            className=\"pointer-events-none absolute top-0 right-0 left-0 z-[4]\"\n            style={{ height: \"45%\", background: \"linear-gradient(180deg, rgba(255,255,255,0.07) 0%, transparent 100%)\", borderRadius: `${Math.max(0, borderRadius - 1)}px ${Math.max(0, borderRadius - 1)}px 0 0` }}\n          />\n\n          {thumbSrc ? (\n            <motion.img\n              src={thumbSrc}\n              alt=\"\"\n              draggable={false}\n              className=\"block h-full w-full object-cover select-none\"\n              animate={{ scale: hovered ? 1.04 : 1 }}\n              transition={{ duration: 0.5, ease: [0.25, 0.46, 0.45, 0.94] }}\n            />\n          ) : (\n            <div aria-hidden=\"true\" className=\"h-full w-full\" style={{ background: \"linear-gradient(145deg, #0e0e1c 0%, #1a0f30 45%, #0c1a38 100%)\" }} />\n          )}\n\n          {enableHoverPreview && (\n            <motion.div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 z-[1] bg-black\" animate={{ opacity: showPreview ? 1 : 0 }} transition={{ duration: 0.4, ease: \"easeOut\" }}>\n              {showPreview &&\n                (isEmbed ? (\n                  <iframe key={previewSrc} src={previewSrc} className=\"pointer-events-none block h-full w-full border-none\" allow=\"autoplay; fullscreen\" title=\"Preview\" />\n                ) : (\n                  <video key={previewSrc} src={previewSrc} muted autoPlay loop playsInline className=\"block h-full w-full object-cover\" />\n                ))}\n            </motion.div>\n          )}\n\n          {innerGlowSize > 0 && (\n            <div\n              aria-hidden=\"true\"\n              className=\"pointer-events-none absolute inset-0 z-[5] opacity-70\"\n              style={{ borderRadius: Math.max(0, borderRadius - borderWidth), boxShadow: `inset 0 0 ${innerGlowSize}px ${Math.ceil(innerGlowSize / 5)}px ${glowColor}` }}\n            />\n          )}\n\n          <motion.div aria-hidden=\"true\" className=\"absolute inset-0 z-[2]\" style={{ background: \"rgba(0,0,0,0.22)\" }} animate={{ opacity: hovered ? 1 : 0 }} transition={{ duration: 0.22 }} />\n\n          {showPlayButton && (\n            <div className=\"absolute inset-0 z-[3] flex items-center justify-center\">\n              <motion.div\n                animate={{ scale: hovered ? 1.12 : 1, opacity: hovered ? 1 : 0.88 }}\n                transition={{ duration: 0.28, ease: \"easeOut\" }}\n                style={{ filter: \"drop-shadow(0 6px 20px rgba(0,0,0,0.55))\" }}\n              >\n                <PlayIcon size={playButtonSize} color={playButtonColor} />\n              </motion.div>\n            </div>\n          )}\n        </FrameWrapper>\n\n        {showCursorLabel && (\n          <motion.div\n            aria-hidden=\"true\"\n            className=\"pointer-events-none absolute z-[6] rounded-full text-[13px] font-semibold whitespace-nowrap\"\n            style={{ left: labelX, top: labelY, x: \"-50%\", y: \"-50%\", padding: \"11px 24px\", background: cursorLabelBg, color: cursorLabelColor, letterSpacing: \"0.02em\", boxShadow: \"0 8px 24px rgba(0,0,0,0.25)\" }}\n            animate={{ opacity: hovered ? 1 : 0, scale: hovered ? 1 : 0.7 }}\n            transition={{ duration: 0.22, ease: \"easeOut\" }}\n          >\n            {cursorLabelText}\n          </motion.div>\n        )}\n      </div>\n\n      <AnimatePresence>\n        {isOpen && (\n          <motion.div\n            key=\"vgl-overlay\"\n            ref={overlayRef}\n            role=\"dialog\"\n            aria-modal=\"true\"\n            aria-label=\"Video player\"\n            tabIndex={-1}\n            initial={{ opacity: 0 }}\n            animate={{ opacity: 1 }}\n            exit={{ opacity: 0 }}\n            transition={{ duration: 0.28, ease: \"easeOut\" }}\n            onClick={(e) => e.target === e.currentTarget && close()}\n            onKeyDown={(e) => e.key === \"Escape\" && close()}\n            className=\"fixed inset-0 z-[99999] flex items-center justify-center p-6 outline-none backdrop-blur-[18px]\"\n            style={{ background: overlayColor }}\n          >\n            {lightboxGlow && (\n              <motion.div\n                aria-hidden=\"true\"\n                initial={{ opacity: 0, scale: 0.75 }}\n                animate={{ opacity: 0.28, scale: 1 }}\n                exit={{ opacity: 0 }}\n                transition={{ duration: 0.5, ease: \"easeOut\" }}\n                className=\"pointer-events-none absolute w-[65%]\"\n                style={{ maxWidth: lightboxMaxWidth, aspectRatio, background: `radial-gradient(ellipse at center, ${glowColor} 0%, transparent 68%)`, filter: \"blur(48px)\" }}\n              />\n            )}\n\n            {lightboxGlow && soundReactiveGlow && !isEmbed && (\n              <motion.div\n                aria-hidden=\"true\"\n                className=\"pointer-events-none absolute w-[65%]\"\n                style={{ maxWidth: lightboxMaxWidth, aspectRatio, background: `radial-gradient(ellipse at center, ${glowColor} 0%, transparent 68%)`, filter: \"blur(48px)\", opacity: audioLevel }}\n              />\n            )}\n\n            <motion.button\n              key=\"vgl-close\"\n              initial={{ opacity: 0, y: -10 }}\n              animate={{ opacity: 1, y: 0 }}\n              exit={{ opacity: 0, y: -6 }}\n              transition={{ delay: 0.1, duration: 0.2 }}\n              onClick={close}\n              aria-label=\"Close video\"\n              whileHover={{ scale: 1.1 }}\n              whileTap={{ scale: 0.9 }}\n              className=\"absolute top-6 right-6 z-[2] flex h-11 w-11 items-center justify-center rounded-full border border-white/18 bg-white/10 backdrop-blur-[10px]\"\n            >\n              <CloseIcon />\n            </motion.button>\n\n            <motion.div\n              key=\"vgl-video\"\n              layoutId={useMorph ? frameLayoutId : undefined}\n              initial={useMorph ? false : { opacity: 0, scale: 0.86, y: 44 }}\n              animate={useMorph ? undefined : { opacity: 1, scale: 1, y: 0 }}\n              exit={useMorph ? { opacity: 1 } : { opacity: 0, scale: 0.9, y: 24 }}\n              transition={useMorph ? { type: \"spring\", damping: 28, stiffness: 260 } : { type: \"spring\", damping: 26, stiffness: 320, delay: 0.04 }}\n              className=\"relative w-full overflow-hidden bg-black shadow-[0_36px_90px_rgba(0,0,0,0.85)]\"\n              style={{ maxWidth: lightboxMaxWidth, aspectRatio, borderRadius: lightboxBorderRadius, border: `${borderWidth}px solid ${borderColor}` }}\n            >\n              {innerGlowSize > 0 && (\n                <div\n                  aria-hidden=\"true\"\n                  className=\"pointer-events-none absolute inset-0 z-[3] opacity-70\"\n                  style={{ borderRadius: Math.max(0, lightboxBorderRadius - borderWidth), boxShadow: `inset 0 0 ${innerGlowSize}px ${Math.ceil(innerGlowSize / 5)}px ${glowColor}` }}\n                />\n              )}\n\n              <div\n                aria-hidden=\"true\"\n                className=\"pointer-events-none absolute top-0 right-0 left-0 z-[2]\"\n                style={{ height: \"42%\", background: \"linear-gradient(180deg, rgba(255,255,255,0.06) 0%, transparent 100%)\", borderRadius: `${Math.max(0, lightboxBorderRadius - 1)}px ${Math.max(0, lightboxBorderRadius - 1)}px 0 0` }}\n              />\n\n              {isEmbed ? (\n                <iframe\n                  key={playbackSrc}\n                  src={playbackSrc}\n                  className=\"block h-full w-full border-none\"\n                  allow=\"autoplay; fullscreen; picture-in-picture; accelerometer; encrypted-media; gyroscope\"\n                  allowFullScreen\n                  title=\"Video\"\n                />\n              ) : (\n                <video\n                  key={playbackSrc}\n                  ref={videoRef}\n                  src={playbackSrc}\n                  title=\"Video\"\n                  crossOrigin={soundReactiveGlow && videoType === \"file\" ? \"anonymous\" : undefined}\n                  autoPlay\n                  controls\n                  playsInline\n                  className=\"block h-full w-full bg-black\"\n                />\n              )}\n            </motion.div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}