{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tilt-text",
  "title": "Tilt Text",
  "description": "Large display text that tilts in 3D toward the cursor, with a layered shadow extrusion for real depth, a specular shine highlight, and idle float/breathe animations.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/tilt-text/tilt-text.tsx",
      "content": "\"use client\";\n\nimport * as React from \"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 type TiltTextGradientDirection = \"horizontal\" | \"vertical\" | \"diagonal\" | \"radial\";\n\nexport interface TiltTextProps extends Omit<React.ComponentPropsWithoutRef<\"div\">, \"children\"> {\n  text?: string;\n  fontSize?: number;\n  autoFit?: boolean;\n  fitPadding?: number;\n  fontWeight?: string;\n  fontFamily?: string;\n  letterSpacing?: number;\n  lineHeight?: number;\n  textColor?: string;\n  backgroundColor?: string;\n  useGradient?: boolean;\n  gradientColorTo?: string;\n  gradientDirection?: TiltTextGradientDirection;\n  perspectiveDepth?: number;\n  tiltStrength?: number;\n  smoothing?: number;\n  scaleOnHover?: boolean;\n  scaleAmount?: number;\n}\n\nexport function TiltText({\n  text = \"WOAH THERE\",\n  fontSize = 140,\n  autoFit = false,\n  fitPadding = 8,\n  fontWeight = \"700\",\n  fontFamily = \"Inter, sans-serif\",\n  letterSpacing = -3,\n  lineHeight = 1.1,\n  textColor = \"#ffffff\",\n  backgroundColor = \"#0a0a0a\",\n  useGradient = false,\n  gradientColorTo = \"#ff55ee\",\n  gradientDirection = \"horizontal\",\n  perspectiveDepth = 900,\n  tiltStrength = 60,\n  smoothing = 0.08,\n  scaleOnHover = true,\n  scaleAmount = 1.05,\n  className,\n  style,\n  ...props\n}: TiltTextProps) {\n  const containerRef = React.useRef<HTMLDivElement>(null);\n  const sceneRef = React.useRef<HTMLDivElement>(null);\n  const mouseRef = React.useRef({ x: -9999, y: -9999, over: false });\n  // Single object for all animated values — updated each frame, never triggers re-render.\n  const animRef = React.useRef({ rotX: 0, rotY: 0, scale: 1 });\n  const rafRef = React.useRef(0);\n\n  const [computedFontSize, setComputedFontSize] = React.useState(fontSize);\n\n  // Live config ref — written every render, read inside the RAF loop.\n  const live = React.useRef({\n    tiltStrength: tiltStrength,\n    perspectiveDepth,\n    smoothing,\n    scaleOnHover,\n    scaleAmount,\n  });\n  React.useEffect(() => {\n    const lc = live.current;\n    lc.tiltStrength = tiltStrength;\n    lc.perspectiveDepth = perspectiveDepth;\n    lc.smoothing = smoothing;\n    lc.scaleOnHover = scaleOnHover;\n    lc.scaleAmount = scaleAmount;\n  }, [tiltStrength, perspectiveDepth, smoothing, scaleOnHover, scaleAmount]);\n\n  const computeFontSizeFn = React.useCallback(() => {\n    if (!autoFit) return;\n    const el = containerRef.current;\n    if (!el) return;\n    const cw = el.offsetWidth;\n    const ch = el.offsetHeight;\n    if (!cw || !ch) return;\n    const off = document.createElement(\"canvas\");\n    const ctx = off.getContext(\"2d\")!;\n    ctx.font = `${fontWeight} 100px ${fontFamily}`;\n    const w100 = ctx.measureText(text).width;\n    if (w100 === 0) return;\n    const padded = cw * (1 - (fitPadding * 2) / 100);\n    setComputedFontSize(Math.min(Math.floor((padded / w100) * 100), Math.floor(ch * 0.85)));\n  }, [autoFit, fontWeight, fontFamily, text, fitPadding]);\n\n  React.useEffect(() => {\n    if (!autoFit) {\n      setComputedFontSize(fontSize);\n      return;\n    }\n    const el = containerRef.current;\n    if (!el) return;\n    let timer = 0;\n    const ro = new ResizeObserver(() => {\n      clearTimeout(timer);\n      timer = window.setTimeout(computeFontSizeFn, 80);\n    });\n    ro.observe(el);\n    computeFontSizeFn();\n    return () => {\n      ro.disconnect();\n      clearTimeout(timer);\n    };\n  }, [autoFit, fontSize, computeFontSizeFn]);\n\n  // Animation loop — mounted once.\n  React.useEffect(() => {\n    let alive = true;\n\n    const tick = () => {\n      if (!alive) return;\n      const cfg = live.current;\n      const anim = animRef.current;\n      const { x: mx, y: my, over } = mouseRef.current;\n\n      let tRotX = 0,\n        tRotY = 0,\n        tScale = 1;\n\n      if (over && mx > -9000 && containerRef.current) {\n        const w = containerRef.current.offsetWidth;\n        const h = containerRef.current.offsetHeight;\n        // Normalize cursor position to [-1, 1] from element center.\n        const nx = (mx / w - 0.5) * 2;\n        const ny = (my / h - 0.5) * 2;\n        tRotX = -ny * cfg.tiltStrength;\n        tRotY = nx * cfg.tiltStrength;\n        tScale = cfg.scaleOnHover ? cfg.scaleAmount : 1;\n      }\n\n      const sm = Math.min(1, Math.max(0.01, cfg.smoothing));\n      anim.rotX += (tRotX - anim.rotX) * sm;\n      anim.rotY += (tRotY - anim.rotY) * sm;\n      anim.scale += (tScale - anim.scale) * sm;\n\n      // Write directly to the DOM — zero React overhead in the hot path.\n      if (sceneRef.current) {\n        sceneRef.current.style.transform = [\n          `perspective(${cfg.perspectiveDepth}px)`,\n          `rotateX(${anim.rotX.toFixed(4)}deg)`,\n          `rotateY(${anim.rotY.toFixed(4)}deg)`,\n          `scale(${anim.scale.toFixed(5)})`,\n        ].join(\" \");\n      }\n\n      rafRef.current = requestAnimationFrame(tick);\n    };\n\n    rafRef.current = requestAnimationFrame(tick);\n    return () => {\n      alive = false;\n      cancelAnimationFrame(rafRef.current);\n    };\n  }, []);\n\n  const gradientDir = gradientDirection === \"vertical\" ? \"180deg\" : gradientDirection === \"diagonal\" ? \"135deg\" : \"90deg\";\n\n  const sharedTextProps: React.CSSProperties = {\n    fontSize: computedFontSize,\n    fontWeight,\n    fontFamily,\n    letterSpacing: `${letterSpacing}px`,\n    lineHeight,\n    whiteSpace: \"pre-line\",\n    textAlign: \"center\",\n    userSelect: \"none\",\n    pointerEvents: \"none\",\n  };\n\n  const mainTextStyle: React.CSSProperties = {\n    ...sharedTextProps,\n    display: \"block\",\n    position: \"relative\",\n    ...(useGradient\n      ? {\n          background: gradientDirection === \"radial\" ? `radial-gradient(circle, ${textColor}, ${gradientColorTo})` : `linear-gradient(${gradientDir}, ${textColor}, ${gradientColorTo})`,\n          WebkitBackgroundClip: \"text\",\n          WebkitTextFillColor: \"transparent\",\n          backgroundClip: \"text\",\n          color: \"transparent\",\n        }\n      : { color: textColor }),\n  };\n\n  return (\n    <div\n      ref={containerRef}\n      className={cn(\"relative flex h-full w-full items-center justify-center overflow-hidden\", className)}\n      style={{ backgroundColor, ...style }}\n      onPointerMove={(e) => {\n        const r = containerRef.current!.getBoundingClientRect();\n        mouseRef.current = { x: e.clientX - r.left, y: e.clientY - r.top, over: true };\n      }}\n      onPointerEnter={() => {\n        mouseRef.current = { ...mouseRef.current, over: true };\n      }}\n      onPointerLeave={() => {\n        mouseRef.current = { x: -9999, y: -9999, over: false };\n      }}\n      {...props}\n    >\n      {/* 3D scene — all transforms applied here */}\n      <div ref={sceneRef} className=\"relative flex h-full w-full items-center justify-center [transform-style:preserve-3d] [will-change:transform]\">\n        <span style={mainTextStyle}>{text}</span>\n      </div>\n\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}