{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "avatar-initials-lib",
  "title": "Avatar initials helpers",
  "description": "Initials from a name, plus a deterministic palette color and gradient from a djb2 hash.",
  "files": [
    {
      "path": "lib/avatar-initials.ts",
      "content": "// Hand-picked so every entry, alone or next to any other, reads well with\n// white text. Random HSL gives muddy yellows and clashing pairs.\nexport const AVATAR_COLORS = [\n  \"#f43f5e\", // rose-500\n  \"#ec4899\", // pink-500\n  \"#d946ef\", // fuchsia-500\n  \"#a855f7\", // purple-500\n  \"#8b5cf6\", // violet-500\n  \"#6366f1\", // indigo-500\n  \"#3b82f6\", // blue-500\n  \"#0284c7\", // sky-600\n  \"#0891b2\", // cyan-600\n  \"#0d9488\", // teal-600\n  \"#059669\", // emerald-600\n  \"#16a34a\", // green-600\n  \"#65a30d\", // lime-600\n  \"#d97706\", // amber-600\n  \"#f97316\", // orange-500\n  \"#ef4444\", // red-500\n];\n\n// djb2 — small, well-distributed string hash. Locale-insensitive on the\n// UTF-16 code units, which is what we want for a deterministic mapping.\nfunction hash(str: string): number {\n  let h = 5381;\n  for (let i = 0; i < str.length; i++) {\n    h = ((h << 5) + h + str.charCodeAt(i)) | 0;\n  }\n  return h;\n}\n\nexport function avatarColor(name: string): string {\n  return AVATAR_COLORS[\n    Math.abs(hash(name.toLowerCase())) % AVATAR_COLORS.length\n  ];\n}\n\n// Slice three independent values out of one 32-bit hash: two palette indices\n// (forced to differ) and a gradient rotation in degrees.\nexport function avatarGradient(name: string): string {\n  const h = Math.abs(hash(name.toLowerCase()));\n  const i1 = h % AVATAR_COLORS.length;\n  const i2 =\n    (i1 + 1 + ((h >> 8) % (AVATAR_COLORS.length - 1))) % AVATAR_COLORS.length;\n  const angle = (h >> 16) % 360;\n  return `linear-gradient(${angle}deg, ${AVATAR_COLORS[i1]}, ${AVATAR_COLORS[i2]})`;\n}\n\n// Take first code point so surrogate-pair scripts (emoji, some CJK) don't\n// get sliced in half.\nfunction firstGlyph(token: string): string {\n  const cp = token.codePointAt(0);\n  return cp ? String.fromCodePoint(cp) : \"\";\n}\n\nexport function getInitials(name: string): string {\n  const tokens = name.trim().split(/\\s+/).filter(Boolean);\n  if (tokens.length === 0) return \"?\";\n  if (tokens.length === 1) return firstGlyph(tokens[0]).toUpperCase();\n  return (\n    firstGlyph(tokens[0]) + firstGlyph(tokens[tokens.length - 1])\n  ).toUpperCase();\n}\n",
      "type": "registry:lib"
    }
  ],
  "type": "registry:lib"
}