{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pointer-surface",
  "type": "registry:ui",
  "title": "Pointer Surface",
  "description": "A surface that answers the pointer: a soft light that follows it across a card, a slight tilt toward it, or both. It is the feel of picking a card up off a table, for a grid of choices a reader is weighing (plans, sessions, topics), not for every box on a…",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "decorative",
    "effect"
  ],
  "dependencies": [],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json",
    "https://ds.interlace.tools/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/effects/pointer-surface.tsx",
      "target": "components/ui/effects/pointer-surface.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/pointer-surface v1.1.0 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/pointer-surface\n// What changed since: https://ds.interlace.tools/c/pointer-surface#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — PointerSurface\n *\n * A surface that answers the pointer: a soft light that follows it across a\n * card, a slight tilt toward it, or both. It is the feel of picking a card up\n * off a table, for a grid of choices a reader is weighing (plans, sessions,\n * topics), not for every box on a page.\n *\n * ## Content first\n *\n * The children render as they are, in the server HTML. The light is a\n * separate `aria-hidden` wash over the content, faint enough to leave text\n * contrast alone, that never takes the pointer, so links and buttons inside work as usual and nothing is read\n * twice. The tilt is a transform on the surface itself and moves no text in\n * the reading order.\n *\n * ## Motion\n *\n * Only on a device with a fine pointer that can hover, and never under\n * `prefers-reduced-motion: reduce`: a touch screen or a reader who asked for\n * less motion gets a still surface. The pointer position is written to two\n * CSS variables (`--pointer-x`, `--pointer-y`) and the light and tilt are\n * computed from them in CSS, so a move costs one style write and no React\n * render. The tilt eases back to flat when the pointer leaves. Keyboard focus\n * inside lights the surface from its centre, so a keyboard reader sees the\n * same lift.\n *\n * ## Tokens\n *\n * The light is `--primary` mixed toward transparent; set `--pointer-light`\n * to retune it. The tilt is `max` degrees at the edge (default 4).\n *\n * ## Composition\n *\n *   PointerSurface                      (div — data-slot=\"pointer-surface\", data-effect, data-active)\n *     ├─ light                          (aria-hidden, pointer-events-none — data-slot=\"pointer-surface-light\")\n *     └─ children\n *\n * | Rule | Concept                 | Where in this file                                   |\n * | ---- | ----------------------- | ---------------------------------------------------- |\n * | R4   | Extends native el       | `div` props                                          |\n * | R6   | data-slot per part      | pointer-surface / -light                             |\n * | R7   | cn + ...rest            | `cn(…, className)` + `{...props}`                    |\n * | R8   | Enums, not booleans     | `effect`                                             |\n * | R19  | Tokens only             | `--primary`, `--duration-*`, `--ease-*`              |\n * | R25  | Client component        | pointer tracking                                     |\n * | R26  | A11y                    | decorative layer hidden; focus lights it too         |\n */\n\nimport { cn } from '@/lib/utils';\nimport { useReducedMotion } from '@/hooks/use-reduced-motion';\n\nexport type PointerSurfaceEffect = 'light' | 'tilt' | 'both';\n\nexport interface PointerSurfaceProps extends React.ComponentPropsWithoutRef<'div'> {\n  /** What follows the pointer: a soft `light`, a slight `tilt`, or `both`. @default 'light' */\n  effect?: PointerSurfaceEffect;\n  /** The tilt at the edge of the surface, in degrees. Kept small on purpose. @default 4 */\n  max?: number;\n}\n\nconst FINE_POINTER = '(hover: hover) and (pointer: fine)';\n\nexport function PointerSurface({\n  effect = 'light',\n  max = 4,\n  className,\n  style,\n  children,\n  onPointerMove,\n  onPointerLeave,\n  onFocus,\n  onBlur,\n  ...props\n}: PointerSurfaceProps) {\n  const reduced = useReducedMotion();\n  const [fine, setFine] = React.useState(false);\n  const [active, setActive] = React.useState(false);\n  const ref = React.useRef<HTMLDivElement>(null);\n\n  React.useEffect(() => {\n    if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return;\n    const query = window.matchMedia(FINE_POINTER);\n    const update = () => setFine(query.matches);\n    update();\n    query.addEventListener?.('change', update);\n    return () => query.removeEventListener?.('change', update);\n  }, []);\n\n  const live = fine && !reduced;\n  const light = effect !== 'tilt';\n  const tilt = effect !== 'light';\n\n  const place = (x: number, y: number) => {\n    const el = ref.current;\n    if (!el) return;\n    el.style.setProperty('--pointer-x', `${x}`);\n    el.style.setProperty('--pointer-y', `${y}`);\n  };\n\n  const handleMove = (event: React.PointerEvent<HTMLDivElement>) => {\n    onPointerMove?.(event);\n    if (!live || event.pointerType === 'touch') return;\n    const rect = event.currentTarget.getBoundingClientRect();\n    if (rect.width === 0 || rect.height === 0) return;\n    place((event.clientX - rect.left) / rect.width, (event.clientY - rect.top) / rect.height);\n    if (!active) setActive(true);\n  };\n\n  const handleLeave = (event: React.PointerEvent<HTMLDivElement>) => {\n    onPointerLeave?.(event);\n    place(0.5, 0.5);\n    setActive(false);\n  };\n\n  const handleFocus = (event: React.FocusEvent<HTMLDivElement>) => {\n    onFocus?.(event);\n    if (!live) return;\n    place(0.5, 0.5);\n    setActive(true);\n  };\n\n  const handleBlur = (event: React.FocusEvent<HTMLDivElement>) => {\n    onBlur?.(event);\n    if (!event.currentTarget.contains(event.relatedTarget as Node | null)) setActive(false);\n  };\n\n  return (\n    <div\n      ref={ref}\n      data-slot=\"pointer-surface\"\n      data-effect={effect}\n      data-active={live && active ? '' : undefined}\n      onPointerMove={handleMove}\n      onPointerLeave={handleLeave}\n      onFocus={handleFocus}\n      onBlur={handleBlur}\n      style={{ '--pointer-x': 0.5, '--pointer-y': 0.5, '--pointer-max': `${max}deg`, ...style } as React.CSSProperties}\n      className={cn(\n        'group/pointer relative isolate',\n        tilt &&\n          live &&\n          'transition-transform duration-(--duration-slow) ease-(--ease-enter) [transform:perspective(60rem)_rotateX(0deg)_rotateY(0deg)] data-[active]:[transform:perspective(60rem)_rotateX(calc((0.5_-_var(--pointer-y))*var(--pointer-max)*2))_rotateY(calc((var(--pointer-x)_-_0.5)*var(--pointer-max)*2))] data-[active]:duration-(--duration-fast)',\n        className,\n      )}\n      {...props}\n    >\n      {light && live ? (\n        <span\n          aria-hidden=\"true\"\n          data-slot=\"pointer-surface-light\"\n          className=\"pointer-events-none absolute inset-0 z-raised rounded-[inherit] opacity-0 transition-opacity duration-(--duration-medium) ease-(--ease-move) [--pointer-light:color-mix(in_oklch,var(--primary)_10%,transparent)] [background:radial-gradient(28rem_circle_at_calc(var(--pointer-x)*100%)_calc(var(--pointer-y)*100%),var(--pointer-light),transparent_60%)] group-data-[active]/pointer:opacity-100\"\n        />\n      ) : null}\n      {children}\n    </div>\n  );\n}\n"
    }
  ],
  "meta": {
    "tier": "effect",
    "client": true,
    "minViewport": null,
    "loading": false,
    "version": "1.1.0",
    "since": "2.0.0"
  },
  "docs": "## @interlace/pointer-surface\n\nInstalled to `components/ui/effects/pointer-surface.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/effects/pointer-surface';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/pointer-surface\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
