{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tilt-card",
  "type": "registry:component",
  "title": "Tilt Card",
  "description": "A card that leans towards the pointer, with layers inside it that move by their depth.",
  "dependencies": [
    "@base-ui/react",
    "tailwind-variants"
  ],
  "registryDependencies": [],
  "cssVars": {
    "light": {
      "success": "oklch(0.696 0.17 162.48)",
      "warning": "oklch(0.769 0.188 70.08)",
      "info": "oklch(0.623 0.214 259.815)"
    },
    "dark": {
      "success": "oklch(0.696 0.17 162.48)",
      "warning": "oklch(0.769 0.188 70.08)",
      "info": "oklch(0.623 0.214 259.815)"
    }
  },
  "files": [
    {
      "path": "components/panelui/tilt-card.tsx",
      "type": "registry:component",
      "target": "@components/panelui/tilt-card.tsx",
      "content": "'use client';\n\n/**\n * TiltCard — a card that leans towards the pointer, with layers inside it\n * that move by how near they are.\n *\n * ```tsx\n * <TiltCard>\n *   <TiltCard.Layer depth={24}>…a figure…</TiltCard.Layer>\n *   <TiltCard.Layer depth={8}>\n *     <TiltCard.Title>Versions</TiltCard.Title>\n *     <TiltCard.Description>Every save is kept.</TiltCard.Description>\n *   </TiltCard.Layer>\n * </TiltCard>\n * ```\n *\n * ## The card turns on the pointer\n *\n * The card is tipped a few degrees towards wherever the pointer is on it, as\n * a card held in the hand is tipped towards the eye, and a patch of light\n * sits under the pointer. When the pointer leaves, it settles back level.\n *\n * ## Layers give it depth\n *\n * A `TiltCard.Layer` is lifted off the card by its `depth`. As the card tips,\n * a layer further out moves further, which is the whole of what makes a flat\n * drawing read as a thing with a front and a back. Without layers the card\n * still tips; with them there is something to look round.\n *\n * ## It is decoration\n *\n * Nothing is said by the tilt, so nothing is lost without it: it does not\n * follow a finger, and it holds still for anyone who has asked their system\n * for reduced motion. Whatever the card says is in its contents.\n */\nimport { useRef, type ComponentProps, type PointerEvent as ReactPointerEvent } from 'react';\nimport { tv } from 'tailwind-variants';\nimport { mergeProps } from '@base-ui/react/merge-props';\nimport { useRender } from '@base-ui/react/use-render';\nimport type { ElementType as RenderElementType } from 'react';\n\n/** Draws a part as another element, or composes it with a component: `render={<a href=\"/\" />}`. */\ntype RenderProp<Tag extends RenderElementType> = { render?: useRender.ComponentProps<Tag>['render'] };\n\n/** Which of the theme's roles the light under the pointer is drawn in. */\nexport type TiltCardColor = 'primary' | 'info' | 'success' | 'warning' | 'destructive';\n\nconst tiltCardVariants = tv({\n  slots: {\n    // The eye's distance from the card. Nearer and the lean would be a lurch.\n    root: 'group/tilt relative [perspective:900px]',\n    /*\n     * The lean is two variables the pointer sets. They move at once while the\n     * pointer is on the card, and ease back when it has gone, so the card\n     * follows a hand exactly and then settles on its own.\n     */\n    card: 'relative overflow-hidden rounded-3xl border bg-card text-card-foreground shadow-sm transition-[transform,box-shadow,border-color] duration-500 ease-out [transform-style:preserve-3d] [transform:rotateX(var(--pu-rx,0deg))_rotateY(var(--pu-ry,0deg))] group-data-[tilting]/tilt:shadow-xl group-data-[tilting]/tilt:duration-100 motion-reduce:transition-none motion-reduce:[transform:none]',\n    // The light is the card's colour, soft and wide, centred on the pointer.\n    glare:\n      'pointer-events-none absolute inset-0 rounded-[inherit] bg-[radial-gradient(18rem_circle_at_var(--pu-gx,50%)_var(--pu-gy,50%),color-mix(in_oklab,var(--pu-color)_16%,transparent),transparent_70%)] opacity-0 transition-opacity duration-300 group-data-[tilting]/tilt:opacity-100',\n    title: 'text-base font-semibold',\n    description: 'text-sm text-muted-foreground',\n    layer:\n      'transition-transform duration-500 ease-out [transform:translate3d(calc(var(--pu-px,0)*var(--pu-depth)*1px),calc(var(--pu-py,0)*var(--pu-depth)*1px),calc(var(--pu-depth)*1px))] group-data-[tilting]/tilt:duration-100 motion-reduce:[transform:none]',\n  },\n  variants: {\n    color: {\n      primary: { card: '[--pu-color:var(--primary)]' },\n      info: { card: '[--pu-color:var(--info)]' },\n      success: { card: '[--pu-color:var(--success)]' },\n      warning: { card: '[--pu-color:var(--warning)]' },\n      destructive: { card: '[--pu-color:var(--destructive)]' },\n    },\n  },\n  defaultVariants: { color: 'primary' },\n});\n\nexport interface TiltCardProps extends Omit<ComponentProps<'div'>, 'color'> {\n  /** The furthest the card leans, in degrees. */\n  tilt?: number;\n  /** Which of the theme's roles the light under the pointer is drawn in. */\n  color?: TiltCardColor;\n  /** Set to `false` for a card with no light under the pointer. */\n  glare?: boolean;\n  /** Extra classes for the card itself. `className` goes on the box round it. */\n  cardClassName?: string;\n}\n\nfunction TiltCardRoot({\n  tilt = 8,\n  color = 'primary',\n  glare = true,\n  className,\n  cardClassName,\n  children,\n  onPointerMove,\n  onPointerLeave,\n  render,\n  ...props\n}: TiltCardProps & RenderProp<'div'>) {\n  const slots = tiltCardVariants({ color });\n  const root = useRef<HTMLDivElement>(null);\n  const frame = useRef(0);\n\n  const lean = (event: ReactPointerEvent<HTMLDivElement>) => {\n    onPointerMove?.(event);\n    // A finger has no hover to end the lean, and would cover it anyway.\n    if (event.pointerType === 'touch') return;\n    if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;\n    const node = root.current;\n    if (!node) return;\n    const { clientX, clientY } = event;\n    cancelAnimationFrame(frame.current);\n    frame.current = requestAnimationFrame(() => {\n      const box = node.getBoundingClientRect();\n      // Where the pointer is on the card, from -1 at one edge to 1 at the other.\n      const x = ((clientX - box.left) / box.width) * 2 - 1;\n      const y = ((clientY - box.top) / box.height) * 2 - 1;\n      node.dataset.tilting = '';\n      // Towards the pointer: the near edge comes forward.\n      node.style.setProperty('--pu-rx', `${(-y * tilt).toFixed(2)}deg`);\n      node.style.setProperty('--pu-ry', `${(x * tilt).toFixed(2)}deg`);\n      node.style.setProperty('--pu-px', x.toFixed(3));\n      node.style.setProperty('--pu-py', y.toFixed(3));\n      node.style.setProperty('--pu-gx', `${(((x + 1) / 2) * 100).toFixed(1)}%`);\n      node.style.setProperty('--pu-gy', `${(((y + 1) / 2) * 100).toFixed(1)}%`);\n    });\n  };\n\n  const settle = (event: ReactPointerEvent<HTMLDivElement>) => {\n    onPointerLeave?.(event);\n    cancelAnimationFrame(frame.current);\n    const node = root.current;\n    if (!node) return;\n    delete node.dataset.tilting;\n    for (const name of ['--pu-rx', '--pu-ry', '--pu-px', '--pu-py']) node.style.removeProperty(name);\n  };\n\n  return useRender({\n    defaultTagName: 'div',\n    render,\n    props: mergeProps(\n      {\n        ref: root,\n        className: slots.root({ className }),\n        onPointerMove: lean,\n        onPointerLeave: settle,\n        children: (\n          <>\n            <div className={slots.card({ className: cardClassName })}>\n              {children}\n              {glare ? <span aria-hidden=\"true\" className={slots.glare()} /> : null}\n            </div>\n          </>\n        ),\n      },\n      props\n    ),\n  });\n}\nTiltCardRoot.displayName = 'TiltCard';\n\nexport interface TiltCardLayerProps extends ComponentProps<'div'> {\n  /** How far off the card it is lifted, in pixels. Further out moves further as the card leans. */\n  depth?: number;\n}\n\n/** Something lifted off the card, which moves against it as the card leans. */\nfunction TiltCardLayer({ depth = 16, className, style, render, ...props }: TiltCardLayerProps & RenderProp<'div'>) {\n  return useRender({\n    defaultTagName: 'div',\n    render,\n    props: mergeProps(\n      { className: tiltCardVariants().layer({ className }), style: { ['--pu-depth' as string]: depth, ...style } },\n      props\n    ),\n  });\n}\nTiltCardLayer.displayName = 'TiltCard.Layer';\n\nexport interface TiltCardTitleProps extends ComponentProps<'h3'> {\n  /** The heading level, to fit the page around the card. Default `h3`. */\n  as?: 'h2' | 'h3' | 'h4' | 'p';\n}\n\n/** What the card is about. */\nfunction TiltCardTitle({ as: Tag = 'h3', className, ...props }: TiltCardTitleProps) {\n  return <Tag data-slot=\"tilt-card-title\" className={tiltCardVariants().title({ className })} {...props} />;\n}\nTiltCardTitle.displayName = 'TiltCard.Title';\n\nexport interface TiltCardDescriptionProps extends ComponentProps<'p'> {}\n\n/** A line or two of body text, under the title. */\nfunction TiltCardDescription({ className, render, ...props }: TiltCardDescriptionProps & RenderProp<'p'>) {\n  return useRender({\n    defaultTagName: 'p',\n    render,\n    props: mergeProps(\n      { 'data-slot': 'tilt-card-description', className: tiltCardVariants().description({ className }) },\n      props\n    ),\n  });\n}\nTiltCardDescription.displayName = 'TiltCard.Description';\n\nexport const TiltCard = Object.assign(TiltCardRoot, {\n  Layer: TiltCardLayer,\n  Title: TiltCardTitle,\n  Description: TiltCardDescription,\n});\n\n/* By name as well, for a Server Component, which cannot dot into a client\n   module. */\nexport { TiltCardLayer, TiltCardTitle, TiltCardDescription };\n"
    }
  ]
}
