{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "avatar",
  "type": "registry:ui",
  "title": "Avatar",
  "description": "A person or team as a photo, or as initials on a colour picked from the name. Four sizes, round or square, falls back when a photo fails.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/theme.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/ui/avatar.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/ui/avatar.tsx",
      "content": "import { useState } from 'react';\nimport { cn } from '../lib/utils';\n\nconst palette = [\n  'bg-kh-accent-soft text-kh-accent-ink',\n  'bg-kh-surface-3 text-kh-ink-2',\n  'bg-kh-ink text-kh-on-ink',\n  'bg-kh-surface-2 text-kh-ink ring-1 ring-inset ring-kh-line-strong',\n];\nconst sizes = { xs: 'size-6 text-[0.625rem]', sm: 'size-8 text-kh-caption', md: 'size-10 text-kh-small', lg: 'size-14 text-kh-heading' };\n\nconst hash = (s: string) => [...s].reduce((a, c) => (a * 31 + c.charCodeAt(0)) >>> 0, 7);\n/** Up to two initials from the words of a name, letters and digits only: a note in brackets ('Ann (front desk)') or a stray\n *  symbol never becomes an initial (prototype 13:27: 'A(' on the team list). */\nexport const initials = (name: string) =>\n  name.replace(/\\([^)]*\\)?/g, ' ').split(/\\s+/).map((w) => w.match(/[\\p{L}\\p{N}]/u)?.[0]).filter(Boolean).slice(0, 2).join('').toUpperCase();\n\nexport interface AvatarProps {\n  /** Whose face this is. Becomes the accessible name and the initials. */\n  name: string;\n  size?: keyof typeof sizes;\n  square?: boolean;\n  /** A photo. Falls back to initials if it is missing or fails to load. */\n  src?: string;\n  srcSet?: string;\n  /** Hide it from assistive tech when the name is written next to it. */\n  decorative?: boolean;\n  className?: string;\n}\n\n/** A person or team: a photo, or their initials on a colour picked from the name (the same name always gets the same colour). */\nexport function Avatar({ name, size = 'md', square, src, srcSet, decorative, className }: AvatarProps) {\n  const [failed, setFailed] = useState<string>();\n  const shape = square ? 'rounded-kh' : 'rounded-kh-pill';\n  const a11y = decorative ? { 'aria-hidden': true as const } : { role: 'img' as const, 'aria-label': name };\n  if (src && failed !== src) {\n    return (\n      <span {...a11y} className={cn('relative inline-flex shrink-0 select-none overflow-hidden bg-kh-surface-3 ring-1 ring-inset ring-kh-line', shape, sizes[size], className)}>\n        <img src={src} srcSet={srcSet} alt=\"\" draggable={false} onError={() => setFailed(src)} className=\"size-full object-cover\" />\n      </span>\n    );\n  }\n  return (\n    <span {...a11y} className={cn('inline-flex shrink-0 select-none items-center justify-center font-semibold', shape, palette[hash(name) % palette.length], sizes[size], className)}>\n      {initials(name)}\n    </span>\n  );\n}\n"
    }
  ]
}
