{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "book-3d",
  "type": "registry:ui",
  "title": "Book 3D",
  "description": "An interactive 3D book component with realistic hover perspective tilt.",
  "dependencies": [
    "motion",
    "react"
  ],
  "devDependencies": [
    "@types/react"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "ui/book-3d.tsx",
      "content": "'use client';\n\nimport { motion, AnimatePresence } from 'motion/react';\nimport { cn } from '@/lib/utils';\nimport { useState, useEffect, useRef } from 'react';\n\ninterface PageData {\n  title?: string;\n  content?: string;\n  image?: string;\n  caption?: string;\n  quote?: string;\n  author?: string;\n}\n\ninterface Book3DProps {\n  src?: string;\n  title?: string;\n  subtitle?: string;\n  width?: number;\n  height?: number;\n  className?: string;\n  pages?: PageData[];\n}\n\n// Inline SVG fractal noise data URI for tactile bookcloth texture\nconst NOISE_DATA_URL =\n  \"data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.35'/%3E%3C/svg%3E\";\n\nexport function Book3D({\n  src,\n  title,\n  subtitle,\n  width = 230,\n  height = 350,\n  className,\n  pages = [\n    {\n      title: 'Welcome to ShitUI',\n      content:\n        'A premium collection of beautifully crafted, animated React components. Built with Motion and Tailwind CSS for modern web applications.',\n    },\n    {\n      image:\n        'https://images.unsplash.com/photo-1589561253898-768105ca91a8?q=80&w=1738&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D',\n      caption: 'Beautiful Design',\n    },\n    {\n      title: 'Premium Components',\n      content:\n        'From glass-morphic buttons to 3D cards, each component is designed with attention to detail. Self-contained, easy to install via CLI, and ready to use.',\n    },\n    {\n      quote:\n        'Great design is not just what looks good. It also needs to perform, convert, and amaze.',\n      author: 'ShitUI Philosophy',\n    },\n    {\n      title: 'Getting Started',\n      content:\n        'Install any component with a single command: npx shadcn@latest add @shitui/[component-name]. No configuration needed, just beautiful components ready to go.',\n    },\n    {\n      title: 'Build Something Great',\n      content:\n        'Join thousands of developers creating stunning interfaces with ShitUI. Your next project deserves components that stand out.',\n    },\n  ],\n}: Book3DProps) {\n  const [isHovered, setIsHovered] = useState(false);\n  const [pageIndex, setPageIndex] = useState(0); // 0 means just cover open, no pages flipped\n  const bookContainerRef = useRef<HTMLDivElement>(null);\n\n  // Close book when user clicks/taps outside on mobile/touch screens\n  useEffect(() => {\n    if (!isHovered) return;\n    const handleOutsideInteraction = (e: MouseEvent | TouchEvent) => {\n      if (bookContainerRef.current && !bookContainerRef.current.contains(e.target as Node)) {\n        setIsHovered(false);\n      }\n    };\n    document.addEventListener('touchstart', handleOutsideInteraction);\n    document.addEventListener('mousedown', handleOutsideInteraction);\n    return () => {\n      document.removeEventListener('touchstart', handleOutsideInteraction);\n      document.removeEventListener('mousedown', handleOutsideInteraction);\n    };\n  }, [isHovered]);\n\n  // Reset pages when book closes\n  useEffect(() => {\n    if (!isHovered) {\n      const timer = setTimeout(() => {\n        setPageIndex(0);\n      }, 300); // Small delay to allow cover to start closing\n      return () => clearTimeout(timer);\n    }\n  }, [isHovered]);\n\n  const [isFlipping, setIsFlipping] = useState(false);\n\n  const handlePageClick = (index: number) => {\n    if (!isHovered || isFlipping) return;\n    if (pageIndex === index) {\n      setIsFlipping(true);\n      setPageIndex((prev) => prev + 1);\n      setTimeout(() => setIsFlipping(false), 300); // Debounce\n    }\n  };\n\n  const handleBackClick = (e: React.MouseEvent, index: number) => {\n    e.stopPropagation();\n    if (isFlipping) return;\n    setIsFlipping(true);\n    setPageIndex(index);\n    setTimeout(() => setIsFlipping(false), 300);\n  };\n\n  const handleContainerClick = () => {\n    // If book is closed on touch screen or tap, open it\n    if (!isHovered) {\n      setIsHovered(true);\n    }\n  };\n\n  return (\n    <div\n      ref={bookContainerRef}\n      className={cn('group relative z-10 cursor-pointer', className, isHovered && 'z-50')}\n      style={{\n        perspective: '1500px',\n        paddingLeft: '150px', // Extra space for the rotated cover on the left\n        marginLeft: '-150px', // Pull back to maintain visual position\n      }}\n      onClick={handleContainerClick}\n      onMouseEnter={() => setIsHovered(true)}\n      onMouseLeave={() => setIsHovered(false)}\n    >\n      <motion.div\n        className=\"preserve-3d relative transition-all duration-700 ease-out\"\n        style={{\n          width,\n          height,\n          transformStyle: 'preserve-3d',\n        }}\n        animate={{\n          rotateY: isHovered ? -35 : 0,\n          rotateX: isHovered ? 15 : 0,\n          z: isHovered ? 60 : 0,\n        }}\n      >\n        {/* Back Cover - Bound with matching tactile blue cloth */}\n        <div\n          className=\"absolute inset-0 rounded-l-sm rounded-r-md shadow-2xl\"\n          style={{\n            transform: 'translateZ(-20px)',\n            boxShadow: '20px 20px 50px rgba(0,0,0,0.5)',\n            backgroundColor: '#1f5ad1',\n            backgroundImage: `url(\"${NOISE_DATA_URL}\")`,\n          }}\n        />\n\n        {/* PAGES STACK */}\n        {Array.from({ length: pages.length })\n          .map((_, i) => pages.length - 1 - i)\n          .map((index) => {\n            const isFlipped = index < pageIndex;\n\n            // Dynamic z-index optimization\n            let activeZIndex = 0;\n            if (isFlipped) {\n              activeZIndex = index + 1;\n            } else {\n              activeZIndex = 20 - index; // Higher base to safely sit above back cover but below front cover\n            }\n\n            return (\n              <motion.div\n                key={index}\n                className=\"transform-style-3d absolute inset-y-[2px] right-[2px] left-[4px] origin-left cursor-pointer rounded-l-sm rounded-r-md border border-neutral-100/50 bg-[#fffcf5]\"\n                style={{\n                  transformStyle: 'preserve-3d',\n                  zIndex: activeZIndex,\n                }}\n                animate={{\n                  rotateY: isFlipped ? -178 : 0,\n                  z: isFlipped ? 0 : pages.length - 1 - index,\n                }}\n                transition={{\n                  duration: 0.6,\n                  ease: [0.23, 1, 0.32, 1],\n                  delay: isFlipped ? 0 : index * 0.05,\n                }}\n                onClick={(e) => {\n                  e.stopPropagation();\n                  if (isFlipped) {\n                    handleBackClick(e, index);\n                  } else {\n                    handlePageClick(index);\n                  }\n                }}\n              >\n                {/* FRONT FACE (Right side content) */}\n                <div\n                  className=\"absolute inset-0 flex flex-col items-center justify-center overflow-hidden bg-white p-6 text-center backface-hidden\"\n                  style={{ backfaceVisibility: 'hidden' }}\n                >\n                  <div className=\"pointer-events-none absolute inset-0 bg-[url('https://www.transparenttextures.com/patterns/paper.png')] opacity-10\" />\n                  {/* Deeper right edge shadow for book crease */}\n                  <div className=\"pointer-events-none absolute top-0 right-0 bottom-0 w-12 bg-linear-to-l from-black/20 via-black/5 to-transparent\" />\n                  {/* Left edge for binding */}\n                  <div className=\"pointer-events-none absolute top-0 bottom-0 left-0 w-2 bg-linear-to-r from-black/10 to-transparent\" />\n\n                  <div className=\"relative z-10 font-serif text-neutral-800 select-none\">\n                    {pages[index].image && (\n                      <div className=\"mb-4 overflow-hidden rounded-sm border border-neutral-200 shadow-inner\">\n                        <img\n                          src={pages[index].image}\n                          alt=\"Page visual\"\n                          className=\"h-32 w-full object-cover grayscale transition-all hover:grayscale-0\"\n                        />\n                      </div>\n                    )}\n                    {pages[index].title && (\n                      <h3 className=\"mb-2 font-sans text-lg text-[10px] font-bold tracking-widest uppercase\">\n                        {pages[index].title}\n                      </h3>\n                    )}\n                    {pages[index].content && (\n                      <p className=\"text-[10px] leading-relaxed text-neutral-600\">\n                        {pages[index].content}\n                      </p>\n                    )}\n                    {pages[index].quote && (\n                      <blockquote className=\"border-l-2 border-neutral-300 pl-3 text-sm text-neutral-600 italic\">\n                        \"{pages[index].quote}\"\n                        <footer className=\"mt-2 font-sans text-[9px] text-neutral-400 not-italic\">\n                          - {pages[index].author}\n                        </footer>\n                      </blockquote>\n                    )}\n                    <span className=\"absolute right-4 bottom-2 text-[8px] text-neutral-400\">\n                      {index + 1}\n                    </span>\n                  </div>\n                </div>\n\n                {/* BACK FACE (Left side content) */}\n                <div\n                  className=\"absolute inset-0 flex items-center justify-center bg-[#f8f5f0] backface-hidden\"\n                  style={{\n                    transform: 'rotateY(180deg)',\n                    backfaceVisibility: 'hidden',\n                  }}\n                >\n                  <div className=\"pointer-events-none absolute inset-0 bg-[url('https://www.transparenttextures.com/patterns/paper.png')] opacity-10\" />\n                  {/* Left edge shadow (becomes visible when flipped) */}\n                  <div className=\"pointer-events-none absolute top-0 bottom-0 left-0 w-12 bg-linear-to-r from-black/20 via-black/5 to-transparent\" />\n                  <div className=\"rotate-90 transform font-sans text-[9px] tracking-widest text-neutral-400 uppercase opacity-30 select-none\">\n                    Notes\n                  </div>\n                </div>\n              </motion.div>\n            );\n          })}\n\n        {/* Front Cover */}\n        <motion.div\n          className={cn(\n            'absolute inset-0 origin-left cursor-pointer',\n            isHovered ? 'z-50' : 'z-50'\n          )}\n          onClick={(e) => {\n            if (isHovered) {\n              e.stopPropagation();\n              setIsHovered(false);\n            }\n          }}\n          style={{\n            transformStyle: 'preserve-3d',\n            transform: !isHovered ? 'translateZ(10px)' : undefined, // Ensure it starts in front\n          }}\n          initial={{\n            rotateY: 0,\n            z: 10,\n          }}\n          animate={{\n            rotateY: isHovered ? -180 : 0,\n            z: isHovered ? 0 : 10, // Push far forward when closed to be in front of all pages\n          }}\n          transition={{\n            duration: 0.8,\n            ease: [0.23, 1, 0.32, 1],\n            delay: isHovered ? 0 : 0.5, // Delay closing so pages flip back first\n          }}\n        >\n          {/* Outer Cover */}\n          <div\n            className={cn(\n              'absolute inset-0 overflow-hidden rounded-l-sm rounded-r-md border-l border-white/20 shadow-md backface-hidden',\n              src ? 'bg-neutral-900' : 'bg-[#3f80ff]'\n            )}\n            style={{\n              backgroundImage: src\n                ? `url(${src})`\n                : 'linear-gradient(135deg, #4d8aff 0%, #3f80ff 50%, #2b6fe8 100%)',\n              backgroundSize: src ? 'cover' : undefined,\n              backgroundPosition: src ? 'center' : undefined,\n              backfaceVisibility: 'hidden',\n            }}\n          >\n            {/* Conditional overlays based on mode */}\n            {src ? (\n              <>\n                {/* Image mode overlays */}\n                <div className=\"absolute inset-0 bg-linear-to-r from-black/30 to-transparent\" />\n                <div className=\"absolute inset-0 bg-linear-to-b from-black/20 via-transparent to-black/40\" />\n              </>\n            ) : (\n              <>\n                {/* 1. Tactical Noise Overlay for authentic paper/cloth grain */}\n                <div\n                  className=\"pointer-events-none absolute inset-0 mix-blend-overlay opacity-30\"\n                  style={{\n                    backgroundImage: `url(\"${NOISE_DATA_URL}\")`,\n                    backgroundRepeat: 'repeat',\n                  }}\n                />\n\n                {/* 2. Rough / Ruff linen cloth cross-weave texture */}\n                <div\n                  className=\"pointer-events-none absolute inset-0 mix-blend-overlay opacity-20\"\n                  style={{\n                    backgroundImage: `\n                      repeating-linear-gradient(0deg, #000 0px, #000 1px, transparent 1px, transparent 2.5px),\n                      repeating-linear-gradient(90deg, #000 0px, #000 1px, transparent 1px, transparent 2.5px)\n                    `,\n                    backgroundSize: '2.5px 2.5px',\n                  }}\n                />\n\n                {/* 3. Surface Light / Radial Sheen */}\n                <div\n                  className=\"pointer-events-none absolute inset-0 opacity-25\"\n                  style={{\n                    background:\n                      'radial-gradient(ellipse at 35% 25%, rgba(255,255,255,0.6) 0%, transparent 65%), linear-gradient(180deg, rgba(255,255,255,0.15) 0%, rgba(0,0,0,0.2) 100%)',\n                  }}\n                />\n\n                {/* 4. Book Spine Hinge / Fold shadow on left */}\n                <div className=\"pointer-events-none absolute top-0 bottom-0 left-0 w-7 bg-linear-to-r from-black/40 via-white/10 to-transparent z-20\" />\n                <div className=\"pointer-events-none absolute top-0 bottom-0 left-3 w-px bg-black/25 z-20\" />\n\n                {/* 5. Right edge opening shadow */}\n                <div className=\"pointer-events-none absolute top-0 bottom-0 right-0 w-3 bg-linear-to-l from-black/20 to-transparent z-20\" />\n              </>\n            )}\n\n            {/* Content - Custom or Clean Default */}\n            {src || title || subtitle ? (\n              // Custom cover with user's image/title/subtitle\n              <div className=\"absolute inset-0 z-10 flex flex-col items-center justify-center p-8 text-white select-none\">\n                {title && (\n                  <div className=\"mb-4 text-center\">\n                    <div className=\"mx-auto mb-5 h-px w-14 bg-white/50\" />\n                    <h3 className=\"mb-2 font-serif text-3xl font-bold tracking-tight drop-shadow-md\">\n                      {title}\n                    </h3>\n                    <div className=\"mx-auto mt-4 h-px w-14 bg-white/50\" />\n                  </div>\n                )}\n                {subtitle && (\n                  <p className=\"mt-2 text-[11px] font-sans font-medium tracking-[0.2em] uppercase opacity-90\">\n                    {subtitle}\n                  </p>\n                )}\n              </div>\n            ) : (\n              // Clean ShitUI Cover with refined typography and noise/ruff finish\n              <div className=\"absolute inset-0 z-10 flex flex-col justify-between p-7 text-white select-none\">\n                {/* Top header badge */}\n                <div className=\"flex items-center justify-between border-b border-white/20 pb-3\">\n                  <span className=\"font-mono text-[9px] font-semibold tracking-[0.25em] text-white/90 uppercase\">\n                    SHITUI\n                  </span>\n                  <span className=\"font-mono text-[8px] tracking-[0.2em] text-white/70 uppercase\">\n                    VOL. 01\n                  </span>\n                </div>\n\n                {/* Main center branding */}\n                <div className=\"my-auto flex flex-col items-center justify-center py-4 text-center\">\n                  <h1 className=\"font-serif text-[42px] font-bold tracking-tight text-white drop-shadow-[0_2px_8px_rgba(0,0,0,0.25)] leading-none\">\n                    ShitUI\n                  </h1>\n                  <div className=\"mt-3.5 h-0.5 w-8 rounded-full bg-white/70\" />\n                  <p className=\"mt-3.5 text-[10px] font-sans font-medium tracking-[0.22em] text-white/90 uppercase\">\n                    Component Library\n                  </p>\n                </div>\n\n                {/* Bottom details */}\n                <div className=\"flex items-center justify-between border-t border-white/20 pt-3 font-mono text-[8.5px] tracking-widest text-white/75 uppercase\">\n                  <span>REACT / MOTION</span>\n                  <span>2026</span>\n                </div>\n              </div>\n            )}\n          </div>\n\n          {/* Inner Cover */}\n          <div\n            className=\"absolute inset-0 overflow-hidden rounded-l-md rounded-r-sm border-r border-neutral-200 bg-[#f5f1e8] backface-hidden\"\n            style={{\n              transform: 'rotateY(180deg)',\n              backfaceVisibility: 'hidden',\n            }}\n          >\n            <div className=\"flex h-full w-full flex-col justify-end p-8\">\n              <p className=\"text-center font-serif text-xs text-neutral-500 italic select-none\">\n                ShitUI\n              </p>\n            </div>\n          </div>\n        </motion.div>\n      </motion.div>\n\n      {/* Shadow */}\n      <div\n        className={cn(\n          'absolute right-4 bottom-0 left-4 h-10 rounded-[100%] bg-black/40 blur-xl transition-all duration-500',\n          isHovered ? 'scale-110 opacity-80' : 'opacity-40'\n        )}\n        style={{\n          transform: 'perspective(1000px) rotateX(60deg) translateZ(-60px)',\n        }}\n      />\n    </div>\n  );\n}\nexport default Book3D;\n",
      "type": "registry:ui"
    }
  ]
}