{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "extruded-depth-text",
  "title": "Extruded Depth Text",
  "description": "Letters with a solid 3D block behind them that leans away from the pointer, or turns slowly by itself, built entirely from text shadows.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/extruded-depth-text/extruded-depth-text.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ExtrudedDepthTextProps extends Omit<\n  React.ComponentPropsWithoutRef<\"div\">,\n  \"children\"\n> {\n  text?: string;\n  /** Layers in the block behind the letters. */\n  depth?: number;\n  /** Colour of the block nearest the letters. */\n  near?: string;\n  /** Colour of the block at the back. */\n  far?: string;\n  /** The block keeps turning slowly when nothing is steering it. */\n  idle?: boolean;\n}\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\n/** The idle turn repeats every four seconds. */\nconst CYCLE = 4000;\n/** Each layer sits this far behind the last, as a share of the lean. */\nconst STEP = 0.016;\n\nfunction mix(a: string, b: string, t: number) {\n  const channels = (hex: string) =>\n    [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16));\n  const [x, y] = [channels(a), channels(b)];\n  return `rgb(${x.map((v, i) => Math.round(v + (y[i] - v) * t)).join(\",\")})`;\n}\n\nexport function ExtrudedDepthText({\n  text = \"DEPTH\",\n  depth = 18,\n  near = \"#5E6AD2\",\n  far = \"#14162B\",\n  idle = true,\n  className,\n  style,\n  ...props\n}: ExtrudedDepthTextProps) {\n  const reduce = useReducedMotion();\n  const ref = React.useRef<HTMLDivElement>(null);\n  const aim = React.useRef<{ x: number; y: number } | null>(null);\n  const shades = React.useMemo(\n    () =>\n      Array.from({ length: depth }, (_, i) =>\n        mix(near, far, i / Math.max(1, depth - 1)),\n      ),\n    [depth, near, far],\n  );\n\n  // The block is one stack of text shadows, rebuilt each frame along the direction it should lean.\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const paint = (x: number, y: number) => {\n      el.style.textShadow = shades\n        .map(\n          (shade, i) =>\n            `${(x * (i + 1) * STEP).toFixed(4)}em ${(y * (i + 1) * STEP).toFixed(4)}em 0 ${shade}`,\n        )\n        .join(\",\");\n    };\n    if (reduce) {\n      paint(0.7, 0.7);\n      return;\n    }\n    let raf = 0;\n    let x = 0.7;\n    let y = 0.7;\n    const frame = (now: number) => {\n      const turn = ((now % CYCLE) / CYCLE) * Math.PI * 2;\n      const steer = aim.current;\n      const tx = steer ? steer.x : idle ? Math.cos(turn) * 0.8 : 0.7;\n      const ty = steer ? steer.y : idle ? 0.55 + Math.sin(turn) * 0.35 : 0.7;\n      x += (tx - x) * 0.09;\n      y += (ty - y) * 0.09;\n      paint(x, y);\n      raf = requestAnimationFrame(frame);\n    };\n    const io = new IntersectionObserver(([entry]) => {\n      cancelAnimationFrame(raf);\n      if (entry.isIntersecting) raf = requestAnimationFrame(frame);\n    });\n    io.observe(el);\n    return () => {\n      io.disconnect();\n      cancelAnimationFrame(raf);\n    };\n  }, [reduce, shades, idle]);\n\n  return (\n    <div\n      ref={ref}\n      className={className}\n      style={style}\n      onPointerMove={(e) => {\n        if (e.pointerType !== \"mouse\") return;\n        const r = e.currentTarget.getBoundingClientRect();\n        aim.current = {\n          x: -((e.clientX - r.left) / r.width - 0.5) * 2,\n          y: -((e.clientY - r.top) / r.height - 0.5) * 2,\n        };\n      }}\n      onPointerLeave={() => {\n        aim.current = null;\n      }}\n      {...props}\n    >\n      {text}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}