{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "holo-card",
  "title": "Holo card",
  "description": "A surface that tilts toward the pointer in 3D, with a sheen and layers at different depths.",
  "registryDependencies": [
    "https://www.cyberspec.dev/r/cyber.json"
  ],
  "files": [
    {
      "path": "registry/cyber/ui/holo-card.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { fxMoves, onFxChange } from \"@/registry/cyber/lib/fx\"\nimport \"@/registry/cyber/ui/cyber/holo-card.css\"\n\nconst clamp = (value: number) => Math.min(1, Math.max(-1, value))\n\n// A projected surface: whatever it wraps turns to face the pointer, in 3D,\n// and a sheen follows the pointer across it. It adds no frame of its own,\n// so put a Card or a Panel inside.\n//\n// - `stack`: how many ghost layers (up to three) stand behind the card, a\n//   step up and along from it, like the sheets of a projection.\n// - `tilt`: the most the surface turns, in degrees.\n// - Depth: anything inside with `data-depth=\"2\"` (-1 to 3), or wrapped in\n//   <HoloLayer depth>, slides toward the pointer in proportion, so it reads\n//   as floating above the surface; a negative depth sinks behind it.\n//\n// It's decoration over real content. The surface is flat and still for\n// touch, and whenever the FX level says nothing should move; nothing here\n// clips, so focus rings inside show whole, and the sheen and the ghosts\n// never take the pointer or a screen reader's attention.\nfunction HoloCard({\n  stack = 0,\n  tilt = 8,\n  style,\n  children,\n  onPointerMove,\n  onPointerLeave,\n  onPointerCancel,\n  ...props\n}: React.ComponentProps<\"div\"> & {\n  stack?: 0 | 1 | 2 | 3\n  tilt?: number\n}) {\n  const surface = React.useRef<HTMLDivElement>(null)\n  const live = React.useRef<HTMLDivElement | null>(null)\n  const pointer = React.useRef({ x: 0, y: 0 })\n  const frame = React.useRef(0)\n\n  // Back to flat. The stylesheet eases it there.\n  const rest = React.useCallback(() => {\n    cancelAnimationFrame(frame.current)\n    frame.current = 0\n    const root = live.current\n    if (!root) return\n    live.current = null\n    root.removeAttribute(\"data-live\")\n    root.style.removeProperty(\"--holo-x\")\n    root.style.removeProperty(\"--holo-y\")\n  }, [])\n\n  // Effects switched off while the pointer is over it: lie flat now, not\n  // when the pointer next moves.\n  React.useEffect(() => {\n    const unsubscribe = onFxChange((level) => {\n      if (level === \"off\") rest()\n    })\n    return () => {\n      unsubscribe()\n      cancelAnimationFrame(frame.current)\n    }\n  }, [rest])\n\n  function track(event: React.PointerEvent<HTMLDivElement>) {\n    onPointerMove?.(event)\n    if (event.pointerType === \"touch\" || !fxMoves()) return rest()\n    live.current = event.currentTarget\n    pointer.current = { x: event.clientX, y: event.clientY }\n    // One write a frame, however often the pointer reports.\n    if (frame.current) return\n    frame.current = requestAnimationFrame(() => {\n      frame.current = 0\n      const root = live.current\n      const card = surface.current\n      if (!root || !card || !card.offsetWidth || !card.offsetHeight) return\n      // Measured from layout, not from the turned surface, so the tilt\n      // can't feed back into the reading.\n      const box = root.getBoundingClientRect()\n      const x = clamp(((pointer.current.x - box.left - card.offsetLeft) / card.offsetWidth) * 2 - 1)\n      const y = clamp(((pointer.current.y - box.top - card.offsetTop) / card.offsetHeight) * 2 - 1)\n      // Where the pointer is on the surface: -1 at the left or the top, 1\n      // at the right or the bottom. The stylesheet does the rest.\n      root.style.setProperty(\"--holo-x\", x.toFixed(3))\n      root.style.setProperty(\"--holo-y\", y.toFixed(3))\n      root.setAttribute(\"data-live\", \"\")\n    })\n  }\n\n  const layers = Math.min(3, Math.max(0, Math.round(stack)))\n  return (\n    <div\n      data-kit=\"holo-card\"\n      data-stack={layers || undefined}\n      style={{ \"--holo-tilt\": `${tilt}deg`, \"--holo-stack\": layers, ...style } as React.CSSProperties}\n      onPointerMove={track}\n      onPointerLeave={(event) => {\n        onPointerLeave?.(event)\n        rest()\n      }}\n      onPointerCancel={(event) => {\n        onPointerCancel?.(event)\n        rest()\n      }}\n      {...props}\n    >\n      <div ref={surface} data-kit=\"holo-card-tilt\">\n        {layers > 0 && (\n          <span data-kit=\"holo-card-ghosts\" aria-hidden>\n            {/* Farthest first, so nearer ones paint over it. */}\n            {Array.from({ length: layers }, (_, index) => (\n              <span key={index} data-kit=\"holo-card-ghost\" data-frame=\"br\" style={{ \"--holo-n\": layers - index } as React.CSSProperties} />\n            ))}\n          </span>\n        )}\n        <div data-kit=\"holo-card-content\">{children}</div>\n        <span data-kit=\"holo-card-sheen\" aria-hidden />\n      </div>\n    </div>\n  )\n}\n\n// A part of the card that floats above its surface (or, with a negative\n// depth, sits behind it). It's a block: a transform has nothing to move on\n// an inline box, so give an inline element of your own `display:\n// inline-block` if you tag it with data-depth instead.\nfunction HoloLayer({ depth = 1, style, ...props }: React.ComponentProps<\"div\"> & { depth?: number }) {\n  return <div data-kit=\"holo-layer\" style={{ \"--holo-depth\": depth, ...style } as React.CSSProperties} {...props} />\n}\n\nexport { HoloCard, HoloLayer }\n",
      "type": "registry:ui",
      "target": "@ui/holo-card.tsx"
    },
    {
      "path": "registry/cyber/ui/cyber/holo-card.css",
      "content": "@layer ui-sdk, cyber.tokens, cyber.base, cyber.ui, cyber.blocks, cyber.fx, cyber.a11y;\n\n@layer cyber.ui {\n  /* The root is the lens: it holds the perspective and takes the pointer,\n     and never turns itself, so what the pointer is over stays put. The\n     script writes where the pointer is as --holo-x and --holo-y (-1 to 1\n     from the surface's centre) and sets data-live; everything that moves\n     is derived from those two numbers here.\n\n       --holo-tilt  the most the surface turns\n       --holo-lift  how far one step of depth slides at full tilt\n       --holo-step  how far apart the ghost layers stand\n       --holo-cut   the cut corner the sheen is trimmed to, to match the\n                    frame inside (0px for a square one) */\n  [data-skin=\"cyber\"] [data-kit=\"holo-card\"] {\n    --holo-tilt: 8deg;\n    --holo-lift: 4px;\n    --holo-step: 7px;\n    --holo-stack: 0;\n    --holo-cut: var(--cy-cut);\n    /* Which way the ghosts stand off. */\n    --_dir: 1;\n\n    position: relative;\n    display: block;\n    width: 100%;\n    min-width: 0;\n    perspective: 720px;\n    /* Room for the ghosts, so a stack never hangs out of its column. */\n    padding-block-start: calc(var(--holo-stack) * var(--holo-step));\n    padding-inline-end: calc(var(--holo-stack) * var(--holo-step));\n\n    &:dir(rtl) {\n      --_dir: -1;\n    }\n  }\n\n  /* The surface. At rest it has no transform at all, so text stays crisp;\n     live, it turns to face the pointer, chasing it with a short ease, and\n     when the pointer leaves it settles back more slowly. No overshoot. */\n  [data-skin=\"cyber\"] [data-kit=\"holo-card-tilt\"] {\n    position: relative;\n    transition: transform var(--cy-t-slow) var(--cy-ease-snap);\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"holo-card\"][data-live] > [data-kit=\"holo-card-tilt\"] {\n    transform: rotateX(calc(var(--holo-y, 0) * -1 * var(--holo-tilt))) rotateY(calc(var(--holo-x, 0) * var(--holo-tilt)));\n    transition: transform var(--cy-t) var(--cy-ease-out);\n    will-change: transform;\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"holo-card-content\"] {\n    position: relative;\n    min-width: 0;\n  }\n\n  /* Ghosts: empty frames the size of the card, each a step further up and\n     along. They're behind the surface, so as it turns they slide the other\n     way from the pointer. */\n  [data-skin=\"cyber\"] [data-kit=\"holo-card-ghost\"] {\n    --frame-cut: var(--holo-cut);\n    --frame-line: var(--cy-line-deco);\n    --frame-fill: color-mix(in srgb, var(--cy-accent) 4%, transparent);\n    --frame-image: none;\n\n    position: absolute;\n    inset: 0;\n    pointer-events: none;\n    opacity: calc(1 - var(--holo-n) * 0.22);\n    translate: calc(var(--holo-n) * (var(--_dir) * var(--holo-step) - var(--holo-x, 0) * var(--holo-lift)))\n      calc(var(--holo-n) * (-1 * var(--holo-step) - var(--holo-y, 0) * var(--holo-lift)));\n    transition: translate var(--cy-t) var(--cy-ease-out);\n  }\n\n  /* Depth. A frame clips, and anything clipped is flattened, so a layer\n     can't truly stand off the surface in 3D. It slides toward the pointer\n     instead, by as much as a raised thing would appear to once the surface\n     has turned, which works at any depth of nesting. */\n  [data-skin=\"cyber\"] [data-kit=\"holo-card\"] :is([data-depth], [data-kit=\"holo-layer\"]) {\n    translate: calc(var(--holo-x, 0) * var(--holo-depth, 1) * var(--holo-lift)) calc(var(--holo-y, 0) * var(--holo-depth, 1) * var(--holo-lift));\n    transition: translate var(--cy-t) var(--cy-ease-out);\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"holo-card\"] [data-depth] {\n    --holo-depth: 1;\n\n    &[data-depth=\"-1\"] {\n      --holo-depth: -1;\n    }\n    &[data-depth=\"0\"] {\n      --holo-depth: 0;\n    }\n    &[data-depth=\"2\"] {\n      --holo-depth: 2;\n    }\n    &[data-depth=\"3\"] {\n      --holo-depth: 3;\n    }\n  }\n\n  /* The sheen: a soft light under the pointer and a hard streak beside it,\n     trimmed to the card's cut corner. Both are painted once and only\n     ever translated, so nothing is repainted as they move. Hidden until\n     the surface is live. */\n  [data-skin=\"cyber\"] [data-kit=\"holo-card-sheen\"] {\n    position: absolute;\n    inset: 0;\n    overflow: hidden;\n    container-type: size;\n    pointer-events: none;\n    clip-path: polygon(0 0, 100% 0, 100% calc(100% - var(--holo-cut)), calc(100% - var(--holo-cut)) 100%, 0 100%);\n    mix-blend-mode: screen;\n    opacity: 0;\n    transition: opacity var(--cy-t-slow) linear;\n\n    &::before {\n      content: \"\";\n      position: absolute;\n      inset: 0;\n      background: radial-gradient(closest-side, color-mix(in srgb, var(--cy-signal) 20%, transparent), transparent);\n      translate: calc(var(--holo-x, 0) * 50cqw) calc(var(--holo-y, 0) * 50cqh);\n      transition: translate var(--cy-t) var(--cy-ease-out);\n    }\n\n    &::after {\n      content: \"\";\n      position: absolute;\n      inset: 0 -100%;\n      background: linear-gradient(\n        112deg,\n        transparent 47%,\n        color-mix(in srgb, var(--cy-ink-hi) 14%, transparent) 49%,\n        color-mix(in srgb, var(--cy-ink-hi) 14%, transparent) 50.5%,\n        transparent 52.5%\n      );\n      translate: calc(var(--holo-x, 0) * 70cqw) 0;\n      transition: translate var(--cy-t) var(--cy-ease-out);\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"holo-card\"][data-live] [data-kit=\"holo-card-sheen\"] {\n    opacity: 1;\n  }\n\n  /* Blending and trimming mean nothing to a forced palette. */\n  @media (forced-colors: active) {\n    [data-skin=\"cyber\"] [data-kit=\"holo-card-sheen\"] {\n      display: none;\n    }\n  }\n}\n",
      "type": "registry:file",
      "target": "@ui/cyber/holo-card.css"
    }
  ],
  "type": "registry:ui"
}
