{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-3d-extrude",
  "type": "registry:component",
  "title": "Text 3D Extrude",
  "description": "Text built from a stack of shifted layers that forms a solid extrusion and tilts with the pointer.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "text",
    "text",
    "3d",
    "extrude",
    "tilt",
    "pointer",
    "depth"
  ],
  "docs": "https://hyperblur.dev/effects/text-3d-extrude",
  "files": [
    {
      "path": "registry/hyperblur/text-3d-extrude.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/text-3d-extrude.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface Text3dExtrudeProps extends React.HTMLAttributes<HTMLSpanElement> {\n  text: string;\n  depth?: number;\n  layers?: number;\n  tilt?: number;\n  color?: string;\n  sideColor?: string;\n  shadow?: boolean;\n}\n\nconst css = `\n.hb-qdb {\n  position: relative;\n  display: inline-block;\n  max-width: 100%;\n  padding: 0.35em 0.5em;\n  line-height: 1.05;\n  perspective: 760px;\n  touch-action: pan-y;\n  cursor: default;\n  font-family: inherit;\n  box-sizing: border-box;\n}\n.hb-qdb *, .hb-qdb *::before, .hb-qdb *::after { box-sizing: border-box; }\n.hb-qdb-stage {\n  position: relative;\n  display: block;\n  transform-style: preserve-3d;\n  transform-origin: 50% 50% calc(var(--hb-qdb-depth) * -0.5);\n  transform: rotateX(var(--hb-qdb-rx)) rotateY(var(--hb-qdb-ry));\n}\n.hb-qdb-f { position: relative; display: block; color: var(--hb-qdb-front); transform: translateZ(0.5px); }\n.hb-qdb-l {\n  position: absolute;\n  inset: 0;\n  display: block;\n  pointer-events: none;\n  user-select: none;\n}\n.hb-qdb-s { filter: blur(0.14em); opacity: 0.4; color: #000; }\n`;\n\nexport function Text3dExtrude({\n  text,\n  depth = 30,\n  layers = 16,\n  tilt = 28,\n  color = \"#ffffff\",\n  sideColor = \"#2f7bff\",\n  shadow = true,\n  className = \"\",\n  style,\n  ...rest\n}: Text3dExtrudeProps) {\n  const ref = React.useRef<HTMLSpanElement>(null);\n  const count = Math.max(2, Math.round(layers));\n  const step = depth / count;\n\n  React.useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    const set = (rx: number, ry: number) => {\n      root.style.setProperty(\"--hb-qdb-rx\", `${rx.toFixed(2)}deg`);\n      root.style.setProperty(\"--hb-qdb-ry\", `${ry.toFixed(2)}deg`);\n    };\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) {\n      set(-tilt * 0.3, tilt * 0.5);\n      return;\n    }\n\n    const pointer = { x: 0, y: 0, inside: false };\n    const start = performance.now();\n    let blend = 0;\n    let rx = 0;\n    let ry = 0;\n    let visible = true;\n    let raf = 0;\n\n    const tick = (now: number) => {\n      raf = 0;\n      if (!visible) return;\n      const box = root.getBoundingClientRect();\n      const t = (now - start) / 1000;\n      blend += ((pointer.inside ? 1 : 0) - blend) * 0.1;\n      const nx = Math.max(-1, Math.min(1, (pointer.x - box.left - box.width / 2) / (box.width / 2 || 1)));\n      const ny = Math.max(-1, Math.min(1, (pointer.y - box.top - box.height / 2) / (box.height / 2 || 1)));\n      const idleY = Math.sin(t * 0.8) * 0.75;\n      const idleX = Math.sin(t * 0.55 + 1.2) * 0.35;\n      const targetY = (idleY + (nx - idleY) * blend) * tilt;\n      const targetX = (-(idleX + (ny - idleX) * blend)) * tilt * 0.7;\n      rx += (targetX - rx) * 0.14;\n      ry += (targetY - ry) * 0.14;\n      set(rx, ry);\n      raf = requestAnimationFrame(tick);\n    };\n\n    const kick = () => {\n      if (!raf && visible) raf = requestAnimationFrame(tick);\n    };\n    const move = (e: PointerEvent) => {\n      pointer.x = e.clientX;\n      pointer.y = e.clientY;\n      pointer.inside = true;\n    };\n    const leave = () => {\n      pointer.inside = false;\n    };\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      kick();\n    });\n    io.observe(root);\n    root.addEventListener(\"pointerenter\", move);\n    root.addEventListener(\"pointermove\", move);\n    root.addEventListener(\"pointerleave\", leave);\n    root.addEventListener(\"pointercancel\", leave);\n    kick();\n    return () => {\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      root.removeEventListener(\"pointerenter\", move);\n      root.removeEventListener(\"pointermove\", move);\n      root.removeEventListener(\"pointerleave\", leave);\n      root.removeEventListener(\"pointercancel\", leave);\n    };\n  }, [tilt]);\n\n  const vars = {\n    \"--hb-qdb-front\": color,\n    \"--hb-qdb-depth\": `${depth}px`,\n    \"--hb-qdb-rx\": \"0deg\",\n    \"--hb-qdb-ry\": \"0deg\",\n    ...style,\n  } as React.CSSProperties;\n\n  const stack = Array.from({ length: count }, (_, k) => {\n    const i = count - k;\n    const shade = ((i / count) * 68).toFixed(1);\n    return {\n      key: i,\n      style: {\n        transform: `translateZ(${(-i * step).toFixed(2)}px)`,\n        color: `color-mix(in srgb, ${sideColor} ${(100 - Number(shade)).toFixed(1)}%, #000 ${shade}%)`,\n      } as React.CSSProperties,\n    };\n  });\n\n  return (\n    <span ref={ref} className={`hb-qdb ${className}`} style={vars} {...rest}>\n      <style href=\"hb-text-3d-extrude\" precedence=\"default\">{css}</style>\n      <span className=\"hb-qdb-stage\">\n        {shadow ? (\n          <span\n            className=\"hb-qdb-l hb-qdb-s\"\n            aria-hidden=\"true\"\n            style={{ transform: `translateZ(${(-depth - 16).toFixed(1)}px)` }}\n          >\n            {text}\n          </span>\n        ) : null}\n        {stack.map((layer) => (\n          <span key={layer.key} className=\"hb-qdb-l\" aria-hidden=\"true\" style={layer.style}>\n            {text}\n          </span>\n        ))}\n        <span className=\"hb-qdb-f\">{text}</span>\n      </span>\n    </span>\n  );\n}\n"
    }
  ]
}