{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "color-picker",
  "title": "Color Picker",
  "description": "Composable Astro color picker parts, CSS input, channels, swatches, and data-slot change events.",
  "dependencies": [
    "@data-slot/core",
    "@data-slot/popover",
    "@lucide/astro",
    "cn"
  ],
  "registryDependencies": [
    "@gnostic/button",
    "@gnostic/input-group",
    "@gnostic/popover"
  ],
  "files": [
    {
      "path": "packages/ui/src/components/ui/color-picker/color-picker-area.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\nimport { cn } from \"cn\"\ntype Props = HTMLAttributes<\"div\">\nconst { class: className, ...props } = Astro.props\n---\n\n<div\n  data-slot=\"color-picker-area\"\n  role=\"group\"\n  tabindex=\"0\"\n  aria-label=\"Saturation and brightness. Use Left and Right for saturation, Up and Down for brightness.\"\n  class={cn(\"relative h-40 w-full cursor-crosshair touch-none rounded-lg select-none outline-none focus-visible:ring-2 focus-visible:ring-ring aria-disabled:pointer-events-none aria-disabled:opacity-50 forced-color-adjust-none\", className)}\n  {...props}\n>\n  <span\n    data-slot=\"color-picker-area-thumb\"\n    class=\"pointer-events-none absolute size-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white shadow-md ring-1 ring-black/40\"\n  ></span>\n</div>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/color-picker/color-picker-area.astro"
    },
    {
      "path": "packages/ui/src/components/ui/color-picker/color-picker-channel-input.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\nimport { cn } from \"cn\"\nimport { InputGroupInput } from \"../input-group/index.ts\"\nimport type { ColorPickerChannelInputProps } from \"./types.ts\"\ntype Props = Omit<HTMLAttributes<\"input\">, \"type\" | \"value\" | \"name\"> &\n  ColorPickerChannelInputProps\nconst { class: className, channel = \"hex\", colorSpace, ...props } = Astro.props\n---\n\n<InputGroupInput\n  data-slot=\"color-picker-channel-input\"\n  data-channel={channel}\n  data-color-space={colorSpace}\n  type=\"text\"\n  inputmode={channel === \"hex\" ? \"text\" : \"decimal\"}\n  aria-label={channel === \"alpha\" ? \"Opacity\" : channel}\n  autocomplete=\"off\"\n  autocapitalize=\"none\"\n  spellcheck=\"false\"\n  class={cn(\"min-w-0 flex-1 px-2 tabular-nums not-first:border-s not-first:border-border data-[channel=hex]:uppercase\", className)}\n  {...props}\n/>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/color-picker/color-picker-channel-input.astro"
    },
    {
      "path": "packages/ui/src/components/ui/color-picker/color-picker-color.ts",
      "content": "/** Color parsing and conversion adapted from the ReUI source supplied for this port.\n * Channels stay in their source color space until a control changes them.\n */\nimport type {\n    ColorPickerColor,\n    ColorPickerColorSpace,\n    ColorPickerChannel,\n    ColorPickerFormat,\n} from './types.ts'\n\ntype Triple = [number, number, number]\n\nconst SPACE_CHANNELS: Record<\n    ColorPickerColorSpace,\n    [ColorPickerChannel, ColorPickerChannel, ColorPickerChannel]\n> = {\n    rgb: ['red', 'green', 'blue'],\n    hsl: ['hue', 'saturation', 'lightness'],\n    hsv: ['hue', 'saturation', 'brightness'],\n    oklch: ['lightness', 'chroma', 'hue'],\n}\n\nexport const COLOR_PICKER_FORMATS: ColorPickerFormat[] = [\n    'hex',\n    'rgb',\n    'hsl',\n    'hsb',\n    'oklch',\n]\n\nexport const FORMAT_LABELS: Record<ColorPickerFormat, string> = {\n    hex: 'HEX',\n    rgb: 'RGB',\n    hsl: 'HSL',\n    hsb: 'HSB',\n    oklch: 'OKLCH',\n}\n\n/* -------------------------------------------------------------------------- */\n/*                                 Color math                                 */\n/* -------------------------------------------------------------------------- */\n\nexport const clamp = (value: number, min: number, max: number) =>\n    Math.min(max, Math.max(min, value))\n\nexport const wrapHue = (hue: number) => ((hue % 360) + 360) % 360\n\n/* Round output only. Drop trailing zeros and never write \"-0\". */\nexport const fixed = (value: number, digits = 3) =>\n    String(Number(value.toFixed(digits)) + 0)\n\nfunction rgbToHsv([red, green, blue]: Triple, fallbackHue = 0): Triple {\n    const r = red / 255\n    const g = green / 255\n    const b = blue / 255\n    const max = Math.max(r, g, b)\n    const delta = max - Math.min(r, g, b)\n    let hue = fallbackHue\n    if (delta > 1e-9) {\n        hue =\n            max === r\n                ? ((g - b) / delta) % 6\n                : max === g\n                  ? (b - r) / delta + 2\n                  : (r - g) / delta + 4\n        hue = wrapHue(hue * 60)\n    }\n    return [hue, max === 0 ? 0 : (delta / max) * 100, max * 100]\n}\n\nfunction hsvToRgb([hue, saturation, brightness]: Triple): Triple {\n    const s = saturation / 100\n    const v = brightness / 100\n    const channel = (n: number) => {\n        const k = (n + hue / 60) % 6\n        return (v - v * s * Math.max(0, Math.min(k, 4 - k, 1))) * 255\n    }\n    return [channel(5), channel(3), channel(1)]\n}\n\n/* HSL and HSB share a hue, carried over as is, so a gray keeps it. */\nfunction hsvToHsl([hue, saturation, brightness]: Triple): Triple {\n    const s = saturation / 100\n    const v = brightness / 100\n    const l = v * (1 - s / 2)\n    const sl = l === 0 || l === 1 ? 0 : (v - l) / Math.min(l, 1 - l)\n    return [hue, sl * 100, l * 100]\n}\n\nfunction hslToHsv([hue, saturation, lightness]: Triple): Triple {\n    const s = saturation / 100\n    const l = lightness / 100\n    const v = l + s * Math.min(l, 1 - l)\n    return [hue, v === 0 ? 0 : 2 * (1 - l / v) * 100, v * 100]\n}\n\nconst toLinear = (channel: number) => {\n    const c = channel / 255\n    return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4\n}\n\nconst fromLinear = (channel: number) =>\n    255 *\n    (channel <= 0.0031308\n        ? 12.92 * channel\n        : 1.055 * channel ** (1 / 2.4) - 0.055)\n\n/* OKLab by Björn Ottosson, the matrices CSS Color 4 uses. Linear sRGB in,\n   unbounded, so a wide-gamut color converts without clipping. */\nfunction linearToOklab([r, g, b]: Triple): Triple {\n    const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b)\n    const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b)\n    const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b)\n    return [\n        0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,\n        1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,\n        0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,\n    ]\n}\n\n/* OKLab, or polar a and b, to OKLCH in the picker's units: L 0 to 100. */\nfunction oklabToOklch([lightness, a, b]: Triple, fallbackHue = 0): Triple {\n    const chroma = Math.sqrt(a * a + b * b)\n    const hue =\n        chroma < 1e-4\n            ? fallbackHue\n            : wrapHue((Math.atan2(b, a) * 180) / Math.PI)\n    return [lightness * 100, chroma, hue]\n}\n\nfunction rgbToOklch(rgb: Triple, fallbackHue = 0): Triple {\n    return oklabToOklch(linearToOklab(rgb.map(toLinear) as Triple), fallbackHue)\n}\n\nfunction oklchToLinear([lightness, chroma, hue]: Triple): Triple {\n    const angle = (hue * Math.PI) / 180\n    const L = lightness / 100\n    const a = chroma * Math.cos(angle)\n    const b = chroma * Math.sin(angle)\n    const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3\n    const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3\n    const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3\n    return [\n        4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,\n        -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,\n        -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s,\n    ]\n}\n\nconst inSrgb = (linear: Triple) =>\n    linear.every((channel) => channel >= -1e-4 && channel <= 1 + 1e-4)\n\nconst clipLinear = (linear: Triple) =>\n    linear.map((channel) => clamp(channel, 0, 1)) as Triple\n\n/* How far a clipped color lands from the OKLCH it stands for, in OKLab. */\nfunction clipError(clipped: Triple, [lightness, chroma, hue]: Triple) {\n    const [l, a, b] = linearToOklab(clipped)\n    const angle = (hue * Math.PI) / 180\n    return Math.hypot(\n        l - lightness / 100,\n        a - chroma * Math.cos(angle),\n        b - chroma * Math.sin(angle),\n    )\n}\n\n/* CSS Color 4 gamut mapping: lower chroma at the same lightness and hue\n   until clipping the rest moves the color less than a just-noticeable\n   difference (0.02 in OKLab), then clip. Pure chroma reduction drifted up to\n   27 units in hex from what a browser paints for Tailwind's P3 shades. */\nfunction oklchToRgb([lightness, chroma, hue]: Triple): Triple {\n    const encode = (linear: Triple) =>\n        linear.map((channel) => fromLinear(channel)) as Triple\n    if (lightness >= 100) return [255, 255, 255]\n    if (lightness <= 0) return [0, 0, 0]\n    const target: Triple = [lightness, Math.max(0, chroma), hue]\n    const origin = oklchToLinear(target)\n    if (inSrgb(origin)) return encode(clipLinear(origin))\n    let clipped = clipLinear(origin)\n    if (clipError(clipped, target) < 0.02) return encode(clipped)\n    let low = 0\n    let high = target[1]\n    let lowInGamut = true\n    while (high - low > 1e-4) {\n        const mid = (low + high) / 2\n        const current: Triple = [lightness, mid, hue]\n        const linear = oklchToLinear(current)\n        if (lowInGamut && inSrgb(linear)) {\n            low = mid\n            continue\n        }\n        clipped = clipLinear(linear)\n        const error = clipError(clipped, current)\n        if (error < 0.02) {\n            if (0.02 - error < 1e-4) break\n            lowInGamut = false\n            low = mid\n        } else {\n            high = mid\n        }\n    }\n    return encode(clipped)\n}\n\nfunction toRgb(color: ColorPickerColor): Triple {\n    const { space, channels } = color\n    if (space === 'rgb') return channels\n    if (space === 'hsv') return hsvToRgb(channels)\n    if (space === 'hsl') return hsvToRgb(hslToHsv(channels))\n    return oklchToRgb(channels)\n}\n\n/** A color's channels in another space. */\nexport function toSpace(\n    color: ColorPickerColor,\n    space: ColorPickerColorSpace,\n): Triple {\n    const { space: from, channels } = color\n    if (from === space) return channels\n    if (from === 'hsv' && space === 'hsl') return hsvToHsl(channels)\n    if (from === 'hsl' && space === 'hsv') return hslToHsv(channels)\n    const rgb = toRgb(color)\n    const hue = from === 'rgb' ? 0 : channels[from === 'oklch' ? 2 : 0]\n    if (space === 'rgb') return rgb\n    if (space === 'hsv') return rgbToHsv(rgb, hue)\n    if (space === 'hsl') return hsvToHsl(rgbToHsv(rgb, hue))\n    return rgbToOklch(rgb, hue)\n}\n\n/** Whether a color fits sRGB. OKLCH can reach past it; the picker then maps it into sRGB the way CSS does. */\nexport function isColorInSrgb(color: ColorPickerColor) {\n    return color.space !== 'oklch' || inSrgb(oklchToLinear(color.channels))\n}\n\nconst HEX_PATTERN = /^#?([\\da-f]{3,4}|[\\da-f]{6}|[\\da-f]{8})$/\n/* [\\s\\S], not \".\", so a function pretty-printed over several lines reads. */\nconst FUNCTION_PATTERN = /^([a-z][a-z\\d-]*)\\(([\\s\\S]*)\\)$/\nconst NUMBER_PATTERN =\n    /^([+-]?(?:\\d+\\.?\\d*|\\.\\d+)(?:e[+-]?\\d+)?)(%|deg|rad|grad|turn)?$/\n\n/* The 148 CSS named colors, each name then its hex: about 2.3 KB, checked\n   against Chrome, and safe to read on the server unlike a canvas. */\nconst NAMED_COLORS =\n    'alicebluef0f8ff antiquewhitefaebd7 aqua00ffff aquamarine7fffd4 ' +\n    'azuref0ffff beigef5f5dc bisqueffe4c4 black000000 blanchedalmondffebcd ' +\n    'blue0000ff blueviolet8a2be2 browna52a2a burlywooddeb887 ' +\n    'cadetblue5f9ea0 chartreuse7fff00 chocolated2691e coralff7f50 ' +\n    'cornflowerblue6495ed cornsilkfff8dc crimsondc143c cyan00ffff ' +\n    'darkblue00008b darkcyan008b8b darkgoldenrodb8860b darkgraya9a9a9 ' +\n    'darkgreen006400 darkgreya9a9a9 darkkhakibdb76b darkmagenta8b008b ' +\n    'darkolivegreen556b2f darkorangeff8c00 darkorchid9932cc darkred8b0000 ' +\n    'darksalmone9967a darkseagreen8fbc8f darkslateblue483d8b ' +\n    'darkslategray2f4f4f darkslategrey2f4f4f darkturquoise00ced1 ' +\n    'darkviolet9400d3 deeppinkff1493 deepskyblue00bfff dimgray696969 ' +\n    'dimgrey696969 dodgerblue1e90ff firebrickb22222 floralwhitefffaf0 ' +\n    'forestgreen228b22 fuchsiaff00ff gainsborodcdcdc ghostwhitef8f8ff ' +\n    'goldffd700 goldenroddaa520 gray808080 green008000 greenyellowadff2f ' +\n    'grey808080 honeydewf0fff0 hotpinkff69b4 indianredcd5c5c indigo4b0082 ' +\n    'ivoryfffff0 khakif0e68c lavendere6e6fa lavenderblushfff0f5 ' +\n    'lawngreen7cfc00 lemonchiffonfffacd lightblueadd8e6 lightcoralf08080 ' +\n    'lightcyane0ffff lightgoldenrodyellowfafad2 lightgrayd3d3d3 ' +\n    'lightgreen90ee90 lightgreyd3d3d3 lightpinkffb6c1 lightsalmonffa07a ' +\n    'lightseagreen20b2aa lightskyblue87cefa lightslategray778899 ' +\n    'lightslategrey778899 lightsteelblueb0c4de lightyellowffffe0 lime00ff00 ' +\n    'limegreen32cd32 linenfaf0e6 magentaff00ff maroon800000 ' +\n    'mediumaquamarine66cdaa mediumblue0000cd mediumorchidba55d3 ' +\n    'mediumpurple9370db mediumseagreen3cb371 mediumslateblue7b68ee ' +\n    'mediumspringgreen00fa9a mediumturquoise48d1cc mediumvioletredc71585 ' +\n    'midnightblue191970 mintcreamf5fffa mistyroseffe4e1 moccasinffe4b5 ' +\n    'navajowhiteffdead navy000080 oldlacefdf5e6 olive808000 olivedrab6b8e23 ' +\n    'orangeffa500 orangeredff4500 orchidda70d6 palegoldenrodeee8aa ' +\n    'palegreen98fb98 paleturquoiseafeeee palevioletreddb7093 ' +\n    'papayawhipffefd5 peachpuffffdab9 perucd853f pinkffc0cb plumdda0dd ' +\n    'powderblueb0e0e6 purple800080 rebeccapurple663399 redff0000 ' +\n    'rosybrownbc8f8f royalblue4169e1 saddlebrown8b4513 salmonfa8072 ' +\n    'sandybrownf4a460 seagreen2e8b57 seashellfff5ee siennaa0522d ' +\n    'silverc0c0c0 skyblue87ceeb slateblue6a5acd slategray708090 ' +\n    'slategrey708090 snowfffafa springgreen00ff7f steelblue4682b4 tand2b48c ' +\n    'teal008080 thistled8bfd8 tomatoff6347 turquoise40e0d0 violetee82ee ' +\n    'wheatf5deb3 whiteffffff whitesmokef5f5f5 yellowffff00 ' +\n    'yellowgreen9acd32'\n\nlet namedColors: Map<string, string> | null = null\n\nfunction namedColor(name: string) {\n    namedColors ??= new Map(\n        NAMED_COLORS.split(' ').map((entry) => [\n            entry.slice(0, -6),\n            entry.slice(-6),\n        ]),\n    )\n    return namedColors.get(name)\n}\n\n/* One CSS number: 100% is worth `percentOf`, computed as value * percentOf\n   / 100 so 50% of 255 is exactly 127.5; angles only where allowed. */\nfunction readNumber(token: string, percentOf: number, angle = false) {\n    if (token === 'none') return 0\n    const match = NUMBER_PATTERN.exec(token)\n    if (!match) return null\n    const value = Number(match[1])\n    if (!Number.isFinite(value)) return null\n    const unit = match[2]\n    if (!unit) return value\n    if (unit === '%') return angle ? null : (value * percentOf) / 100\n    if (!angle) return null\n    if (unit === 'rad') return (value * 180) / Math.PI\n    if (unit === 'grad') return value * 0.9\n    if (unit === 'turn') return value * 360\n    return value\n}\n\ntype Matrix = [Triple, Triple, Triple]\n\nconst multiply = (matrix: Matrix, [x, y, z]: Triple): Triple =>\n    matrix.map((row) => row[0] * x + row[1] * y + row[2] * z) as Triple\n\nconst compose = (outer: Matrix, inner: Matrix): Matrix =>\n    outer.map((row) =>\n        [0, 1, 2].map(\n            (column) =>\n                row[0] * inner[0][column] +\n                row[1] * inner[1][column] +\n                row[2] * inner[2][column],\n        ),\n    ) as Matrix\n\n/* CSS Color 4's matrices: XYZ D65 to linear sRGB, each RGB space to XYZ,\n   and Bradford from D50, the white of lab(), lch() and ProPhoto. */\nconst XYZ_TO_SRGB: Matrix = [\n    [12831 / 3959, -329 / 214, -1974 / 3959],\n    [-851781 / 878810, 1648619 / 878810, 36519 / 878810],\n    [705 / 12673, -2585 / 12673, 705 / 667],\n]\nconst D50_TO_D65: Matrix = [\n    [0.955473421488075, -0.02309845494876471, 0.06325924320057072],\n    [-0.0283697093338637, 1.0099953980813041, 0.021041441191917323],\n    [0.012314014864481998, -0.020507649298898964, 1.330365926242124],\n]\nconst D50_TO_SRGB = compose(XYZ_TO_SRGB, D50_TO_D65)\n\n/* sRGB's curve, carried past 0 and 1 by symmetry, as color() allows. */\nconst decodeSrgb = (value: number) => {\n    const size = Math.abs(value)\n    return (\n        Math.sign(value) *\n        (size <= 0.04045 ? size / 12.92 : ((size + 0.055) / 1.055) ** 2.4)\n    )\n}\n\nconst RGB_SPACES: Record<\n    string,\n    { decode: (value: number) => number; toSrgb: Matrix | null }\n> = {\n    srgb: { decode: decodeSrgb, toSrgb: null },\n    'srgb-linear': { decode: (value) => value, toSrgb: null },\n    'display-p3': {\n        decode: decodeSrgb,\n        toSrgb: compose(XYZ_TO_SRGB, [\n            [0.4865709486482162, 0.26566769316909306, 0.1982172852343625],\n            [0.2289745640697488, 0.6917385218365064, 0.079286914093745],\n            [0, 0.04511338185890264, 1.043944368900976],\n        ]),\n    },\n    'a98-rgb': {\n        decode: (value) => Math.sign(value) * Math.abs(value) ** (563 / 256),\n        toSrgb: compose(XYZ_TO_SRGB, [\n            [573536 / 994567, 263643 / 1420810, 187206 / 994567],\n            [591459 / 1989134, 6239551 / 9945670, 374412 / 4972835],\n            [53769 / 1989134, 351524 / 4972835, 4929758 / 4972835],\n        ]),\n    },\n    'prophoto-rgb': {\n        decode: (value) => {\n            const size = Math.abs(value)\n            return size <= 16 / 512\n                ? value / 16\n                : Math.sign(value) * size ** 1.8\n        },\n        toSrgb: compose(D50_TO_SRGB, [\n            [0.7977666449006423, 0.13518129740053308, 0.0313477341283922],\n            [0.2880748288194013, 0.711835234241873, 0.00008993693872564],\n            [0, 0, 0.8251046025104602],\n        ]),\n    },\n    rec2020: {\n        decode: (value) => {\n            const size = Math.abs(value)\n            return size < 0.018053968510807 * 4.5\n                ? value / 4.5\n                : Math.sign(value) *\n                      ((size + 0.09929682680944) / 1.09929682680944) **\n                          (1 / 0.45)\n        },\n        toSrgb: compose(XYZ_TO_SRGB, [\n            [0.6369580483012914, 0.14461690358620832, 0.1688809751641721],\n            [0.2627002120112671, 0.6779980715188708, 0.05930171646986196],\n            [0, 0.028072693049087428, 1.060985057710791],\n        ]),\n    },\n    xyz: { decode: (value) => value, toSrgb: XYZ_TO_SRGB },\n    'xyz-d65': { decode: (value) => value, toSrgb: XYZ_TO_SRGB },\n    'xyz-d50': { decode: (value) => value, toSrgb: D50_TO_SRGB },\n}\n\n/* CIE Lab, D50 white, to XYZ D50, as CSS Color 4 writes it. */\nfunction labToXyz([lightness, a, b]: Triple): Triple {\n    const kappa = 24389 / 27\n    const epsilon = 216 / 24389\n    const fy = (lightness + 16) / 116\n    const fx = a / 500 + fy\n    const fz = fy - b / 200\n    const x = fx ** 3 > epsilon ? fx ** 3 : (116 * fx - 16) / kappa\n    const y = lightness > kappa * epsilon ? fy ** 3 : lightness / kappa\n    const z = fz ** 3 > epsilon ? fz ** 3 : (116 * fz - 16) / kappa\n    return [x * (0.3457 / 0.3585), y, z * ((1 - 0.3457 - 0.3585) / 0.3585)]\n}\n\n/* A color that can reach past sRGB is kept as OKLCH, so nothing is clipped\n   until a format or a screen needs sRGB. */\nconst fromLinearSrgb = (linear: Triple): Triple =>\n    oklabToOklch(linearToOklab(linear))\n\nconst isUnit = (channels: Triple) =>\n    channels.every((channel) => channel >= -1e-6 && channel <= 1 + 1e-6)\n\n/* The channels of one function, as a color in the picker's spaces. */\nexport function readChannels(\n    name: string,\n    parts: string[],\n): { space: ColorPickerColorSpace; channels: Triple } | null {\n    if (name === 'rgb') {\n        const rgb = parts.map((part) => readNumber(part, 255))\n        if (rgb.some((value) => value === null)) return null\n        return {\n            space: 'rgb',\n            channels: rgb.map((value) => clamp(value!, 0, 255)) as Triple,\n        }\n    }\n    if (name === 'hsl' || name === 'hsv' || name === 'hsb' || name === 'hwb') {\n        const hue = readNumber(parts[0], 1, true)\n        const first = readNumber(parts[1], 100)\n        const second = readNumber(parts[2], 100)\n        if (hue === null || first === null || second === null) return null\n        const x = clamp(first, 0, 100)\n        const y = clamp(second, 0, 100)\n        if (name === 'hsl') return { space: 'hsl', channels: [hue, x, y] }\n        if (name !== 'hwb') return { space: 'hsv', channels: [hue, x, y] }\n        /* hwb(): whiteness and blackness are HSB's saturation and brightness\n       read from the other end; summing past 100% gives their gray. */\n        const total = x + y\n        if (total >= 100) {\n            return { space: 'hsv', channels: [hue, 0, (x / total) * 100] }\n        }\n        const brightness = 100 - y\n        return {\n            space: 'hsv',\n            channels: [hue, (1 - x / brightness) * 100, brightness],\n        }\n    }\n    if (name === 'oklch' || name === 'oklab') {\n        const lightness = readNumber(parts[0], 1)\n        const second = readNumber(parts[1], 0.4)\n        const third =\n            name === 'oklch'\n                ? readNumber(parts[2], 1, true)\n                : readNumber(parts[2], 0.4)\n        if (lightness === null || second === null || third === null) return null\n        const l = clamp(lightness, 0, 1)\n        if (name === 'oklch') {\n            return {\n                space: 'oklch',\n                channels: [l * 100, Math.max(0, second), third],\n            }\n        }\n        return {\n            space: 'oklch',\n            channels: oklabToOklch([l, second, third]),\n        }\n    }\n    if (name === 'lab' || name === 'lch') {\n        const lightness = readNumber(parts[0], 100)\n        const second = readNumber(parts[1], name === 'lab' ? 125 : 150)\n        const third =\n            name === 'lch'\n                ? readNumber(parts[2], 1, true)\n                : readNumber(parts[2], 125)\n        if (lightness === null || second === null || third === null) return null\n        const l = clamp(lightness, 0, 100)\n        const angle = (third * Math.PI) / 180\n        const [a, b] =\n            name === 'lab'\n                ? [second, third]\n                : [\n                      Math.max(0, second) * Math.cos(angle),\n                      Math.max(0, second) * Math.sin(angle),\n                  ]\n        return {\n            space: 'oklch',\n            channels: fromLinearSrgb(\n                multiply(D50_TO_SRGB, labToXyz([l, a, b])),\n            ),\n        }\n    }\n    if (name === 'color') {\n        if (!Object.hasOwn(RGB_SPACES, parts[0])) return null\n        const target = RGB_SPACES[parts[0]]\n        if (!target || parts.length !== 4) return null\n        const values = parts.slice(1).map((part) => readNumber(part, 1))\n        if (values.some((value) => value === null)) return null\n        const channels = values as Triple\n        if (parts[0] === 'srgb' && isUnit(channels)) {\n            return {\n                space: 'rgb',\n                channels: channels.map(\n                    (value) => clamp(value, 0, 1) * 255,\n                ) as Triple,\n            }\n        }\n        const linear = channels.map(target.decode) as Triple\n        return {\n            space: 'oklch',\n            channels: fromLinearSrgb(\n                target.toSrgb ? multiply(target.toSrgb, linear) : linear,\n            ),\n        }\n    }\n    return null\n}\n\n/**\n * Reads a CSS color: hex with 3, 4, 6 or 8 digits, `#` optional; the 148\n * named colors and `transparent`; `rgb()`, `hsl()`, `hwb()`, `lab()`,\n * `lch()`, `oklab()`, `oklch()` and `color()` in any of CSS Color 4's RGB\n * and XYZ spaces, plus `hsb()` or `hsv()`; modern or comma syntax, with or\n * without alpha. A color that can fall outside sRGB is kept as OKLCH.\n * Anything else, `var()` and `currentColor` included, is `null`.\n */\nexport function parseColor(\n    input: string | null | undefined,\n): ColorPickerColor | null {\n    if (typeof input !== 'string') return null\n    const text = input.trim().toLowerCase()\n    if (!text) return null\n    if (text === 'transparent') {\n        return { space: 'rgb', channels: [0, 0, 0], alpha: 0 }\n    }\n    const hex = HEX_PATTERN.exec(namedColor(text) ?? text)\n    if (hex) {\n        let digits = hex[1]\n        if (digits.length <= 4) {\n            digits = [...digits].map((digit) => digit + digit).join('')\n        }\n        const byte = (index: number) =>\n            parseInt(digits.slice(index, index + 2), 16)\n        return {\n            space: 'rgb',\n            channels: [byte(0), byte(2), byte(4)],\n            alpha: digits.length === 8 ? byte(6) / 255 : 1,\n        }\n    }\n    const call = FUNCTION_PATTERN.exec(text)\n    if (!call) return null\n    const name = call[1].replace(/a$/, '')\n    const [main, slash, ...rest] = call[2].split('/')\n    if (rest.length > 0) return null\n    const parts = main.split(/[\\s,]+/).filter(Boolean)\n    /* color() names its space first, and takes alpha only after a slash. */\n    const count = name === 'color' ? 4 : 3\n    /* Alpha follows a slash, or is the fourth value of the comma syntax. */\n    const alphaToken =\n        slash?.trim() ?? (name === 'color' ? undefined : parts[3])\n    if (\n        parts.length !== count &&\n        !(name !== 'color' && parts.length === 4 && slash === undefined)\n    ) {\n        return null\n    }\n    const alpha = alphaToken === undefined ? 1 : readNumber(alphaToken, 1)\n    const read = readChannels(name, parts.slice(0, count))\n    if (alpha === null || !read) return null\n    const channels = read.channels\n    if (channels.some((channel) => !Number.isFinite(channel))) return null\n    if (read.space !== 'rgb') {\n        const hueIndex = read.space === 'oklch' ? 2 : 0\n        channels[hueIndex] = wrapHue(channels[hueIndex])\n    }\n    return { space: read.space, channels, alpha: clamp(alpha, 0, 1) }\n}\n\nconst CSS_WIDE = /^(inherit|initial|unset|revert|revert-layer|currentcolor)$/\n\n/* Whatever else the browser paints (color-mix(), relative colors,\n   light-dark(), system colors), resolved by its computed style, which\n   serializes as a function parseColor reads. Two parents of different\n   colors expose anything that inherits (var() with no value, a CSS-wide\n   keyword); a canvas would have read those as black. Only typing reaches\n   this, never a render. */\nexport function parseWithBrowser(text: string): ColorPickerColor | null {\n    if (\n        typeof document === 'undefined' ||\n        CSS_WIDE.test(text.toLowerCase()) ||\n        !CSS.supports?.('color', text)\n    ) {\n        return null\n    }\n    const parent = document.createElement('div')\n    const probe = document.createElement('div')\n    parent.style.display = 'none'\n    probe.style.color = text\n    parent.append(probe)\n    document.body.append(parent)\n    parent.style.color = 'rgb(1, 2, 3)'\n    const first = getComputedStyle(probe).color\n    parent.style.color = 'rgb(4, 5, 6)'\n    const second = getComputedStyle(probe).color\n    parent.remove()\n    return first === second ? parseColor(first) : null\n}\n\n/**\n * Writes a color in a format. HEX gains a fourth byte and the others a\n * `/ alpha` only when the color is translucent; OKLCH keeps channels outside\n * sRGB, every other format maps the color into sRGB the way CSS does.\n */\nexport function formatColor(\n    color: ColorPickerColor,\n    format: ColorPickerFormat,\n): string {\n    const alpha = clamp(color.alpha, 0, 1)\n    const opacityText = fixed(alpha)\n    const tail = opacityText !== '1' ? ` / ${opacityText}` : ''\n    if (format === 'hex' || format === 'rgb') {\n        const rgb = toRgb(color).map((channel) =>\n            Math.round(clamp(channel, 0, 255)),\n        )\n        if (format === 'rgb') return `rgb(${rgb.join(' ')}${tail})`\n        const opacity = Math.round(alpha * 255)\n        const bytes = opacity < 255 ? [...rgb, opacity] : rgb\n        return `#${bytes.map((byte) => byte.toString(16).padStart(2, '0')).join('')}`\n    }\n    if (format === 'oklch') {\n        const [l, c, h] = toSpace(color, 'oklch')\n        /* Chroma is never below 0, and a hue that rounds to 360 is 0. */\n        const hue = fixed(wrapHue(Number(fixed(h))))\n        return `oklch(${fixed(l)}% ${fixed(Math.max(0, c))} ${hue}${tail})`\n    }\n    const [h, s, third] = toSpace(color, format === 'hsl' ? 'hsl' : 'hsv')\n    return `${format}(${fixed(wrapHue(Number(fixed(h))))} ${fixed(s)}% ${fixed(third)}%${tail})`\n}\n\n/* What CSS paints: OKLCH as itself, so a wide-gamut screen shows it. */\nexport const toCss = (color: ColorPickerColor) =>\n    formatColor(color, color.space === 'oklch' ? 'oklch' : 'rgb')\n\nconst DEFAULT_SPACE: Record<ColorPickerChannel, ColorPickerColorSpace> = {\n    hue: 'hsv',\n    saturation: 'hsv',\n    brightness: 'hsv',\n    lightness: 'hsl',\n    chroma: 'oklch',\n    red: 'rgb',\n    green: 'rgb',\n    blue: 'rgb',\n    alpha: 'rgb',\n}\n\n/* A space that has no such channel falls back to the channel's own. */\nexport const resolveSpace = (\n    channel: ColorPickerChannel,\n    space: ColorPickerColorSpace | undefined,\n) =>\n    channel !== 'alpha' && space && SPACE_CHANNELS[space].includes(channel)\n        ? space\n        : DEFAULT_SPACE[channel]\n\n/**\n * Get the range and step for a given channel and space.\n */\nexport function channelRange(\n    space: ColorPickerColorSpace,\n    channel: ColorPickerChannel,\n) {\n    if (channel === 'alpha') return { max: 1, step: 0.01 }\n    if (channel === 'hue') return { max: 360, step: 1 }\n    if (channel === 'chroma') return { max: 0.4, step: 0.004 }\n    return { max: space === 'rgb' ? 255 : 100, step: 1 }\n}\n\nexport function readChannel(\n    color: ColorPickerColor,\n    space: ColorPickerColorSpace,\n    channel: ColorPickerChannel,\n) {\n    if (channel === 'alpha') return color.alpha\n    return toSpace(color, space)[SPACE_CHANNELS[space].indexOf(channel)]\n}\n\nexport function withChannel(\n    color: ColorPickerColor,\n    space: ColorPickerColorSpace,\n    channel: ColorPickerChannel,\n    value: number,\n): ColorPickerColor {\n    if (channel === 'alpha') return { ...color, alpha: clamp(value, 0, 1) }\n    const channels = [...toSpace(color, space)] as Triple\n    channels[SPACE_CHANNELS[space].indexOf(channel)] = value\n    return { space, channels, alpha: color.alpha }\n}\n\n/* The colors a track runs through: the full spectrum for hue, so a gray\n   still shows where it would go, and sampled stops elsewhere, since OKLCH\n   and HSL lightness do not run straight in sRGB. */\nexport function trackStops(\n    color: ColorPickerColor,\n    space: ColorPickerColorSpace,\n    channel: ColorPickerChannel,\n) {\n    const opaque = { ...color, alpha: 1 }\n    if (channel === 'alpha') return ['transparent', toCss(opaque)]\n    let base = opaque\n    if (channel === 'hue') {\n        base =\n            space === 'oklch'\n                ? withChannel(\n                      opaque,\n                      'oklch',\n                      'chroma',\n                      Math.max(readChannel(opaque, 'oklch', 'chroma'), 0.12),\n                  )\n                : { space: 'hsv', channels: [0, 100, 100], alpha: 1 }\n    }\n    const count =\n        channel === 'hue' || space === 'oklch'\n            ? 13\n            : space === 'hsl' && channel === 'lightness'\n              ? 3\n              : 2\n    const { max } = channelRange(space, channel)\n    const target = channel === 'hue' && space !== 'oklch' ? 'hsv' : space\n    return Array.from({ length: count }, (_, index) =>\n        formatColor(\n            withChannel(base, target, channel, (max * index) / (count - 1)),\n            'rgb',\n        ),\n    )\n}\n\ntype FieldChannel = ColorPickerChannel | 'hex'\n\nexport const FORMAT_FIELDS: Record<\n    ColorPickerFormat,\n    { space: ColorPickerColorSpace; channels: FieldChannel[] }\n> = {\n    hex: { space: 'rgb', channels: ['hex'] },\n    rgb: { space: 'rgb', channels: ['red', 'green', 'blue'] },\n    hsl: { space: 'hsl', channels: ['hue', 'saturation', 'lightness'] },\n    hsb: { space: 'hsv', channels: ['hue', 'saturation', 'brightness'] },\n    oklch: { space: 'oklch', channels: ['lightness', 'chroma', 'hue'] },\n}\n\nexport function channelText(\n    color: ColorPickerColor,\n    space: ColorPickerColorSpace,\n    channel: FieldChannel,\n) {\n    if (channel === 'hex') {\n        return formatColor({ ...color, alpha: 1 }, 'hex')\n            .slice(1)\n            .toUpperCase()\n    }\n    if (channel === 'alpha') return `${Math.round(color.alpha * 100)}%`\n    const value = readChannel(color, space, channel)\n    if (channel === 'chroma') return fixed(value, 3)\n    return space === 'oklch' ? fixed(value, 1) : String(Math.round(value))\n}\n\nconst FIELD_NUMBER =\n    /^([+-]?(?:\\d+(?:[.,]\\d*)?|[.,]\\d+))\\s*(%|°|deg|grad|rad|turn)?$/\n\n/* A typed channel. Hex keeps the current opacity unless it carries its own.\n   A number takes a comma decimal; % is a share of the channel's range, as in\n   CSS (50% red is 127.5, 50% chroma 0.2), and a hue takes an angle unit and\n   wraps, so -30 is 330. Anything else is rejected. */\nexport function readChannelText(\n    text: string,\n    color: ColorPickerColor,\n    space: ColorPickerColorSpace,\n    channel: FieldChannel,\n): ColorPickerColor | null {\n    if (channel === 'hex') {\n        const digits = text.trim().replace(/^#/, '')\n        const parsed = /^[\\da-f]+$/i.test(digits) ? parseColor(digits) : null\n        if (!parsed) return null\n        return digits.length === 4 || digits.length === 8\n            ? parsed\n            : { ...parsed, alpha: color.alpha }\n    }\n    const match = FIELD_NUMBER.exec(text.trim().toLowerCase())\n    if (!match) return null\n    const value = Number(match[1].replace(',', '.'))\n    const unit = match[2]\n    if (!Number.isFinite(value)) return null\n    if (channel === 'hue') {\n        if (unit === '%') return null\n        const degrees =\n            unit === 'rad'\n                ? (value * 180) / Math.PI\n                : unit === 'grad'\n                  ? value * 0.9\n                  : unit === 'turn'\n                    ? value * 360\n                    : value\n        return withChannel(color, space, channel, wrapHue(degrees))\n    }\n    if (unit && unit !== '%') return null\n    if (channel === 'alpha')\n        return { ...color, alpha: clamp(value / 100, 0, 1) }\n    const { max } = channelRange(space, channel)\n    const scaled = unit === '%' ? (value * max) / 100 : value\n    return withChannel(color, space, channel, clamp(scaled, 0, max))\n}\n\nexport const CHECKER =\n    'repeating-conic-gradient(var(--color-muted) 0 25%, var(--color-background) 0 50%) 50% / 8px 8px'\nexport const EMPTY_COLOR: ColorPickerColor = {\n    space: 'hsv',\n    channels: [0, 0, 0],\n    alpha: 1,\n}\n",
      "type": "registry:file",
      "target": "~/src/components/ui/color-picker/color-picker-color.ts"
    },
    {
      "path": "packages/ui/src/components/ui/color-picker/color-picker-content.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\nimport { cn } from \"cn\"\nimport { PopoverContent } from \"../popover/index.ts\"\nimport ColorPickerPanel from \"./color-picker-panel.astro\"\nimport type { ColorPickerContentProps } from \"./types.ts\"\ntype Props = HTMLAttributes<\"div\"> & ColorPickerContentProps\nconst { class: className, align = \"start\", ...props } = Astro.props\n---\n\n<PopoverContent\n  data-color-picker-content\n  align={align}\n  aria-label=\"Choose a color\"\n  class={cn(\"w-80 max-w-[calc(100vw-1.5rem)] p-3\", className)}\n  {...props}\n>\n  <slot>\n    <ColorPickerPanel />\n  </slot>\n</PopoverContent>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/color-picker/color-picker-content.astro"
    },
    {
      "path": "packages/ui/src/components/ui/color-picker/color-picker-fields.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\nimport ChevronDownIcon from \"@lucide/astro/icons/chevron-down\"\nimport { cn } from \"cn\"\nimport { InputGroup } from \"../input-group/index.ts\"\nimport ColorPickerChannelInput from \"./color-picker-channel-input.astro\"\nimport {\n  COLOR_PICKER_FORMATS,\n  FORMAT_FIELDS,\n  FORMAT_LABELS,\n} from \"./color-picker-color.ts\"\nimport type { ColorPickerFieldsProps } from \"./types.ts\"\n\ntype Props = HTMLAttributes<\"div\"> & ColorPickerFieldsProps\n\nconst {\n  class: className,\n  defaultFormat = \"hex\",\n  formats = COLOR_PICKER_FORMATS,\n  ...props\n} = Astro.props\n\nconst available = formats.length ? [...new Set(formats)] : [defaultFormat]\nconst selected = available.includes(defaultFormat)\n  ? defaultFormat\n  : available[0]!\n---\n\n<div\n  data-slot=\"color-picker-fields\"\n  data-format={selected}\n  class={cn(\"min-w-0\", className)}\n  {...props}\n>\n  <InputGroup dir=\"ltr\">\n    {available.length > 1 && (\n      <div data-slot=\"color-picker-format\" class=\"relative flex shrink-0 self-stretch rounded-s-[inherit] border-e border-input\">\n        <select\n          data-slot=\"color-picker-format-trigger\"\n          data-color-picker-format\n          aria-label=\"Color format\"\n          class=\"h-full w-full cursor-pointer appearance-none rounded-s-[inherit] bg-transparent py-0 ps-2 pe-5 text-xs font-medium text-foreground outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50\"\n        >\n          {available.map((format) => (\n            <option value={format} selected={format === selected}>\n              {FORMAT_LABELS[format]}\n            </option>\n          ))}\n        </select>\n        <ChevronDownIcon\n          data-slot=\"color-picker-format-icon\"\n          class=\"pointer-events-none absolute end-1 top-1/2 size-3 -translate-y-1/2 text-muted-foreground\"\n          aria-hidden=\"true\"\n        />\n      </div>\n    )}\n    {available.map((format) => (\n      <div\n        data-slot=\"color-picker-channels\"\n        data-color-picker-channels\n        data-format={format}\n        class=\"flex min-w-0 flex-1 self-stretch [&>input]:px-1.5 [&>input]:text-xs [&>input[data-channel=alpha]]:w-[calc(4.8ch+0.75rem)] [&>input[data-channel=alpha]]:flex-none\"\n        hidden={format !== selected}\n      >\n        {FORMAT_FIELDS[format].channels.map((channel) => (\n          <ColorPickerChannelInput\n            channel={channel}\n            colorSpace={FORMAT_FIELDS[format].space}\n          />\n        ))}\n        <ColorPickerChannelInput channel=\"alpha\" hidden />\n      </div>\n    ))}\n  </InputGroup>\n</div>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/color-picker/color-picker-fields.astro"
    },
    {
      "path": "packages/ui/src/components/ui/color-picker/color-picker-input.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\nimport { cn } from \"cn\"\nimport {\n  InputGroup,\n  InputGroupAddon,\n  InputGroupButton,\n  InputGroupInput,\n} from \"../input-group/index.ts\"\nimport ColorPickerSwatch from \"./color-picker-swatch.astro\"\ntype Props = Omit<HTMLAttributes<\"input\">, \"value\" | \"type\" | \"name\">\nconst { class: className, ...props } = Astro.props\n---\n\n<div\n  data-slot=\"color-picker-input\"\n  class={cn(\"w-full\", className)}\n>\n  <InputGroup>\n    <InputGroupAddon align=\"inline-start\">\n      <InputGroupButton\n        data-slot=\"popover-trigger\"\n        data-color-picker-trigger\n        size=\"icon-xs\"\n        aria-label=\"Open color picker\"\n      >\n        <ColorPickerSwatch />\n      </InputGroupButton>\n    </InputGroupAddon>\n    <InputGroupInput\n      data-slot=\"color-picker-text\"\n      type=\"text\"\n      autocomplete=\"off\"\n      autocapitalize=\"none\"\n      spellcheck=\"false\"\n      aria-keyshortcuts=\"Alt+ArrowDown\"\n      {...props}\n    />\n  </InputGroup>\n</div>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/color-picker/color-picker-input.astro"
    },
    {
      "path": "packages/ui/src/components/ui/color-picker/color-picker-panel.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\nimport { cn } from \"cn\"\nimport ColorPickerArea from \"./color-picker-area.astro\"\nimport ColorPickerSlider from \"./color-picker-slider.astro\"\nimport ColorPickerFields from \"./color-picker-fields.astro\"\ntype Props = HTMLAttributes<\"div\">\nconst { class: className, ...props } = Astro.props\n---\n\n<div\n  data-slot=\"color-picker-panel\"\n  role=\"group\"\n  aria-label=\"Color controls\"\n  class={cn(\"flex w-full min-w-0 flex-col gap-3\", className)}\n  {...props}\n>\n  <slot>\n    <ColorPickerArea />\n    <ColorPickerSlider channel=\"hue\" />\n    <ColorPickerSlider channel=\"alpha\" />\n    <ColorPickerFields />\n  </slot>\n</div>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/color-picker/color-picker-panel.astro"
    },
    {
      "path": "packages/ui/src/components/ui/color-picker/color-picker-slider.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\nimport { cn } from \"cn\"\nimport { channelRange, resolveSpace } from \"./color-picker-color.ts\"\nimport type { ColorPickerSliderProps } from \"./types.ts\"\ntype Props = Omit<\n  HTMLAttributes<\"input\">,\n  \"type\" | \"min\" | \"max\" | \"step\" | \"value\"\n> &\n  ColorPickerSliderProps\nconst { class: className, channel = \"hue\", colorSpace, ...props } = Astro.props\nconst { max, step } = channelRange(resolveSpace(channel, colorSpace), channel)\n---\n\n<input\n  data-slot=\"color-picker-slider\"\n  data-channel={channel}\n  data-color-space={colorSpace}\n  type=\"range\"\n  min=\"0\"\n  max={max}\n  step={step}\n  value=\"0\"\n  aria-label={channel === \"alpha\" ? \"Opacity\" : channel}\n  hidden={channel === \"alpha\"}\n  class={cn(\"h-3 w-full cursor-pointer appearance-none rounded-full outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 forced-color-adjust-none [&::-moz-range-thumb]:size-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-2 [&::-moz-range-thumb]:border-white [&::-moz-range-thumb]:bg-white [&::-moz-range-thumb]:shadow-md [&::-moz-range-track]:h-3 [&::-moz-range-track]:bg-transparent [&::-webkit-slider-runnable-track]:h-3 [&::-webkit-slider-runnable-track]:bg-transparent [&::-webkit-slider-thumb]:-mt-0.5 [&::-webkit-slider-thumb]:size-4 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:border-2 [&::-webkit-slider-thumb]:border-white [&::-webkit-slider-thumb]:bg-white [&::-webkit-slider-thumb]:shadow-md\", className)}\n  {...props}\n/>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/color-picker/color-picker-slider.astro"
    },
    {
      "path": "packages/ui/src/components/ui/color-picker/color-picker-swatch-item.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\nimport { cn } from \"cn\"\nimport CheckIcon from \"@lucide/astro/icons/check\"\nimport { CHECKER, parseColor, toCss } from \"./color-picker-color.ts\"\nimport type { ColorPickerSwatchItemProps } from \"./types.ts\"\ntype Props = Omit<HTMLAttributes<\"button\">, \"value\"> &\n  ColorPickerSwatchItemProps\nconst {\n  class: className,\n  value,\n  label = value,\n  disabled = false,\n  style,\n  ...props\n} = Astro.props\nconst color = parseColor(value)\nconst css = color ? toCss(color) : \"transparent\"\nconst background = `linear-gradient(${css}, ${css}), ${CHECKER}`\n---\n\n<button\n  data-slot=\"color-picker-swatch-item\"\n  data-value={value}\n  type=\"button\"\n  aria-label={label}\n  aria-pressed=\"false\"\n  disabled={disabled || !color}\n  class={cn(\"relative flex size-8 shrink-0 items-center justify-center rounded-md border border-foreground/15 outline-none aria-pressed:ring-2 aria-pressed:ring-ring aria-pressed:ring-offset-2 aria-pressed:ring-offset-background focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 forced-color-adjust-none\", className)}\n  style={\n    typeof style === \"string\"\n      ? `background: ${background}; ${style}`\n      : { background, ...style }\n  }\n  {...props}\n>\n  <span data-slot=\"color-picker-swatch-check\" aria-hidden=\"true\" hidden>\n    <CheckIcon class=\"size-4 text-white mix-blend-difference\" />\n  </span>\n</button>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/color-picker/color-picker-swatch-item.astro"
    },
    {
      "path": "packages/ui/src/components/ui/color-picker/color-picker-swatch.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\nimport { cn } from \"cn\"\ntype Props = HTMLAttributes<\"span\">\nconst { class: className, ...props } = Astro.props\n---\n\n<span\n  data-slot=\"color-picker-swatch\"\n  aria-hidden=\"true\"\n  class={cn(\"inline-block size-5 shrink-0 rounded-sm border border-foreground/15 forced-color-adjust-none\", className)}\n  {...props}\n></span>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/color-picker/color-picker-swatch.astro"
    },
    {
      "path": "packages/ui/src/components/ui/color-picker/color-picker-swatches.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\nimport { cn } from \"cn\"\nimport ColorPickerSwatchItem from \"./color-picker-swatch-item.astro\"\nimport type { ColorPickerSwatchesProps } from \"./types.ts\"\ntype Props = HTMLAttributes<\"div\"> & ColorPickerSwatchesProps\nconst { class: className, colors = [], ...props } = Astro.props\n---\n\n<div\n  data-slot=\"color-picker-swatches\"\n  role=\"group\"\n  aria-label=\"Color swatches\"\n  class={cn(\"flex flex-wrap gap-2\", className)}\n  {...props}\n>\n  <slot>\n    {colors.map((value) => (\n      <ColorPickerSwatchItem value={value} />\n    ))}\n  </slot>\n</div>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/color-picker/color-picker-swatches.astro"
    },
    {
      "path": "packages/ui/src/components/ui/color-picker/color-picker-trigger.astro",
      "content": "---\nimport type { ComponentProps } from \"astro/types\"\nimport { cn } from \"cn\"\nimport ChevronDownIcon from \"@lucide/astro/icons/chevron-down\"\nimport { Button } from \"../button/index.ts\"\nimport ColorPickerSwatch from \"./color-picker-swatch.astro\"\nimport ColorPickerValue from \"./color-picker-value.astro\"\ntype Props = ComponentProps<typeof Button>\nconst { class: className, variant = \"outline\", ...props } = Astro.props\n---\n\n<Button\n  data-slot=\"popover-trigger\"\n  data-color-picker-trigger\n  variant={variant}\n  class={cn(\"w-full min-w-0 justify-start font-normal\", className)}\n  {...props}\n>\n  <slot>\n    <ColorPickerSwatch />\n    <ColorPickerValue />\n    <ChevronDownIcon data-icon=\"inline-end\" />\n  </slot>\n</Button>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/color-picker/color-picker-trigger.astro"
    },
    {
      "path": "packages/ui/src/components/ui/color-picker/color-picker-value.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\nimport { cn } from \"cn\"\ntype Props = HTMLAttributes<\"span\">\nconst { class: className, ...props } = Astro.props\n---\n\n<span\n  data-slot=\"color-picker-value\"\n  class={cn(\"min-w-0 flex-1 truncate text-start font-mono text-sm\", className)}\n  {...props}\n></span>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/color-picker/color-picker-value.astro"
    },
    {
      "path": "packages/ui/src/components/ui/color-picker/color-picker.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\nimport { cn } from \"cn\"\nimport ColorPickerTrigger from \"./color-picker-trigger.astro\"\nimport ColorPickerContent from \"./color-picker-content.astro\"\nimport { EMPTY_COLOR, formatColor, parseColor } from \"./color-picker-color.ts\"\nimport type { ColorPickerProps } from \"./types.ts\"\n\ntype Props = HTMLAttributes<\"div\"> & ColorPickerProps\nconst {\n  class: className,\n  id = `color-${crypto.randomUUID()}`,\n  defaultValue = \"#000000\",\n  format = \"hex\",\n  alpha = false,\n  disabled = false,\n  readOnly = false,\n  label = \"Choose a color\",\n  name,\n  form,\n  ...props\n} = Astro.props\nconst parsed = parseColor(defaultValue) ?? EMPTY_COLOR\nconst color = alpha ? parsed : { ...parsed, alpha: 1 }\n---\n\n<div\n  data-slot=\"color-picker\"\n  id={id}\n  data-default-value={formatColor(\n    color,\n    color.space === \"oklch\" ? \"oklch\" : \"rgb\",\n  )}\n  data-format={format}\n  data-alpha={alpha}\n  data-disabled={disabled}\n  data-readonly={readOnly}\n  data-label={label}\n  class={cn(\"inline-flex min-w-0 flex-col\", className)}\n  {...props}\n>\n  <slot>\n    <ColorPickerTrigger />\n    <ColorPickerContent />\n  </slot>\n  <input\n    data-slot=\"color-picker-form-input\"\n    type=\"hidden\"\n    name={name}\n    form={form}\n    value={formatColor(color, format)}\n    disabled={disabled}\n  />\n  <span data-slot=\"color-picker-status\" role=\"status\" class=\"sr-only\"></span>\n</div>\n\n<script>\n  import { create, type ColorPickerController } from \"./color-picker.ts\"\n  const controllers: ColorPickerController[] = []\n  const initialize = () => controllers.push(...create())\n  initialize()\n  document.addEventListener(\"astro:page-load\", initialize)\n  document.addEventListener(\"astro:before-swap\", () => {\n    for (const controller of controllers) controller.destroy()\n    controllers.length = 0\n  })\n</script>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/color-picker/color-picker.astro"
    },
    {
      "path": "packages/ui/src/components/ui/color-picker/color-picker.ts",
      "content": "import {\n    clearRootBinding,\n    emit,\n    ensureId,\n    getOwnedElements,\n    getPart,\n    getParts,\n    getRootBinding,\n    getRoots,\n    hasRootBinding,\n    observeFormReset,\n    on,\n    onRoot,\n    setRootBinding,\n} from '@data-slot/core'\nimport { createPopover, type PopoverController } from '@data-slot/popover'\n\nimport {\n    CHECKER,\n    EMPTY_COLOR,\n    channelRange,\n    channelText,\n    clamp,\n    fixed,\n    formatColor,\n    parseColor,\n    parseWithBrowser,\n    readChannel,\n    readChannelText,\n    resolveSpace,\n    toCss,\n    toSpace,\n    trackStops,\n    withChannel,\n    wrapHue,\n} from './color-picker-color.ts'\n\nimport type {\n    ColorPickerChangeDetail,\n    ColorPickerChannel,\n    ColorPickerColor,\n    ColorPickerColorSpace,\n    ColorPickerFormat,\n} from './types.ts'\n\nconst ROOT_SLOT = 'color-picker'\n\n/** Browser controller for one composed picker. */\nexport interface ColorPickerController {\n    /** Remove listeners and restore the popup and root ID. */\n    destroy(): void\n    /** Current value in the root's output format. */\n    getValue(): string\n    /** Set a CSS color. Returns false for invalid text. Silent updates prevent feedback loops. */\n    setColor(value: string, options?: { silent?: boolean }): boolean\n}\n\n/** Bind each unbound picker in the scope. */\nexport function create(scope: ParentNode = document) {\n    return getRoots<HTMLElement>(scope, ROOT_SLOT)\n        .filter((root) => !hasRootBinding(root, ROOT_SLOT))\n        .map(createColorPicker)\n}\n\n/** Parts are optional. Capture them before the popover moves its content. */\nexport function createColorPicker(root: HTMLElement): ColorPickerController {\n    const existing = getRootBinding<ColorPickerController>(root, ROOT_SLOT)\n    if (existing) return existing\n    const parts = <T extends HTMLElement = HTMLElement>(slot: string) =>\n        getParts<T>(root, slot)\n    const formInput = getPart<HTMLInputElement>(root, 'color-picker-form-input')\n    const texts = parts<HTMLInputElement>('color-picker-text')\n    const channels = parts<HTMLInputElement>('color-picker-channel-input')\n    const sliders = parts<HTMLInputElement>('color-picker-slider')\n    const areas = parts('color-picker-area')\n    const thumbs = areas.map((area) =>\n        area.querySelector<HTMLElement>(\n            '[data-slot=\"color-picker-area-thumb\"]',\n        ),\n    )\n    const swatches = parts('color-picker-swatch')\n    const items = parts<HTMLButtonElement>('color-picker-swatch-item')\n    const values = parts('color-picker-value')\n    const fields = parts('color-picker-fields')\n    const status = getPart(root, 'color-picker-status')\n    const trigger = getPart<HTMLButtonElement>(root, 'popover-trigger')\n    const content = getPart<HTMLElement>(root, 'popover-content')\n    const controls = getOwnedElements<\n        HTMLInputElement | HTMLButtonElement | HTMLSelectElement\n    >(root, root, 'input, button, select')\n    const ownDisabled = new Map(\n        controls.map((control) => [control, control.disabled]),\n    )\n    const ownReadOnly = new Map(\n        [...texts, ...channels].map((input) => [input, input.readOnly]),\n    )\n    const output = (root.dataset.format ?? 'hex') as ColorPickerFormat\n    const alpha = root.dataset.alpha === 'true'\n    const normalize = (color: ColorPickerColor): ColorPickerColor =>\n        alpha ? color : { ...color, alpha: 1 }\n    const initial = normalize(\n        parseColor(root.dataset.defaultValue) ?? EMPTY_COLOR,\n    )\n    let color = initial\n    let value = formatColor(color, output)\n    let destroyed = false\n    let interaction: string | null = null\n    let popover: PopoverController | undefined\n    const cleanups: Array<() => void> = []\n    const disabled = () => root.dataset.disabled === 'true'\n    const readOnly = () => root.dataset.readonly === 'true'\n    const editable = () => !destroyed && !disabled() && !readOnly()\n    const fieldId = ensureId(root, 'color-picker')\n    const focusTarget = texts[0] ?? trigger\n    const oldTargetId = focusTarget?.id\n    // Labels can target the root ID in Astro markup. Move it to the actual control.\n    // This runs after the docs preview has applied its unique ID prefix.\n    if (focusTarget) {\n        root.id = `${fieldId}-root`\n        focusTarget.id = fieldId\n        if (\n            !focusTarget.getAttribute('aria-label') &&\n            !focusTarget.getAttribute('aria-labelledby') &&\n            !focusTarget.labels?.length\n        ) {\n            focusTarget.setAttribute(\n                'aria-label',\n                root.dataset.label ?? 'Choose a color',\n            )\n        }\n    }\n    if (content)\n        content.setAttribute(\n            'aria-label',\n            root.dataset.label ?? 'Choose a color',\n        )\n    const formats = new Map(\n        fields.map((field) => [field, field.dataset.format ?? 'hex']),\n    )\n    const channelOf = (input: HTMLElement) =>\n        input.dataset.channel as ColorPickerChannel\n    const spaceOf = (input: HTMLElement) =>\n        resolveSpace(\n            channelOf(input),\n            input.dataset.colorSpace as ColorPickerColorSpace | undefined,\n        )\n    const textFor = (input: HTMLInputElement) =>\n        channelText(\n            color,\n            spaceOf(input),\n            input.dataset.channel as ColorPickerChannel | 'hex',\n        )\n    const detail = (): ColorPickerChangeDetail => ({\n        id: fieldId,\n        name: formInput?.name ?? '',\n        value,\n        hex: formatColor(color, 'hex'),\n        oklch: formatColor(color, 'oklch'),\n        hsl: [...toSpace(color, 'hsl')],\n    })\n    const announce = () => {\n        if (status) status.textContent = `Selected ${value}`\n    }\n    const paint = () => {\n        if (destroyed) return\n        value = formatColor(color, output)\n        root.dataset.value = value\n        if (formInput) formInput.value = value\n        for (const input of texts) input.value = value\n        for (const node of values) {\n            node.textContent = value\n            node.title = value\n        }\n        const css = toCss(color)\n        for (const node of swatches)\n            node.style.background = `linear-gradient(${css}, ${css}), ${CHECKER}`\n        const [h, s, v] = toSpace(color, 'hsv')\n        areas.forEach((area, index) => {\n            area.style.background = `linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, transparent), hsl(${fixed(h)} 100% 50%)`\n            area.setAttribute(\n                'aria-description',\n                `Saturation ${Math.round(s)}%, brightness ${Math.round(v)}%`,\n            )\n            area.setAttribute('aria-disabled', String(disabled()))\n            area.tabIndex = disabled() ? -1 : 0\n            const thumb = thumbs[index]\n            if (thumb) {\n                thumb.style.left = `${s}%`\n                thumb.style.top = `${100 - v}%`\n                thumb.style.backgroundColor = css\n            }\n        })\n        for (const slider of sliders) {\n            const channel = channelOf(slider),\n                space = spaceOf(slider)\n            slider.value = String(readChannel(color, space, channel))\n            slider.style.background = `linear-gradient(to right, ${trackStops(color, space, channel).join(', ')}), ${CHECKER}`\n            if (channel === 'alpha') slider.hidden = !alpha\n            slider.setAttribute(\n                'aria-valuetext',\n                channel === 'alpha'\n                    ? `${Math.round(color.alpha * 100)}%`\n                    : fixed(readChannel(color, space, channel)),\n            )\n        }\n        for (const input of channels) {\n            input.value = textFor(input)\n            if (input.dataset.channel === 'alpha') input.hidden = !alpha\n            if (input.dataset.channel !== 'hex') {\n                const channel = channelOf(input),\n                    space = spaceOf(input)\n                input.setAttribute('role', 'spinbutton')\n                input.setAttribute('aria-valuemin', '0')\n                input.setAttribute(\n                    'aria-valuemax',\n                    String(\n                        channel === 'alpha'\n                            ? 100\n                            : channelRange(space, channel).max,\n                    ),\n                )\n                input.setAttribute(\n                    'aria-valuenow',\n                    String(\n                        channel === 'alpha'\n                            ? color.alpha * 100\n                            : readChannel(color, space, channel),\n                    ),\n                )\n                input.setAttribute('aria-valuetext', input.value)\n            }\n        }\n        for (const item of items) {\n            const parsed = parseColor(item.dataset.value)\n            const selected =\n                !!parsed &&\n                formatColor(normalize(parsed), 'hex') ===\n                    formatColor(color, 'hex')\n            item.setAttribute('aria-pressed', String(selected))\n            const check = item.querySelector<HTMLElement>(\n                '[data-slot=\"color-picker-swatch-check\"]',\n            )\n            check?.toggleAttribute('hidden', !selected)\n        }\n        for (const control of controls) {\n            control.disabled =\n                !!ownDisabled.get(control) ||\n                disabled() ||\n                (readOnly() &&\n                    !texts.includes(control as HTMLInputElement) &&\n                    control !== trigger &&\n                    control !== formInput)\n        }\n        for (const input of [...texts, ...channels])\n            input.readOnly = readOnly() || !!ownReadOnly.get(input)\n    }\n    const set = (next: ColorPickerColor, silent = false) => {\n        if (destroyed) return\n        const previous = value\n        color = normalize(next)\n        paint()\n        if (silent || previous === value) return\n        announce()\n        formInput?.dispatchEvent(new Event('input', { bubbles: true }))\n        emit(root, 'color-picker:change', detail())\n    }\n    const finish = () => {\n        if (interaction !== null && interaction !== value) {\n            formInput?.dispatchEvent(new Event('change', { bubbles: true }))\n            emit(root, 'color-picker:commit', detail())\n        }\n        interaction = null\n    }\n    const change = (next: ColorPickerColor) => {\n        interaction = value\n        set(next)\n        finish()\n    }\n    const listen = (\n        target: EventTarget,\n        type: string,\n        handler: (event: Event) => void,\n    ) => cleanups.push(on(target, type, handler))\n    const restoreField = (input: HTMLInputElement) => {\n        input.value = texts.includes(input) ? value : textFor(input)\n    }\n    for (const input of [...texts, ...channels]) {\n        const read = () => {\n            if (!editable() || input.disabled || input.readOnly) {\n                restoreField(input)\n                return\n            }\n            if (\n                input.value === (texts.includes(input) ? value : textFor(input))\n            )\n                return\n            const next = texts.includes(input)\n                ? (parseColor(input.value) ??\n                  parseWithBrowser(input.value.trim()))\n                : readChannelText(\n                      input.value,\n                      color,\n                      spaceOf(input),\n                      input.dataset.channel as ColorPickerChannel | 'hex',\n                  )\n            if (next) change(next)\n            else restoreField(input)\n        }\n        listen(input, 'blur', read)\n        listen(input, 'keydown', (event) => {\n            const key = event as KeyboardEvent\n            if (key.defaultPrevented) return\n            if (key.key === 'Escape') {\n                if (\n                    input.value !==\n                    (texts.includes(input) ? value : textFor(input))\n                ) {\n                    key.preventDefault()\n                    key.stopPropagation()\n                    restoreField(input)\n                }\n            } else if (key.key === 'Enter') read()\n            else if (\n                key.altKey &&\n                key.key === 'ArrowDown' &&\n                texts.includes(input)\n            ) {\n                key.preventDefault()\n                read()\n                if (!disabled()) popover?.open()\n            } else if (\n                channels.includes(input) &&\n                input.dataset.channel !== 'hex' &&\n                editable() &&\n                !input.disabled &&\n                !input.readOnly\n            ) {\n                const step = (\n                    {\n                        ArrowUp: 1,\n                        ArrowDown: -1,\n                        PageUp: 10,\n                        PageDown: -10,\n                    } as Record<string, number>\n                )[key.key]\n                if (!step) return\n                key.preventDefault()\n                const channel = channelOf(input),\n                    space = spaceOf(input)\n                const from = readChannelText(input.value, color, space, channel)\n                if (!from) return\n                const unit =\n                    channel === 'alpha'\n                        ? 0.01\n                        : channel === 'chroma'\n                          ? 0.001\n                          : 1\n                const next =\n                    readChannel(from, space, channel) +\n                    step * unit * (key.shiftKey ? 10 : 1)\n                change(\n                    withChannel(\n                        from,\n                        space,\n                        channel,\n                        channel === 'hue'\n                            ? wrapHue(next)\n                            : clamp(next, 0, channelRange(space, channel).max),\n                    ),\n                )\n            }\n        })\n    }\n    for (const field of fields) {\n        const menu = field.querySelector<HTMLSelectElement>(\n            '[data-color-picker-format]',\n        )\n        if (!menu) continue\n        const show = () => {\n            field.dataset.format = menu.value\n            for (const group of field.querySelectorAll<HTMLElement>(\n                '[data-color-picker-channels]',\n            ))\n                group.hidden = group.dataset.format !== menu.value\n        }\n        listen(menu, 'change', show)\n    }\n    for (const slider of sliders) {\n        listen(slider, 'input', () => {\n            if (!editable() || slider.disabled) {\n                paint()\n                return\n            }\n            interaction ??= value\n            const number = Number(slider.value)\n            if (Number.isFinite(number))\n                set(\n                    withChannel(\n                        color,\n                        spaceOf(slider),\n                        channelOf(slider),\n                        number,\n                    ),\n                )\n        })\n        listen(slider, 'change', finish)\n    }\n    for (const area of areas) {\n        let pointer: number | null = null\n        const apply = (event: PointerEvent) => {\n            const rect = area.getBoundingClientRect()\n            if (!rect.width || !rect.height) return\n            const hue = toSpace(color, 'hsv')[0]\n            set({\n                space: 'hsv',\n                channels: [\n                    hue,\n                    clamp(\n                        ((event.clientX - rect.left) / rect.width) * 100,\n                        0,\n                        100,\n                    ),\n                    clamp(\n                        100 - ((event.clientY - rect.top) / rect.height) * 100,\n                        0,\n                        100,\n                    ),\n                ],\n                alpha: color.alpha,\n            })\n        }\n        const release = () => {\n            if (pointer === null) return\n            const id = pointer\n            pointer = null\n            if (area.hasPointerCapture(id)) area.releasePointerCapture(id)\n            finish()\n        }\n        listen(area, 'pointerdown', (event) => {\n            const e = event as PointerEvent\n            if (\n                !editable() ||\n                e.defaultPrevented ||\n                e.button !== 0 ||\n                !e.isPrimary\n            )\n                return\n            e.preventDefault()\n            area.focus()\n            interaction = value\n            pointer = e.pointerId\n            area.setPointerCapture(pointer)\n            apply(e)\n        })\n        listen(area, 'pointermove', (event) => {\n            const e = event as PointerEvent\n            if (editable() && e.pointerId === pointer) apply(e)\n        })\n        for (const type of ['pointerup', 'pointercancel', 'lostpointercapture'])\n            listen(area, type, (event) => {\n                if ((event as PointerEvent).pointerId === pointer) release()\n            })\n        cleanups.push(() => {\n            interaction = null\n            release()\n        })\n        listen(area, 'keydown', (event) => {\n            const e = event as KeyboardEvent\n            if (!editable() || e.defaultPrevented) return\n            const [h, oldS, oldV] = toSpace(color, 'hsv')\n            let s = oldS,\n                v = oldV\n            const step = e.shiftKey ? 10 : 1\n            if (e.key === 'ArrowLeft') s -= step\n            else if (e.key === 'ArrowRight') s += step\n            else if (e.key === 'ArrowUp') v += step\n            else if (e.key === 'ArrowDown') v -= step\n            else if (e.key === 'Home') s = 0\n            else if (e.key === 'End') s = 100\n            else if (e.key === 'PageUp') v = 100\n            else if (e.key === 'PageDown') v = 0\n            else return\n            e.preventDefault()\n            change({\n                space: 'hsv',\n                channels: [h, clamp(s, 0, 100), clamp(v, 0, 100)],\n                alpha: color.alpha,\n            })\n        })\n    }\n    for (const item of items)\n        listen(item, 'click', (event) => {\n            if (!editable() || item.disabled || event.defaultPrevented) return\n            const next = parseColor(item.dataset.value)\n            if (next) change(next)\n        })\n    for (const group of parts('color-picker-swatches')) {\n        const buttons = items.filter((item) => group.contains(item))\n        listen(group, 'keydown', (event) => {\n            const e = event as KeyboardEvent\n            const available = buttons.filter((button) => !button.disabled)\n            const index = available.indexOf(e.target as HTMLButtonElement)\n            if (index < 0 || e.defaultPrevented) return\n            const rtl = getComputedStyle(group).direction === 'rtl'\n            let target: HTMLButtonElement | undefined\n            if (e.key === 'Home') target = available[0]\n            else if (e.key === 'End') target = available.at(-1)\n            else if (\n                e.key === 'ArrowDown' ||\n                e.key === (rtl ? 'ArrowLeft' : 'ArrowRight')\n            )\n                target = available[index + 1]\n            else if (\n                e.key === 'ArrowUp' ||\n                e.key === (rtl ? 'ArrowRight' : 'ArrowLeft')\n            )\n                target = available[index - 1]\n            else return\n            e.preventDefault()\n            target?.focus()\n        })\n    }\n    const reset = observeFormReset({\n        root,\n        getForm: () => formInput?.form ?? null,\n        onReset: () => {\n            interaction = null\n            for (const [field, format] of formats) {\n                field.dataset.format = format\n                const menu = field.querySelector<HTMLSelectElement>(\n                    '[data-color-picker-format]',\n                )\n                if (menu) menu.value = format\n                for (const group of field.querySelectorAll<HTMLElement>(\n                    '[data-color-picker-channels]',\n                ))\n                    group.hidden = group.dataset.format !== format\n            }\n            set(initial, true)\n            if (status) status.textContent = ''\n        },\n    })\n    cleanups.push(() => reset.destroy())\n    paint()\n    // Reuse the data-slot popup behavior without adding another root wrapper.\n    if (trigger && content) popover = createPopover(root)\n    const controller: ColorPickerController = {\n        getValue: () => value,\n        setColor(text, options) {\n            const next = parseColor(text)\n            if (!next || destroyed) return false\n            if (options?.silent) set(next, true)\n            else change(next)\n            return true\n        },\n        destroy() {\n            if (destroyed) return\n            destroyed = true\n            popover?.destroy()\n            for (const cleanup of cleanups) cleanup()\n            if (focusTarget) {\n                focusTarget.id = oldTargetId ?? ''\n                root.id = fieldId\n            }\n            clearRootBinding(root, ROOT_SLOT, controller)\n        },\n    }\n    cleanups.push(\n        onRoot(root, 'color-picker:set', (event) => {\n            const command = (event as CustomEvent<{ value?: unknown }>).detail\n            if (typeof command?.value === 'string')\n                controller.setColor(command.value, { silent: true })\n        }),\n    )\n    return setRootBinding(root, ROOT_SLOT, controller)\n}\n",
      "type": "registry:file",
      "target": "~/src/components/ui/color-picker/color-picker.ts"
    },
    {
      "path": "packages/ui/src/components/ui/color-picker/index.ts",
      "content": "export { default as ColorPicker } from './color-picker.astro'\nexport { default as ColorPickerTrigger } from './color-picker-trigger.astro'\nexport { default as ColorPickerInput } from './color-picker-input.astro'\nexport { default as ColorPickerContent } from './color-picker-content.astro'\nexport { default as ColorPickerPanel } from './color-picker-panel.astro'\nexport { default as ColorPickerArea } from './color-picker-area.astro'\nexport { default as ColorPickerSlider } from './color-picker-slider.astro'\nexport { default as ColorPickerChannelInput } from './color-picker-channel-input.astro'\nexport { default as ColorPickerFields } from './color-picker-fields.astro'\nexport { default as ColorPickerSwatch } from './color-picker-swatch.astro'\nexport { default as ColorPickerValue } from './color-picker-value.astro'\nexport { default as ColorPickerSwatches } from './color-picker-swatches.astro'\nexport { default as ColorPickerSwatchItem } from './color-picker-swatch-item.astro'\n\nexport { create, createColorPicker } from './color-picker.ts'\nexport type { ColorPickerController } from './color-picker.ts'\nexport { parseColor, formatColor, isColorInSrgb } from './color-picker-color.ts'\nexport type * from './types.ts'\n",
      "type": "registry:file",
      "target": "~/src/components/ui/color-picker/index.ts"
    },
    {
      "path": "packages/ui/src/components/ui/color-picker/types.ts",
      "content": "import type { PopoverContentProps } from '../popover/types.ts'\n\n/** The output color format. */\nexport type ColorPickerFormat = 'hex' | 'rgb' | 'hsl' | 'hsb' | 'oklch'\n\n/** Where channels live. HSB is `hsv` here, after the math. */\nexport type ColorPickerColorSpace = 'rgb' | 'hsl' | 'hsv' | 'oklch'\n\n/** A channel that a slider can change. */\nexport type ColorPickerChannel =\n    | 'hue'\n    | 'saturation'\n    | 'brightness'\n    | 'lightness'\n    | 'chroma'\n    | 'red'\n    | 'green'\n    | 'blue'\n    | 'alpha'\n\n/**\n * A parsed color. Channels stay in the space they were given or edited in,\n * so the hue of a gray and an OKLCH color outside sRGB survive a round trip.\n * rgb runs 0 to 255; hsl and hsv take hue 0 to 360 and the rest 0 to 100;\n * oklch takes lightness 0 to 100, chroma 0 to 0.4 and hue 0 to 360. Alpha is\n * 0 to 1.\n */\nexport type ColorPickerColor = {\n    space: ColorPickerColorSpace\n    channels: [number, number, number]\n    alpha: number\n}\n\n/** Shared state for composed color picker parts. HTML attributes pass through. */\nexport interface ColorPickerProps {\n    /** Initial CSS color. @default \"#000000\" */\n    defaultValue?: string\n    /** Output format for events and form submission. @default \"hex\" */\n    format?: ColorPickerFormat\n    /** Permit transparency. @default false */\n    alpha?: boolean\n    /** Disable all controls. @default false */\n    disabled?: boolean\n    /** Show the color without permitting changes. @default false */\n    readOnly?: boolean\n    /** Accessible name for the picker. @default \"Choose a color\" */\n    label?: string\n    /** Name of the hidden form field. */\n    name?: string\n    /** ID of an external form. */\n    form?: string\n}\n\n/** Placement options for the popup. */\nexport type ColorPickerContentProps = PopoverContentProps\n\n/** Options for a color channel slider. */\nexport interface ColorPickerSliderProps {\n    /** Channel to change. @default \"hue\" */\n    channel?: ColorPickerChannel\n    /** Color space for the channel. Defaults to the channel's native space. */\n    colorSpace?: ColorPickerColorSpace\n}\n\n/** Options for a single channel field. */\nexport interface ColorPickerChannelInputProps {\n    /** Channel to change, or the hex digits. @default \"hex\" */\n    channel?: ColorPickerChannel | 'hex'\n    /** Color space for the channel. Defaults to the channel's native space. */\n    colorSpace?: ColorPickerColorSpace\n}\n\n/** Options for the joined channel fields. */\nexport interface ColorPickerFieldsProps {\n    /** Initial display format. Independent of the output format. @default \"hex\" */\n    defaultFormat?: ColorPickerFormat\n    /** Formats available in the menu. @default [\"hex\", \"rgb\", \"hsl\", \"hsb\", \"oklch\"] */\n    formats?: readonly ColorPickerFormat[]\n}\n\n/** One color in a swatch group. */\nexport interface ColorPickerSwatchItemProps {\n    /** CSS color to select. */\n    value: string\n    /** Accessible name. Defaults to the color value. */\n    label?: string\n}\n\n/** Optional colors for the swatch group. A slot can supply individual items. */\nexport interface ColorPickerSwatchesProps {\n    /** CSS colors to show. @default [] */\n    colors?: readonly string[]\n}\n\n/** Detail for bubbling color-picker:change and color-picker:commit events. */\nexport interface ColorPickerChangeDetail {\n    /** ID of the main input or trigger. */\n    id: string\n    /** Form field name, or an empty string. */\n    name: string\n    /** Color in the root's output format. */\n    value: string\n    /** Equivalent hex color, with alpha when needed. */\n    hex: string\n    /** Equivalent OKLCH color. Preserves wide-gamut values. */\n    oklch: string\n    /** Hue, saturation, and lightness. */\n    hsl: [number, number, number]\n}\n",
      "type": "registry:file",
      "target": "~/src/components/ui/color-picker/types.ts"
    }
  ],
  "meta": {
    "framework": "astro",
    "source": "@gnostic/ui",
    "testedDependencies": {
      "@data-slot/core": "^1.0.2",
      "@data-slot/popover": "^1.1.2",
      "@lucide/astro": "^1.68.0",
      "cn": "0.5.2"
    }
  },
  "docs": "https://ui.gnosticai.com/components/color-picker",
  "categories": [
    "ui"
  ],
  "type": "registry:ui"
}
