{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "avatar",
  "title": "Avatar",
  "description": "A portrait in a cut frame, with initials over a generated scanline field when there's no image.",
  "dependencies": [
    "@ui-sdk/react@0.1.0-beta.5"
  ],
  "registryDependencies": [
    "https://www.cyberspec.dev/r/cyber.json"
  ],
  "files": [
    {
      "path": "registry/cyber/ui/avatar.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Avatar as SdkAvatar, AvatarFallback, AvatarImage } from \"@ui-sdk/react/avatar\"\nimport \"@/registry/cyber/ui/cyber/avatar.css\"\n\ntype Size = \"sm\" | \"md\" | \"lg\"\ntype Shape = \"cut\" | \"hex\"\ntype Status = \"online\" | \"busy\" | \"away\" | \"offline\"\n\nconst statusWords: Record<Status, string> = { online: \"Online\", busy: \"Busy\", away: \"Away\", offline: \"Offline\" }\n\n// A stack sets the size and shape of the portraits inside it.\nconst Stack = React.createContext<{ size?: Size; shape?: Shape }>({})\n\nfunction initialsOf(name: string) {\n  const words = name.trim().split(/\\s+/).filter(Boolean)\n  const letters = words.length > 1 ? [words[0], words[words.length - 1]] : words\n  return letters.map((word) => [...word][0]?.toUpperCase() ?? \"\").join(\"\")\n}\n\n// The field behind the initials: sixteen scanlines in the outline of a head\n// and shoulders, with each line's reach, offset and strength taken from the\n// name. The same name always draws the same ghost, on any machine.\nfunction scanlines(name: string) {\n  let hash = 2166136261\n  for (const char of name) hash = Math.imul(hash ^ char.codePointAt(0)!, 16777619)\n  // mulberry32: a small generator, seeded by the name's hash.\n  const next = () => {\n    hash = (hash + 0x6d2b79f5) | 0\n    let t = Math.imul(hash ^ (hash >>> 15), 1 | hash)\n    t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t\n    return ((t ^ (t >>> 14)) >>> 0) / 4294967296\n  }\n  // Half-widths of a bust, top to bottom, on a 32-unit square.\n  const bust = [0, 0, 4, 6, 7, 7, 7, 6, 5, 3, 3, 9, 13, 15, 16, 16]\n  const lines: { y: number; x: number; width: number; opacity: number }[] = []\n  bust.forEach((half, row) => {\n    const reach = half === 0 ? 0 : Math.max(2, half + Math.round(next() * 4 - 2))\n    const slip = Math.round(next() * 4 - 2)\n    const dropped = next() < 0.12\n    if (reach && !dropped) lines.push({ y: row * 2, x: 16 - reach + slip, width: reach * 2, opacity: 0.35 + next() * 0.65 })\n    // Now and then a line of noise runs the full width, behind the figure.\n    if (next() < 0.3) lines.push({ y: row * 2, x: Math.round(next() * 12), width: 8 + Math.round(next() * 20), opacity: 0.18 })\n  })\n  return lines\n}\n\n// A portrait in a cut or a hexagonal frame. While there's no picture, it\n// shows the person's initials over a field of scanlines generated from their\n// name, so two people never share a face; a picture, once loaded, is drawn in\n// the theme's two tones like every other image on the display.\n//\n// - `name` is read to assistive technology and gives the initials. Set\n//   `decorative` when the name is printed beside the portrait already.\n// - `src`: a picture. Leave it out for the generated fallback.\n// - `shape`: \"cut\" (two corners off) or \"hex\".\n// - `status` lights a lamp on the corner, and each state is a different mark\n//   as well as a different color. `statusLabel` replaces the word a screen\n//   reader hears for it.\nfunction Avatar({\n  name,\n  src,\n  size,\n  shape,\n  status,\n  statusLabel,\n  decorative,\n  ...props\n}: Omit<React.ComponentProps<typeof SdkAvatar>, \"children\"> & {\n  name: string\n  src?: string\n  size?: Size\n  shape?: Shape\n  status?: Status\n  statusLabel?: string\n  decorative?: boolean\n}) {\n  const stack = React.useContext(Stack)\n  const lines = React.useMemo(() => scanlines(name), [name])\n  return (\n    <SdkAvatar data-kit=\"avatar\" data-size={size ?? stack.size ?? \"md\"} data-shape={shape ?? stack.shape ?? \"cut\"} {...props}>\n      <span data-kit=\"avatar-frame\">\n        <span data-kit=\"avatar-face\">\n          {src && <AvatarImage data-kit=\"avatar-image\" src={src} alt={decorative ? \"\" : name} />}\n          <AvatarFallback data-kit=\"avatar-fallback\">\n            <svg data-kit=\"avatar-field\" viewBox=\"0 0 32 32\" preserveAspectRatio=\"none\" aria-hidden focusable=\"false\">\n              {lines.map((line, index) => (\n                <rect key={index} x={line.x} y={line.y} width={line.width} height={1} opacity={line.opacity} />\n              ))}\n            </svg>\n            <span data-kit=\"avatar-initials\" aria-hidden>\n              {initialsOf(name)}\n            </span>\n            {!decorative && <span data-sr-only>{name}</span>}\n          </AvatarFallback>\n        </span>\n      </span>\n      {status && <span data-kit=\"avatar-status\" data-status={status} role=\"img\" aria-label={statusLabel ?? statusWords[status]} />}\n    </SdkAvatar>\n  )\n}\n\n// Several portraits overlapping in a row, with the rest counted on a tile at\n// the end.\n//\n// - `label` names the group (\"Crew on this job\").\n// - `max`: how many to show before counting the rest.\n// - `size` and `shape` apply to every portrait in it.\nfunction AvatarStack({\n  label,\n  max = 4,\n  size = \"md\",\n  shape = \"cut\",\n  children,\n  ...props\n}: React.ComponentProps<\"div\"> & { label: string; max?: number; size?: Size; shape?: Shape }) {\n  const people = React.Children.toArray(children)\n  const rest = people.length - max\n  const stack = React.useMemo(() => ({ size, shape }), [size, shape])\n  return (\n    <div data-kit=\"avatar-stack\" role=\"group\" aria-label={label} {...props}>\n      <Stack.Provider value={stack}>{rest > 0 ? people.slice(0, max) : people}</Stack.Provider>\n      {rest > 0 && (\n        <span data-kit=\"avatar\" data-size={size} data-shape={shape} data-more=\"\">\n          <span data-kit=\"avatar-frame\">\n            <span data-kit=\"avatar-face\">\n              <span data-kit=\"avatar-initials\" aria-hidden>\n                +{rest}\n              </span>\n              <span data-sr-only>{rest} more</span>\n            </span>\n          </span>\n        </span>\n      )}\n    </div>\n  )\n}\n\nexport { Avatar, AvatarStack }\nexport type { Shape as AvatarShape, Size as AvatarSize, Status as AvatarStatus }\n",
      "type": "registry:ui",
      "target": "@ui/avatar.tsx"
    },
    {
      "path": "registry/cyber/ui/cyber/avatar.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 only a box the size of the portrait: it isn't clipped, so\n     the status lamp can sit on its corner. Inside it are two layers cut to\n     the same shape, one a pixel inside the other: the outer is the edge, the\n     inner the face. That draws an outline around a shape a border can't\n     follow, and it's the same construction for the cut frame and the hexagon. */\n  [data-skin=\"cyber\"] [data-kit=\"avatar\"] {\n    --size: 40px;\n    --cut: 8px;\n    --lamp: 9px;\n\n    position: relative;\n    display: inline-block;\n    flex: none;\n    width: var(--size);\n    height: var(--size);\n    vertical-align: middle;\n    font-size: calc(var(--size) * 0.36);\n\n    &[data-size=\"sm\"] {\n      --size: 28px;\n      --cut: 6px;\n      --lamp: 7px;\n    }\n    &[data-size=\"lg\"] {\n      --size: 56px;\n      --cut: 11px;\n      --lamp: 11px;\n    }\n\n    /* A regular hexagon standing on a point is narrower than it is tall. */\n    &[data-shape=\"hex\"] {\n      width: calc(var(--size) * 0.94);\n      height: calc(var(--size) * 1.085);\n    }\n  }\n\n  [data-skin=\"cyber\"] :is([data-kit=\"avatar-frame\"], [data-kit=\"avatar-face\"]) {\n    position: absolute;\n    clip-path: polygon(var(--c) 0, 100% 0, 100% calc(100% - var(--c)), calc(100% - var(--c)) 100%, 0 100%, 0 var(--c));\n\n    [data-shape=\"hex\"] > &,\n    [data-shape=\"hex\"] > * > & {\n      clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"avatar-frame\"] {\n    --c: var(--cut);\n    inset: 0;\n    background: var(--cy-line-ctl);\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"avatar-face\"] {\n    /* A touch less than the outer cut, so the diagonal edge is as thin as\n       the straight ones. */\n    --c: calc(var(--cut) - 0.6px);\n    inset: 1px;\n    isolation: isolate;\n    display: grid;\n    place-items: center;\n    overflow: hidden;\n    background: color-mix(in srgb, var(--cy-accent) 12%, var(--cy-panel));\n    color: var(--cy-ink-hi);\n  }\n\n  /* A loaded picture is drawn in two tones: greyscale, multiplied onto a\n     bright plate of the accent, with scanlines over it. Until it loads, the\n     SDK keeps it out of sight with inline styles, which these leave alone. */\n  [data-skin=\"cyber\"] [data-kit=\"avatar\"][data-loading-status=\"loaded\"] [data-kit=\"avatar-face\"] {\n    background: color-mix(in srgb, var(--cy-accent) 72%, var(--cy-ink-hi));\n\n    &::after {\n      content: \"\";\n      position: absolute;\n      inset: 0;\n      pointer-events: none;\n      background: repeating-linear-gradient(to bottom, transparent 0 2px, color-mix(in srgb, var(--cy-void) 42%, transparent) 2px 3px);\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"avatar-image\"][data-loading-status=\"loaded\"] {\n    position: absolute;\n    inset: 0;\n    width: 100%;\n    height: 100%;\n    object-fit: cover;\n    filter: grayscale(1) contrast(1.15);\n    mix-blend-mode: multiply;\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"avatar-fallback\"] {\n    position: absolute;\n    inset: 0;\n    display: grid;\n    place-items: center;\n  }\n\n  /* The generated ghost: thin lines of the accent, behind the initials. */\n  [data-skin=\"cyber\"] [data-kit=\"avatar-field\"] {\n    position: absolute;\n    inset: 0;\n    width: 100%;\n    height: 100%;\n    fill: var(--cy-accent);\n    opacity: 0.62;\n    shape-rendering: crispEdges;\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"avatar-initials\"] {\n    position: relative;\n    font-weight: 700;\n    line-height: 1;\n    letter-spacing: 0.04em;\n    /* A dark halo keeps the letters clear of the lines behind them. */\n    text-shadow:\n      0 0 3px var(--cy-panel),\n      0 0 6px var(--cy-panel),\n      0 1px 0 var(--cy-panel);\n  }\n\n  /* The lamp. Each state is its own mark, so it reads without its color:\n     online a solid square, busy a solid diamond, away a hollow square,\n     offline a flat bar. */\n  [data-skin=\"cyber\"] [data-kit=\"avatar-status\"] {\n    position: absolute;\n    inset-block-end: -2px;\n    inset-inline-end: -2px;\n    width: var(--lamp);\n    height: var(--lamp);\n    background: var(--cy-ok);\n    /* A gap of the void between the lamp and the portrait. */\n    box-shadow: 0 0 0 2px var(--cy-void);\n\n    &[data-status=\"busy\"] {\n      background: var(--cy-flag);\n      rotate: 45deg;\n    }\n    &[data-status=\"away\"] {\n      background: var(--cy-void);\n      border: 2px solid var(--cy-flag);\n    }\n    &[data-status=\"offline\"] {\n      height: 3px;\n      inset-block-end: 1px;\n      background: var(--cy-ink-mute);\n    }\n  }\n\n  /* The tile that counts the rest of a stack. */\n  [data-skin=\"cyber\"] [data-kit=\"avatar\"][data-more] {\n    & [data-kit=\"avatar-frame\"] {\n      background: var(--cy-line-deco);\n    }\n    & [data-kit=\"avatar-face\"] {\n      background: var(--cy-panel);\n      color: var(--cy-signal);\n      font-family: var(--cy-mono);\n      font-size: 0.86em;\n    }\n    & [data-kit=\"avatar-initials\"] {\n      font-weight: 500;\n      letter-spacing: 0;\n      text-shadow: none;\n    }\n  }\n\n  /* A row of portraits, each over the edge of the one before, with a sliver\n     of the void between them that follows their shape. */\n  [data-skin=\"cyber\"] [data-kit=\"avatar-stack\"] {\n    display: inline-flex;\n    align-items: center;\n    padding-inline-start: 2px;\n\n    & > [data-kit=\"avatar\"] {\n      filter: drop-shadow(-2px 0 0 var(--cy-void));\n\n      &:not(:first-child) {\n        margin-inline-start: calc(var(--size) * -0.12);\n      }\n\n      &:dir(rtl) {\n        filter: drop-shadow(2px 0 0 var(--cy-void));\n      }\n    }\n  }\n\n  /* Forced colors drop backgrounds, and the edge here is one: a real border\n     takes its place, square. */\n  @media (forced-colors: active) {\n    [data-skin=\"cyber\"] :is([data-kit=\"avatar-frame\"], [data-kit=\"avatar-face\"]) {\n      clip-path: none;\n    }\n    [data-skin=\"cyber\"] [data-kit=\"avatar-frame\"] {\n      border: 1px solid CanvasText;\n    }\n    [data-skin=\"cyber\"] [data-kit=\"avatar-status\"] {\n      border: 1px solid CanvasText;\n    }\n  }\n}\n",
      "type": "registry:file",
      "target": "@ui/cyber/avatar.css"
    }
  ],
  "type": "registry:ui"
}
