{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"extrude-type","type":"registry:ui","title":"Extrude Type","description":"Chunky extruded 3D lettering built from stacked layers that tilts toward the pointer and sways gently when idle.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/extrude-type.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\nexport interface ExtrudeTypeProps {\n  text?: string;\n  /** Number of stacked copies forming the extrusion. */\n  layers?: number;\n  /** Gap between copies, in px. */\n  depth?: number;\n  /** Maximum tilt toward the pointer, in degrees. */\n  maxTilt?: number;\n  /** Front face color. */\n  color?: string;\n  /** Color of the deepest layer. */\n  depthColor?: string;\n  className?: string;\n}\n\nexport function ExtrudeType({\n  text = \"DEPTH\",\n  layers = 20,\n  depth = 3,\n  maxTilt = 24,\n  color = \"#ecfccb\",\n  depthColor = \"#1a2e05\",\n  className,\n}: ExtrudeTypeProps) {\n  const root = useRef<HTMLDivElement>(null);\n  const stack = useRef<HTMLDivElement>(null);\n\n  useEffect(() => {\n    const el = root.current!;\n    const s = stack.current!;\n    const area = el.parentElement ?? el;\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const cur = { x: 0, y: 0 };\n    const target = { x: 0, y: 0 };\n    let hovering = false;\n    let raf = 0;\n    let visible = true;\n\n    const apply = () => (s.style.transform = `rotateX(${cur.x}deg) rotateY(${cur.y}deg)`);\n    if (reduced) {\n      cur.x = maxTilt * 0.3;\n      cur.y = -maxTilt * 0.5;\n      apply();\n      return;\n    }\n\n    const loop = (now: number) => {\n      if (!hovering) {\n        // Idle sway so the extrusion reads even without a pointer.\n        const t = now / 1000;\n        target.y = Math.sin(t * 0.7) * maxTilt * 0.6;\n        target.x = Math.cos(t * 0.5) * maxTilt * 0.3 + maxTilt * 0.15;\n      }\n      cur.x += (target.x - cur.x) * 0.08;\n      cur.y += (target.y - cur.y) * 0.08;\n      apply();\n      raf = visible ? requestAnimationFrame(loop) : 0;\n    };\n    const move = (e: PointerEvent) => {\n      const r = area.getBoundingClientRect();\n      const nx = ((e.clientX - r.left) / r.width) * 2 - 1;\n      const ny = ((e.clientY - r.top) / r.height) * 2 - 1;\n      hovering = true;\n      // Small bias so the extrusion still shows with the pointer dead center.\n      target.y = nx * maxTilt - maxTilt * 0.2;\n      target.x = -ny * maxTilt + maxTilt * 0.25;\n    };\n    const leave = () => (hovering = false);\n\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible && !raf) raf = requestAnimationFrame(loop);\n    });\n    io.observe(el);\n    area.addEventListener(\"pointermove\", move, { passive: true });\n    area.addEventListener(\"pointerleave\", leave);\n    return () => {\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      area.removeEventListener(\"pointermove\", move);\n      area.removeEventListener(\"pointerleave\", leave);\n    };\n  }, [maxTilt]);\n\n  const n = Math.max(1, Math.round(layers));\n  return (\n    <div ref={root} className={className} style={{ perspective: \"1000px\", display: \"inline-block\" }}>\n      <span className=\"sr-only\">{text}</span>\n      <div ref={stack} aria-hidden style={{ position: \"relative\", transformStyle: \"preserve-3d\", willChange: \"transform\" }}>\n        {Array.from({ length: n }, (_, k) => {\n          const i = n - 1 - k; // back to front\n          const mix = n > 1 ? Math.round(45 + (i / (n - 1)) * 55) : 0;\n          return (\n            <span\n              key={i}\n              style={{\n                position: i === 0 ? \"relative\" : \"absolute\",\n                inset: 0,\n                display: \"block\",\n                whiteSpace: \"pre\",\n                transform: `translateZ(${-i * depth}px)`,\n                color: i === 0 ? color : `color-mix(in oklab, ${depthColor} ${mix}%, ${color})`,\n              }}\n            >\n              {text}\n            </span>\n          );\n        })}\n      </div>\n    </div>\n  );\n}\n"}]}