{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"tilt-card","type":"registry:block","title":"Tilt card","description":"A dashboard card that tilts in 3D toward the pointer, with a moving light reflection and layered content that gains depth.","dependencies":["motion","lucide-react"],"registryDependencies":["utils"],"files":[{"path":"registry/prequel/tilt-card/tilt-card.tsx","type":"registry:component","content":"\"use client\";\n\nimport {\n  useRef,\n  type PointerEvent as ReactPointerEvent,\n  type ReactNode,\n} from \"react\";\nimport {\n  motion,\n  useInView,\n  useMotionTemplate,\n  useMotionValue,\n  useReducedMotion,\n  useSpring,\n  useTransform,\n} from \"motion/react\";\nimport { ArrowUpRight } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nconst EASE: [number, number, number, number] = [0.22, 1, 0.36, 1];\n\nconst SERIES = [\n  38, 41, 39, 45, 44, 49, 52, 48, 55, 58, 57, 63, 61, 68, 72, 70, 74, 79,\n];\n\nfunction buildSeries(values: number[], width: number, height: number, pad: number) {\n  const min = Math.min(...values);\n  const max = Math.max(...values);\n  const span = max - min || 1;\n  const step = (width - pad * 2) / (values.length - 1);\n\n  const points = values.map((value, index) => ({\n    x: pad + index * step,\n    y: pad + (height - pad * 2) * (1 - (value - min) / span),\n  }));\n\n  const line = points\n    .map((point, index) => `${index === 0 ? \"M\" : \"L\"}${point.x.toFixed(2)},${point.y.toFixed(2)}`)\n    .join(\" \");\n\n  return {\n    line,\n    area: `${line} L${(width - pad).toFixed(2)},${(height - pad).toFixed(2)} L${pad},${(\n      height - pad\n    ).toFixed(2)} Z`,\n    last: points[points.length - 1],\n  };\n}\n\nconst CHART = buildSeries(SERIES, 220, 56, 4);\n\nfunction clamp(value: number) {\n  return Math.min(1, Math.max(0, value));\n}\n\n/* ------------------------------------------------------------------ */\n/* types                                                               */\n/* ------------------------------------------------------------------ */\n\nexport type TiltCardProps = {\n  className?: string;\n  /** Replaces the default demo body. */\n  children?: ReactNode;\n  /** Maximum rotation on each axis, in degrees. Defaults to 9. */\n  maxTilt?: number;\n  /** Perspective of the 3D stage, in pixels. Defaults to 900. */\n  perspective?: number;\n};\n\n/* ------------------------------------------------------------------ */\n/* block                                                               */\n/* ------------------------------------------------------------------ */\n\nexport function TiltCard({\n  className,\n  children,\n  maxTilt = 9,\n  perspective = 900,\n}: TiltCardProps) {\n  const reduce = Boolean(useReducedMotion());\n  const stageRef = useRef<HTMLDivElement>(null);\n  const inView = useInView(stageRef, { once: true, margin: \"-10% 0px\" });\n  const show = inView || reduce;\n\n  /* A normalized pointer position drives both the tilt and the glare.\n     Springs smooth the motion without a single React re-render. */\n  const pointerX = useMotionValue(0.5);\n  const pointerY = useMotionValue(0.5);\n  const smoothX = useSpring(pointerX, { stiffness: 170, damping: 22, mass: 0.6 });\n  const smoothY = useSpring(pointerY, { stiffness: 170, damping: 22, mass: 0.6 });\n\n  const rotateX = useTransform(smoothY, [0, 1], [maxTilt, -maxTilt]);\n  const rotateY = useTransform(smoothX, [0, 1], [-maxTilt, maxTilt]);\n\n  const glareX = useTransform(smoothX, (value) => `${(value * 100).toFixed(1)}%`);\n  const glareY = useTransform(smoothY, (value) => `${(value * 100).toFixed(1)}%`);\n  const glare = useMotionTemplate`radial-gradient(\n    circle 300px at ${glareX} ${glareY},\n    color-mix(in oklab, var(--card-foreground) 14%, transparent),\n    transparent 68%\n  )`;\n\n  const follow = (event: ReactPointerEvent<HTMLDivElement>) => {\n    if (reduce) return;\n    const rect = event.currentTarget.getBoundingClientRect();\n    if (!rect.width || !rect.height) return;\n    pointerX.set(clamp((event.clientX - rect.left) / rect.width));\n    pointerY.set(clamp((event.clientY - rect.top) / rect.height));\n  };\n\n  const reset = () => {\n    if (reduce) return;\n    pointerX.set(0.5);\n    pointerY.set(0.5);\n  };\n\n  return (\n    <motion.div\n      ref={stageRef}\n      initial={reduce ? false : { opacity: 0, y: 18 }}\n      animate={show ? { opacity: 1, y: 0 } : { opacity: 0, y: 18 }}\n      transition={{ duration: 0.6, ease: EASE }}\n      style={{ perspective: `${Math.max(400, perspective)}px` }}\n      className={cn(\"relative [transform-style:preserve-3d]\", className)}\n    >\n      <motion.div\n        onPointerMove={follow}\n        onPointerLeave={reset}\n        onPointerCancel={reset}\n        style={{ rotateX, rotateY, transformStyle: \"preserve-3d\" }}\n        className=\"group relative overflow-hidden rounded-xl border border-border bg-card text-card-foreground [will-change:transform]\"\n      >\n        <div\n          className=\"relative p-5 sm:p-6\"\n          style={{ transform: \"translateZ(26px)\", transformStyle: \"preserve-3d\" }}\n        >\n          {children ?? (\n            <>\n              <div className=\"flex items-start justify-between gap-3\">\n                <div className=\"flex min-w-0 items-center gap-3\">\n                  <div className=\"grid h-9 w-9 flex-none place-items-center rounded-lg border border-border bg-muted font-mono text-[10.5px] font-semibold tracking-tight\">\n                    NW\n                  </div>\n                  <div className=\"min-w-0\">\n                    <h3 className=\"truncate text-[14px] font-semibold tracking-[-0.01em]\">\n                      Northwind Labs\n                    </h3>\n                    <p className=\"mt-0.5 truncate text-[11.5px] text-muted-foreground\">\n                      Production · v2.4.1\n                    </p>\n                  </div>\n                </div>\n\n                <span className=\"inline-flex flex-none items-center gap-1.5 rounded-full bg-muted px-2 py-1 text-[11px] font-medium text-muted-foreground\">\n                  <span className=\"h-1.5 w-1.5 rounded-full bg-success\" />\n                  Healthy\n                </span>\n              </div>\n\n              <div className=\"mt-6 flex items-end justify-between gap-3\">\n                <div className=\"min-w-0\">\n                  <p className=\"text-[11.5px] text-muted-foreground\">Requests today</p>\n                  <p className=\"mt-1 text-[28px] font-semibold leading-none tracking-[-0.03em] tabular-nums\">\n                    1,928,440\n                  </p>\n                </div>\n                <span className=\"inline-flex flex-none items-center gap-0.5 pb-0.5 text-[12px] font-medium tabular-nums text-success\">\n                  <ArrowUpRight className=\"h-3.5 w-3.5\" aria-hidden=\"true\" />\n                  12.4%\n                </span>\n              </div>\n\n              <svg\n                viewBox=\"0 0 220 56\"\n                role=\"img\"\n                aria-label=\"Requests over the last 18 hours, rising from 38 to 79 thousand per minute.\"\n                className=\"mt-4 w-full\"\n              >\n                <line\n                  x1=\"4\"\n                  x2=\"216\"\n                  y1=\"28\"\n                  y2=\"28\"\n                  stroke=\"var(--border)\"\n                  strokeDasharray=\"2 4\"\n                />\n                <motion.path\n                  d={CHART.area}\n                  fill=\"var(--chart-1)\"\n                  initial={false}\n                  animate={{ opacity: show ? 0.07 : 0 }}\n                  transition={{ duration: 0.5, delay: 0.2 }}\n                />\n                <motion.path\n                  d={CHART.line}\n                  fill=\"none\"\n                  stroke=\"var(--chart-1)\"\n                  strokeWidth={2}\n                  strokeLinecap=\"round\"\n                  strokeLinejoin=\"round\"\n                  initial={reduce ? false : { pathLength: 0 }}\n                  animate={{ pathLength: show ? 1 : 0 }}\n                  transition={{ duration: 1, ease: EASE, delay: 0.25 }}\n                />\n                <g>\n                  <circle\n                    cx={CHART.last.x}\n                    cy={CHART.last.y}\n                    r={5}\n                    fill=\"var(--card)\"\n                    stroke=\"var(--chart-1)\"\n                    strokeWidth={2}\n                  />\n                  <circle\n                    cx={CHART.last.x}\n                    cy={CHART.last.y}\n                    r={1.6}\n                    fill=\"var(--chart-1)\"\n                  />\n                  <circle\n                    cx={CHART.last.x - 1.1}\n                    cy={CHART.last.y - 1.1}\n                    r={0.8}\n                    fill=\"var(--card)\"\n                  />\n                </g>\n              </svg>\n\n              <dl className=\"mt-4 grid grid-cols-3 gap-3 border-t border-border pt-4\">\n                <div className=\"min-w-0\">\n                  <dt className=\"text-[11px] text-muted-foreground\">p95</dt>\n                  <dd className=\"mt-0.5 text-[13px] font-medium tabular-nums\">48 ms</dd>\n                </div>\n                <div className=\"min-w-0\">\n                  <dt className=\"text-[11px] text-muted-foreground\">Errors</dt>\n                  <dd className=\"mt-0.5 text-[13px] font-medium tabular-nums\">0.03%</dd>\n                </div>\n                <div className=\"min-w-0\">\n                  <dt className=\"text-[11px] text-muted-foreground\">Uptime</dt>\n                  <dd className=\"mt-0.5 text-[13px] font-medium tabular-nums\">99.97%</dd>\n                </div>\n              </dl>\n            </>\n          )}\n        </div>\n\n        <motion.span\n          aria-hidden=\"true\"\n          style={{ background: glare }}\n          className=\"pointer-events-none absolute inset-0 z-20 rounded-[inherit] opacity-0 transition-opacity duration-300 group-hover:opacity-100 group-focus-within:opacity-100 motion-reduce:transition-none\"\n        />\n      </motion.div>\n    </motion.div>\n  );\n}\n\n/* The default card on its own, handy for previews. */\nexport function TiltCardDemo() {\n  return <TiltCard />;\n}\n\nexport default TiltCard;\n"}]}