{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "colors",
  "type": "registry:lib",
  "files": [
    {
      "path": "src/registry/lib/colors.ts",
      "content": "interface hsl {\n  h: number;\n  s: number;\n  l: number;\n}\n\ninterface hex {\n  hex: string;\n}\n\ntype Color = hsl & hex;\n\nconst sanitizeHex = (val: string) => {\n  const sanitized = val.replace(/[^a-fA-F0-9]/g, \"\").toUpperCase();\n\n  if (![3, 6, 8].includes(sanitized.length)) {\n    return undefined;\n  }\n\n  return `#${sanitized}`;\n};\n\nconst hslToHex = ({ h, s, l }: hsl) => {\n  s /= 100;\n  l /= 100;\n\n  const k = (n: number) => (n + h / 30) % 12;\n  const a = s * Math.min(l, 1 - l);\n  const f = (n: number) =>\n    l - a * Math.max(Math.min(k(n) - 3, 9 - k(n), 1), -1);\n  const r = Math.round(255 * f(0));\n  const g = Math.round(255 * f(8));\n  const b = Math.round(255 * f(4));\n\n  const toHex = (x: number) => {\n    const hex = x.toString(16);\n    return hex.length === 1 ? `0${hex}` : hex;\n  };\n\n  return `${toHex(r)}${toHex(g)}${toHex(b)}`.toUpperCase();\n};\n\nconst hexToHsl = ({ hex }: hex): hsl => {\n  hex = hex.replace(/^#/, \"\");\n\n  if (hex.length === 3) {\n    hex = hex\n      .split(\"\")\n      .map((char) => char + char)\n      .join(\"\");\n  }\n\n  while (hex.length < 6) {\n    hex += \"0\";\n  }\n\n  let r = Number.parseInt(hex.slice(0, 2), 16) || 0;\n  let g = Number.parseInt(hex.slice(2, 4), 16) || 0;\n  let b = Number.parseInt(hex.slice(4, 6), 16) || 0;\n\n  r /= 255;\n  g /= 255;\n  b /= 255;\n  const max = Math.max(r, g, b);\n  const min = Math.min(r, g, b);\n  let h = 0;\n  let s: number;\n  const l = (max + min) / 2;\n\n  if (max === min) {\n    h = s = 0;\n  } else {\n    const d = max - min;\n    s = l > 0.5 ? d / (2 - max - min) : d / (max + min);\n    switch (max) {\n      case r:\n        h = (g - b) / d + (g < b ? 6 : 0);\n        break;\n      case g:\n        h = (b - r) / d + 2;\n        break;\n      case b:\n        h = (r - g) / d + 4;\n        break;\n    }\n    h /= 6;\n    h *= 360;\n  }\n\n  return { h: Math.round(h), s: Math.round(s * 100), l: Math.round(l * 100) };\n};\n\nexport { type hsl, type hex, type Color, sanitizeHex, hslToHex, hexToHsl };\n",
      "type": "registry:lib",
      "target": "lib/colors.ts"
    }
  ]
}