{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "thermostat",
  "title": "Thermostat",
  "author": "VenusUI",
  "description": "A round thermostat whose ring glows warm when heating and cool when cooling.",
  "dependencies": [
    "lucide-react"
  ],
  "files": [
    {
      "path": "registry/default/ui/thermostat.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Flame, Snowflake } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface ThermostatProps extends Omit<React.ComponentProps<\"div\">, \"onChange\"> {\n  min?: number\n  max?: number\n  defaultValue?: number\n  /** The room's current temperature. */\n  current?: number\n  unit?: string\n  onValueChange?: (value: number) => void\n}\n\nconst SWEEP = 270\nconst START = 135\n\nfunction arc(from: number, to: number, r: number) {\n  const point = (deg: number) => [100 + r * Math.cos((deg * Math.PI) / 180), 100 + r * Math.sin((deg * Math.PI) / 180)]\n  const [x1, y1] = point(from)\n  const [x2, y2] = point(to)\n  return `M${x1.toFixed(2)} ${y1.toFixed(2)}A${r} ${r} 0 ${to - from > 180 ? 1 : 0} 1 ${x2.toFixed(2)} ${y2.toFixed(2)}`\n}\n\n/**\n * A round thermostat. Drag around the ring, scroll, or use the arrow keys to\n * set the temperature; the ring glows warm when it's heating and cool when\n * it's cooling.\n */\nfunction Thermostat({ min = 10, max = 30, defaultValue = 21, current = 19, unit = \"°C\", onValueChange, className, ...props }: ThermostatProps) {\n  const [value, setValue] = React.useState(defaultValue)\n  const dragging = React.useRef(false)\n  const share = (value - min) / (max - min)\n  const mode = value > current + 0.4 ? \"heat\" : value < current - 0.4 ? \"cool\" : \"hold\"\n  const color = mode === \"heat\" ? \"#f97316\" : mode === \"cool\" ? \"#38bdf8\" : \"#a3a3a3\"\n\n  const set = (next: number) => {\n    const clamped = Math.round(Math.min(max, Math.max(min, next)) * 2) / 2\n    setValue(clamped)\n    onValueChange?.(clamped)\n  }\n\n  const fromPointer = (event: React.PointerEvent<HTMLDivElement>) => {\n    const box = event.currentTarget.getBoundingClientRect()\n    let deg = (Math.atan2(event.clientY - (box.top + box.height / 2), event.clientX - (box.left + box.width / 2)) * 180) / Math.PI\n    deg = (deg - START + 360) % 360\n    if (deg > SWEEP) deg = deg > SWEEP + 45 ? 0 : SWEEP\n    set(min + (deg / SWEEP) * (max - min))\n  }\n\n  return (\n    <div data-slot=\"thermostat\" className={cn(\"w-64 max-w-full\", className)} {...props}>\n      <div\n        role=\"slider\"\n        tabIndex={0}\n        aria-label=\"Target temperature\"\n        aria-valuemin={min}\n        aria-valuemax={max}\n        aria-valuenow={value}\n        aria-valuetext={`${value}${unit}, ${mode === \"heat\" ? \"heating\" : mode === \"cool\" ? \"cooling\" : \"holding\"}`}\n        onPointerDown={(event) => {\n          event.currentTarget.setPointerCapture(event.pointerId)\n          dragging.current = true\n          fromPointer(event)\n        }}\n        onPointerMove={(event) => dragging.current && fromPointer(event)}\n        onPointerUp={() => (dragging.current = false)}\n        onWheel={(event) => set(value - Math.sign(event.deltaY) * 0.5)}\n        onKeyDown={(event) => {\n          const moves: Record<string, number> = { ArrowUp: 0.5, ArrowRight: 0.5, ArrowDown: -0.5, ArrowLeft: -0.5, PageUp: 2, PageDown: -2 }\n          const move = moves[event.key]\n          if (move === undefined) return\n          event.preventDefault()\n          set(value + move)\n        }}\n        className=\"relative aspect-square cursor-pointer touch-none rounded-full bg-[radial-gradient(circle_at_50%_35%,#3f3f46,#18181b_70%)] shadow-[0_18px_30px_-12px_rgb(0_0_0/0.6),inset_0_0_0_8px_#27272a,inset_0_2px_0_rgb(255_255_255/0.15)] outline-none select-none focus-visible:ring-4 focus-visible:ring-ring/60\"\n      >\n        <span aria-hidden=\"true\" className=\"absolute inset-[12%] rounded-full transition-[box-shadow] duration-500\" style={{ boxShadow: `0 0 50px 4px ${color}55` }} />\n        <svg viewBox=\"0 0 200 200\" aria-hidden=\"true\" className=\"absolute inset-0 size-full\">\n          {Array.from({ length: 41 }, (_, i) => {\n            const deg = START + (i / 40) * SWEEP\n            const r1 = 82\n            const r2 = i % 5 === 0 ? 72 : 76\n            const lit = i / 40 <= share\n            return (\n              <line\n                key={i}\n                x1={(100 + r1 * Math.cos((deg * Math.PI) / 180)).toFixed(2)}\n                y1={(100 + r1 * Math.sin((deg * Math.PI) / 180)).toFixed(2)}\n                x2={(100 + r2 * Math.cos((deg * Math.PI) / 180)).toFixed(2)}\n                y2={(100 + r2 * Math.sin((deg * Math.PI) / 180)).toFixed(2)}\n                stroke={lit ? color : \"#52525b\"}\n                strokeWidth=\"2\"\n                strokeLinecap=\"round\"\n              />\n            )\n          })}\n          <path d={arc(START, START + SWEEP * share, 90)} stroke={color} strokeWidth=\"5\" strokeLinecap=\"round\" fill=\"none\" />\n          <circle cx={(100 + 90 * Math.cos(((START + SWEEP * share) * Math.PI) / 180)).toFixed(2)} cy={(100 + 90 * Math.sin(((START + SWEEP * share) * Math.PI) / 180)).toFixed(2)} r=\"7\" fill=\"#fafafa\" />\n        </svg>\n        <div className=\"absolute inset-0 flex flex-col items-center justify-center text-white\">\n          <span className=\"text-xs tracking-widest text-neutral-400 uppercase\">{mode === \"heat\" ? \"Heating to\" : mode === \"cool\" ? \"Cooling to\" : \"Holding\"}</span>\n          <span className=\"font-mono text-5xl font-light tabular-nums\">\n            {value.toFixed(1)}\n            <span className=\"text-lg\">{unit}</span>\n          </span>\n          <span className=\"mt-1 flex items-center gap-1 text-xs text-neutral-400\">\n            {mode === \"heat\" ? <Flame aria-hidden=\"true\" className=\"size-3.5 text-orange-400\" /> : mode === \"cool\" ? <Snowflake aria-hidden=\"true\" className=\"size-3.5 text-sky-300\" /> : null}\n            Inside {current}\n            {unit}\n          </span>\n        </div>\n      </div>\n    </div>\n  )\n}\n\nexport { Thermostat }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "inputs",
    "interactive"
  ],
  "type": "registry:ui"
}