{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "camera-shutter",
  "title": "Camera Shutter",
  "author": "VenusUI",
  "description": "A lens with a working iris: blades close to the chosen aperture and snap shut when you release the shutter.",
  "files": [
    {
      "path": "registry/default/ui/camera-shutter.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface CameraShutterProps extends Omit<React.ComponentProps<\"div\">, \"onChange\"> {\n  /** Available apertures, widest first, as f-numbers. */\n  stops?: number[]\n  defaultStop?: number\n  /** Engraved on the lens ring. */\n  lensLabel?: string\n  onStopChange?: (stop: number) => void\n  /** Called when the shutter fires, with the aperture and the running shot count. */\n  onCapture?: (shot: { stop: number; count: number }) => void\n}\n\nconst BLADES = 9\nconst CENTER = 100\nconst RIM = 74\nconst MIN_HOLE = 2\nconst MAX_HOLE = 66\n\ntype Point = [number, number]\nconst fixed = (value: number) => value.toFixed(2)\n\nfunction rimHit(from: Point, to: Point): Point {\n  const dx = to[0] - from[0]\n  const dy = to[1] - from[1]\n  const length = Math.hypot(dx, dy) || 1\n  const [ux, uy] = [dx / length, dy / length]\n  const [ox, oy] = [from[0] - CENTER, from[1] - CENTER]\n  const b = ox * ux + oy * uy\n  const t = -b + Math.sqrt(Math.max(0, b * b - (ox * ox + oy * oy - RIM * RIM)))\n  return [from[0] + ux * t, from[1] + uy * t]\n}\n\n/** One path per blade for an opening from 0 (shut) to 1 (wide open). */\nfunction bladePaths(opening: number) {\n  const hole = MIN_HOLE + (MAX_HOLE - MIN_HOLE) * opening\n  const twist = (1 - opening) * 1.05\n  const corners = Array.from({ length: BLADES }, (_, i): Point => {\n    const angle = twist + (i * Math.PI * 2) / BLADES\n    return [CENTER + hole * Math.cos(angle), CENTER + hole * Math.sin(angle)]\n  })\n  const at = (i: number) => corners[(i + BLADES) % BLADES]\n  const edge = corners.map((corner, i) => rimHit(at(i - 1), corner))\n  return corners.map((corner, i) => {\n    const next = at(i + 1)\n    const nextEdge = edge[(i + 1) % BLADES]\n    return `M${fixed(corner[0])} ${fixed(corner[1])}L${fixed(next[0])} ${fixed(next[1])}L${fixed(nextEdge[0])} ${fixed(nextEdge[1])}A${RIM} ${RIM} 0 0 0 ${fixed(edge[i][0])} ${fixed(edge[i][1])}Z`\n  })\n}\n\n/**\n * A lens with a working iris. Pick an aperture and the blades close down to\n * it; press the shutter and they snap shut and open again with a flash.\n */\nfunction CameraShutter({\n  stops = [1.8, 2.8, 4, 5.6, 8, 11, 16],\n  defaultStop,\n  lensLabel = \"50mm 1:1.8\",\n  onStopChange,\n  onCapture,\n  className,\n  ...props\n}: CameraShutterProps) {\n  const openingFor = React.useCallback((stop: number) => stops[0] / stop, [stops])\n  const [stop, setStop] = React.useState(defaultStop ?? stops[2] ?? stops[0])\n  const [opening, setOpening] = React.useState(() => openingFor(defaultStop ?? stops[2] ?? stops[0]))\n  const [count, setCount] = React.useState(0)\n  const [flash, setFlash] = React.useState(false)\n  const current = React.useRef(opening)\n  const frame = React.useRef(0)\n  const timer = React.useRef<ReturnType<typeof setTimeout>>(undefined)\n  const busy = React.useRef(false)\n  const id = React.useId().replace(/[^a-zA-Z0-9]/g, \"\")\n\n  React.useEffect(\n    () => () => {\n      cancelAnimationFrame(frame.current)\n      clearTimeout(timer.current)\n    },\n    []\n  )\n\n  const moveTo = (target: number, duration: number, done?: () => void) => {\n    cancelAnimationFrame(frame.current)\n    const from = current.current\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n    if (reduced) {\n      current.current = target\n      setOpening(target)\n      done?.()\n      return\n    }\n    let start: number | undefined\n    const step = (now: number) => {\n      start ??= now\n      const progress = Math.min(1, (now - start) / duration)\n      const value = from + (target - from) * (1 - (1 - progress) ** 3)\n      current.current = value\n      setOpening(value)\n      if (progress < 1) frame.current = requestAnimationFrame(step)\n      else done?.()\n    }\n    frame.current = requestAnimationFrame(step)\n  }\n\n  const chooseStop = (next: number) => {\n    setStop(next)\n    onStopChange?.(next)\n    if (!busy.current) moveTo(openingFor(next), 320)\n  }\n\n  const fire = () => {\n    if (busy.current) return\n    busy.current = true\n    moveTo(0, 90, () => {\n      setFlash(true)\n      const nextCount = count + 1\n      setCount(nextCount)\n      onCapture?.({ stop, count: nextCount })\n      timer.current = setTimeout(() => {\n        setFlash(false)\n        moveTo(openingFor(stop), 240, () => {\n          busy.current = false\n        })\n      }, 90)\n    })\n  }\n\n  const blades = bladePaths(opening)\n\n  return (\n    <div data-slot=\"camera-shutter\" className={cn(\"flex w-72 max-w-full flex-col items-center gap-5\", className)} {...props}>\n      <div className=\"relative aspect-square w-full rounded-full bg-[radial-gradient(circle_at_35%_28%,#3f3f46,#18181b_62%,#09090b)] shadow-[0_18px_40px_-14px_rgb(0_0_0/0.6),inset_0_1px_1px_rgb(255_255_255/0.2)]\">\n        <svg viewBox=\"0 0 200 200\" role=\"img\" aria-label={`Lens iris set to f/${stop}`} className=\"size-full\">\n          <defs>\n            <radialGradient id={`${id}-glass`} cx=\"42%\" cy=\"36%\" r=\"72%\">\n              <stop offset=\"0\" stopColor=\"#6d5bd0\" />\n              <stop offset=\"0.42\" stopColor=\"#123a4c\" />\n              <stop offset=\"1\" stopColor=\"#030712\" />\n            </radialGradient>\n            <path id={`${id}-ring`} d=\"M100 12a88 88 0 1 1-.01 0\" />\n          </defs>\n          {Array.from({ length: 72 }, (_, i) => (\n            <line key={i} x1=\"100\" y1=\"3\" x2=\"100\" y2={i % 6 === 0 ? 8 : 6} stroke=\"#71717a\" strokeWidth=\"0.7\" transform={`rotate(${i * 5} 100 100)`} />\n          ))}\n          <text fill=\"#d4d4d8\" fontSize=\"7\" letterSpacing=\"2.4\" fontFamily=\"ui-monospace, monospace\">\n            <textPath href={`#${id}-ring`} startOffset=\"3%\">\n              {lensLabel}\n            </textPath>\n          </text>\n          <circle cx=\"100\" cy=\"100\" r=\"80\" fill=\"#0a0a0b\" stroke=\"#3f3f46\" strokeWidth=\"1.5\" />\n          <circle cx=\"100\" cy=\"100\" r={RIM} fill={`url(#${id}-glass)`} />\n          <ellipse cx=\"78\" cy=\"72\" rx=\"15\" ry=\"8\" fill=\"white\" opacity=\"0.2\" transform=\"rotate(-32 78 72)\" />\n          {blades.map((d, i) => (\n            <path key={i} d={d} fill={i % 2 ? \"#1c1c20\" : \"#232328\"} stroke=\"#44444c\" strokeWidth=\"0.5\" strokeLinejoin=\"round\" />\n          ))}\n          <circle cx=\"100\" cy=\"100\" r={RIM} fill=\"none\" stroke=\"#000\" strokeWidth=\"2\" />\n        </svg>\n        <span aria-hidden=\"true\" className={cn(\"pointer-events-none absolute inset-0 rounded-full bg-white transition-opacity\", flash ? \"opacity-90 duration-75\" : \"opacity-0 duration-300\")} />\n      </div>\n\n      <fieldset className=\"w-full\">\n        <legend className=\"sr-only\">Aperture</legend>\n        <div className=\"flex flex-wrap justify-center gap-1\">\n          {stops.map((value) => (\n            <label key={value} className=\"cursor-pointer\">\n              <input type=\"radio\" name={`${id}-stop`} className=\"peer sr-only\" checked={stop === value} onChange={() => chooseStop(value)} />\n              <span className=\"block rounded-md border px-2 py-1 font-mono text-xs text-muted-foreground transition-colors peer-checked:border-foreground peer-checked:bg-foreground peer-checked:text-background peer-focus-visible:ring-3 peer-focus-visible:ring-ring/50\">\n                f/{value}\n              </span>\n            </label>\n          ))}\n        </div>\n      </fieldset>\n\n      <div className=\"flex items-center gap-3\">\n        <button\n          type=\"button\"\n          onClick={fire}\n          aria-label=\"Release the shutter\"\n          className=\"grid size-14 place-items-center rounded-full border-4 border-foreground/80 outline-none transition-transform active:scale-90 focus-visible:ring-3 focus-visible:ring-ring/50 motion-reduce:transition-none\"\n        >\n          <span aria-hidden=\"true\" className=\"size-9 rounded-full bg-red-600 shadow-[inset_0_-3px_5px_rgb(0_0_0/0.3)]\" />\n        </button>\n        <p aria-live=\"polite\" className=\"w-20 font-mono text-xs text-muted-foreground tabular-nums\">\n          {count} {count === 1 ? \"shot\" : \"shots\"}\n        </p>\n      </div>\n    </div>\n  )\n}\n\nexport { CameraShutter }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "interactive",
    "animations"
  ],
  "type": "registry:ui"
}