{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tape-measure",
  "title": "Tape Measure",
  "author": "VenusUI",
  "description": "A retractable tape measure: pull the tab out to read a length, and it snaps back unless locked.",
  "dependencies": [
    "lucide-react"
  ],
  "files": [
    {
      "path": "registry/default/ui/tape-measure.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Lock, LockOpen } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface TapeMeasureProps extends Omit<React.ComponentProps<\"div\">, \"onChange\"> {\n  /** Longest the tape goes, in units. */\n  max?: number\n  unit?: \"cm\" | \"in\"\n  /** Pixels per unit on screen. */\n  scale?: number\n  onMeasure?: (length: number) => void\n}\n\n/**\n * A retractable tape measure. Pull the tab to draw out the tape and read the\n * length; let go and it snaps back, unless you lock it. The tab is a slider,\n * so the arrow keys work too.\n */\nfunction TapeMeasure({ max = 30, unit = \"cm\", scale = 14, onMeasure, className, ...props }: TapeMeasureProps) {\n  const [length, setLength] = React.useState(0)\n  const [locked, setLocked] = React.useState(false)\n  const [dragging, setDragging] = React.useState(false)\n  const start = React.useRef({ x: 0, length: 0 })\n  const step = unit === \"cm\" ? 0.1 : 0.125\n\n  const set = (next: number) => {\n    const value = Math.round(Math.min(max, Math.max(0, next)) / step) * step\n    setLength(value)\n    onMeasure?.(value)\n  }\n\n  const release = () => {\n    setDragging(false)\n    if (!locked) set(0)\n  }\n\n  const ticks = Array.from({ length: max + 1 }, (_, i) => i)\n\n  return (\n    <div data-slot=\"tape-measure\" className={cn(\"w-full max-w-xl\", className)} {...props}>\n      <div className=\"flex items-center\">\n        {/* The case */}\n        <div className=\"relative z-10 grid size-28 shrink-0 place-items-center rounded-[1.6rem] bg-linear-145 from-amber-300 via-amber-400 to-amber-600 shadow-[0_12px_20px_-10px_rgb(0_0_0/0.55),inset_0_2px_0_rgb(255_255_255/0.5)]\">\n          <span aria-hidden=\"true\" className=\"grid size-16 place-items-center rounded-full bg-neutral-900 shadow-[inset_0_2px_6px_rgb(0_0_0/0.6)]\">\n            <span className=\"size-6 rounded-full bg-linear-145 from-neutral-300 to-neutral-500\" />\n          </span>\n          <button\n            type=\"button\"\n            aria-pressed={locked}\n            aria-label={locked ? \"Unlock the tape\" : \"Lock the tape\"}\n            onClick={() => {\n              setLocked(!locked)\n              if (locked && !dragging) set(0)\n            }}\n            className=\"absolute -top-2 left-1/2 grid h-5 w-9 -translate-x-1/2 place-items-center rounded-full bg-neutral-900 text-amber-300 outline-none focus-visible:ring-3 focus-visible:ring-ring/50\"\n          >\n            {locked ? <Lock aria-hidden=\"true\" className=\"size-3\" /> : <LockOpen aria-hidden=\"true\" className=\"size-3\" />}\n          </button>\n        </div>\n\n        {/* The tape */}\n        <div className=\"relative -ml-2 h-9 min-w-0 flex-1 overflow-hidden\">\n          <div\n            aria-hidden=\"true\"\n            className={cn(\"absolute top-1.5 left-0 h-6 overflow-hidden bg-yellow-300 shadow-[inset_0_-2px_0_rgb(0_0_0/0.15)]\", !dragging && \"transition-[width] duration-500 ease-[cubic-bezier(.2,1.3,.4,1)] motion-reduce:transition-none\")}\n            style={{ width: length * scale }}\n          >\n            {ticks.map((i) => (\n              <span key={i} className=\"absolute top-0 flex flex-col items-start\" style={{ left: i * scale }}>\n                <span className={cn(\"w-px bg-neutral-900\", i % 5 === 0 ? \"h-3\" : \"h-2\")} />\n                {i % 5 === 0 && i > 0 ? <span className=\"-ml-1 font-mono text-[8px] leading-none font-bold text-neutral-900\">{i}</span> : null}\n              </span>\n            ))}\n          </div>\n          <button\n            type=\"button\"\n            role=\"slider\"\n            aria-label=\"Tape length\"\n            aria-valuemin={0}\n            aria-valuemax={max}\n            aria-valuenow={Number(length.toFixed(2))}\n            aria-valuetext={`${length.toFixed(1)} ${unit}`}\n            onPointerDown={(event) => {\n              event.currentTarget.setPointerCapture(event.pointerId)\n              start.current = { x: event.clientX, length }\n              setDragging(true)\n            }}\n            onPointerMove={(event) => dragging && set(start.current.length + (event.clientX - start.current.x) / scale)}\n            onPointerUp={release}\n            onPointerCancel={release}\n            onKeyDown={(event) => {\n              const moves: Record<string, number> = { ArrowRight: 1, ArrowUp: 1, ArrowLeft: -1, ArrowDown: -1, PageUp: 5, PageDown: -5 }\n              if (event.key === \"Home\") return set(0)\n              const move = moves[event.key]\n              if (move === undefined) return\n              event.preventDefault()\n              set(length + move)\n            }}\n            className={cn(\"absolute top-0 h-9 w-4 cursor-grab touch-none rounded-r-sm bg-linear-to-b from-neutral-300 to-neutral-500 shadow outline-none focus-visible:ring-3 focus-visible:ring-ring/50 active:cursor-grabbing\", !dragging && \"transition-[left] duration-500 ease-[cubic-bezier(.2,1.3,.4,1)] motion-reduce:transition-none\")}\n            style={{ left: length * scale }}\n          />\n        </div>\n      </div>\n      <p aria-live=\"polite\" className=\"mt-4 text-center font-mono text-sm tabular-nums\">\n        <span className=\"text-2xl font-semibold\">{length.toFixed(1)}</span> {unit}\n        <span className=\"ml-3 text-xs text-muted-foreground\">{locked ? \"locked\" : length ? \"let go to retract\" : \"pull the tab\"}</span>\n      </p>\n    </div>\n  )\n}\n\nexport { TapeMeasure }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "inputs",
    "interactive"
  ],
  "type": "registry:ui"
}