{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"lightfield-surface","type":"registry:component","title":"Lightfield Surface","description":"A small amount of physical light, not a glow.","dependencies":[],"categories":["media","pointer","light","product","tilt"],"files":[{"path":"components/lab/lightfield-surface/lightfield-surface.tsx","target":"components/lab/lightfield-surface/lightfield-surface.tsx","type":"registry:component","content":"\"use client\";\n\nimport {\n  useEffect,\n  useRef,\n  type CSSProperties,\n  type PointerEvent as ReactPointerEvent,\n  type ReactNode,\n} from \"react\";\nimport \"./lightfield-surface.css\";\n\nexport type LightfieldSurfaceProps = {\n  children: ReactNode;\n  /** Overall highlight strength, 0–1. */\n  intensity?: number;\n  /** Maximum tilt in degrees. Keep this small. */\n  tilt?: number;\n  /** Highlight radius as a percentage of the surface. */\n  highlight?: number;\n  finish?: \"matte\" | \"satin\" | \"gloss\";\n  /** Make the surface itself a tab stop with a visible focus treatment. */\n  focusable?: boolean;\n  /** Stop responding to the pointer without changing the layout. */\n  disabled?: boolean;\n  className?: string;\n  style?: CSSProperties;\n};\n\nfunction reducedMotion() {\n  return (\n    typeof window !== \"undefined\" &&\n    window.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches\n  );\n}\n\n/**\n * LIGHTFIELD SURFACE\n *\n * A card that catches light. Pointer movement updates a damped target\n * at most once per frame; the loop stops as soon as the surface has\n * settled, so a page of cards at rest runs nothing. Coarse pointers and\n * reduced-motion users get the static finish. The tilt is clamped and\n * intentionally small: depth, not a funhouse mirror.\n */\nexport function LightfieldSurface({\n  children,\n  intensity = 0.5,\n  tilt = 3,\n  highlight = 52,\n  finish = \"satin\",\n  focusable = false,\n  disabled = false,\n  className,\n  style,\n}: LightfieldSurfaceProps) {\n  const rootRef = useRef<HTMLDivElement>(null);\n  const target = useRef({ x: 50, y: 22, rx: 0, ry: 0 });\n  const current = useRef({ x: 50, y: 22, rx: 0, ry: 0 });\n  const frame = useRef<number | null>(null);\n  const fine = useRef(true);\n\n  useEffect(() => {\n    const query = window.matchMedia?.(\"(pointer: fine)\");\n    fine.current = query ? query.matches : true;\n    const update = () => {\n      fine.current = query ? query.matches : true;\n    };\n    query?.addEventListener?.(\"change\", update);\n    return () => query?.removeEventListener?.(\"change\", update);\n  }, []);\n\n  const paint = () => {\n    const node = rootRef.current;\n    if (!node) return;\n    node.style.setProperty(\"--lf-x\", `${current.current.x}%`);\n    node.style.setProperty(\"--lf-y\", `${current.current.y}%`);\n    node.style.setProperty(\"--lf-rx\", `${current.current.rx}deg`);\n    node.style.setProperty(\"--lf-ry\", `${current.current.ry}deg`);\n  };\n\n  const stop = () => {\n    if (frame.current !== null) {\n      window.cancelAnimationFrame(frame.current);\n      frame.current = null;\n    }\n  };\n\n  const run = () => {\n    if (frame.current !== null) return;\n    const tick = () => {\n      frame.current = null;\n      const t = target.current;\n      const c = current.current;\n      const ease = 0.18;\n      c.x += (t.x - c.x) * ease;\n      c.y += (t.y - c.y) * ease;\n      c.rx += (t.rx - c.rx) * ease;\n      c.ry += (t.ry - c.ry) * ease;\n      paint();\n      const settled =\n        Math.abs(t.x - c.x) < 0.05 &&\n        Math.abs(t.y - c.y) < 0.05 &&\n        Math.abs(t.rx - c.rx) < 0.01 &&\n        Math.abs(t.ry - c.ry) < 0.01;\n      if (settled) {\n        c.x = t.x;\n        c.y = t.y;\n        c.rx = t.rx;\n        c.ry = t.ry;\n        paint();\n        return;\n      }\n      frame.current = window.requestAnimationFrame(tick);\n    };\n    frame.current = window.requestAnimationFrame(tick);\n  };\n\n  useEffect(() => stop, []);\n\n  const move = (event: ReactPointerEvent<HTMLDivElement>) => {\n    if (\n      disabled ||\n      event.pointerType === \"touch\" ||\n      !fine.current ||\n      reducedMotion()\n    )\n      return;\n    const node = rootRef.current;\n    if (!node) return;\n    const rect = node.getBoundingClientRect();\n    if (!rect.width || !rect.height) return;\n    const px = (event.clientX - rect.left) / rect.width;\n    const py = (event.clientY - rect.top) / rect.height;\n    target.current = {\n      x: px * 100,\n      y: py * 100,\n      rx: (0.5 - py) * tilt * 2,\n      ry: (px - 0.5) * tilt * 2,\n    };\n    run();\n  };\n\n  const leave = () => {\n    target.current = { x: 50, y: 16, rx: 0, ry: 0 };\n    if (fine.current && !reducedMotion()) run();\n  };\n\n  const onFocus = () => {\n    if (disabled || !fine.current) return;\n    target.current = { x: 30, y: 10, rx: 0, ry: 0 };\n    if (!reducedMotion()) run();\n  };\n\n  const onBlur = () => {\n    if (disabled) return;\n    target.current = { x: 50, y: 16, rx: 0, ry: 0 };\n    if (!reducedMotion()) run();\n  };\n\n  const inline = {\n    ...style,\n    \"--lf-intensity\": Math.max(0, Math.min(1, intensity)),\n    \"--lf-tilt\": `${Math.max(0, Math.min(6, tilt))}deg`,\n    \"--lf-size\": `${Math.max(16, Math.min(100, highlight))}%`,\n  } as CSSProperties;\n\n  return (\n    <div\n      ref={rootRef}\n      className={`lf-root${className ? ` ${className}` : \"\"}`}\n      data-finish={finish}\n      data-disabled={disabled ? \"true\" : \"false\"}\n      data-focusable={focusable ? \"true\" : \"false\"}\n      style={inline}\n      tabIndex={focusable ? 0 : undefined}\n      onPointerMove={move}\n      onPointerLeave={leave}\n      onFocus={onFocus}\n      onBlur={onBlur}\n    >\n      <div className=\"lf-plane\">{children}</div>\n      <span className=\"lf-light\" aria-hidden=\"true\" />\n      <span className=\"lf-edge\" aria-hidden=\"true\" />\n    </div>\n  );\n}\n"},{"path":"components/lab/lightfield-surface/lightfield-surface.css","target":"components/lab/lightfield-surface/lightfield-surface.css","type":"registry:file","content":".lf-root {\n  --lf-x: 50%;\n  --lf-y: 22%;\n  --lf-rx: 0deg;\n  --lf-ry: 0deg;\n  --lf-intensity: 0.5;\n  --lf-tilt: 3deg;\n  --lf-size: 52%;\n  --lf-focus: #d9b98a;\n  position: relative;\n  min-width: 0;\n  border-radius: 14px;\n  perspective: 900px;\n  isolation: isolate;\n  font: inherit;\n  transform-style: preserve-3d;\n}\n\n.lf-plane {\n  position: relative;\n  z-index: 1;\n  height: 100%;\n  overflow: hidden;\n  border-radius: inherit;\n  transform: rotateX(var(--lf-rx)) rotateY(var(--lf-ry));\n  transform-style: preserve-3d;\n  will-change: transform;\n}\n\n.lf-light {\n  position: absolute;\n  inset: 0;\n  z-index: 2;\n  border-radius: inherit;\n  pointer-events: none;\n  background: radial-gradient(\n    circle at var(--lf-x) var(--lf-y),\n    rgba(255, 250, 236, calc(var(--lf-intensity) * 0.42)),\n    rgba(255, 250, 236, calc(var(--lf-intensity) * 0.12)) 32%,\n    transparent var(--lf-size)\n  );\n  mix-blend-mode: screen;\n  opacity: 1;\n  transition: opacity 260ms ease;\n}\n\n.lf-root[data-finish=\"matte\"] .lf-light {\n  background: radial-gradient(\n    circle at var(--lf-x) var(--lf-y),\n    rgba(255, 250, 236, calc(var(--lf-intensity) * 0.16)),\n    transparent var(--lf-size)\n  );\n}\n\n.lf-root[data-finish=\"gloss\"] .lf-light {\n  background:\n    radial-gradient(\n      circle at var(--lf-x) var(--lf-y),\n      rgba(255, 253, 246, calc(var(--lf-intensity) * 0.62)),\n      rgba(255, 253, 246, calc(var(--lf-intensity) * 0.16)) 18%,\n      transparent var(--lf-size)\n    ),\n    linear-gradient(\n      118deg,\n      transparent 28%,\n      rgba(255, 255, 255, calc(var(--lf-intensity) * 0.08)) 44%,\n      transparent 58%\n    );\n}\n\n.lf-edge {\n  position: absolute;\n  inset: 0;\n  z-index: 3;\n  border: 1px solid rgba(255, 255, 255, 0.1);\n  border-radius: inherit;\n  pointer-events: none;\n  background: linear-gradient(\n    145deg,\n    rgba(255, 255, 255, calc(var(--lf-intensity) * 0.14)),\n    transparent 30%\n  );\n  mask: linear-gradient(#000, #000) content-box, linear-gradient(#000, #000);\n  mask-composite: exclude;\n  padding: 1px;\n}\n\n.lf-root:focus-visible {\n  outline: 2px solid var(--lf-focus);\n  outline-offset: 3px;\n}\n\n.lf-root:focus-within .lf-light {\n  opacity: 1;\n}\n\n.lf-root[data-disabled=\"true\"] .lf-light {\n  opacity: 0.35;\n}\n\n.lf-root[data-disabled=\"true\"] .lf-plane {\n  transform: none;\n}\n\n@media (hover: none), (prefers-reduced-motion: reduce) {\n  .lf-plane {\n    transform: none;\n  }\n\n  .lf-light {\n    background: radial-gradient(\n      circle at 50% 16%,\n      rgba(255, 250, 236, calc(var(--lf-intensity) * 0.3)),\n      transparent var(--lf-size)\n    );\n  }\n\n  .lf-root[data-finish=\"gloss\"] .lf-light {\n    background:\n      radial-gradient(\n        circle at 50% 16%,\n        rgba(255, 253, 246, calc(var(--lf-intensity) * 0.5)),\n        transparent var(--lf-size)\n      ),\n      linear-gradient(\n        118deg,\n        transparent 28%,\n        rgba(255, 255, 255, calc(var(--lf-intensity) * 0.06)) 44%,\n        transparent 58%\n      );\n  }\n}\n"}]}