{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"camera-key","type":"registry:component","title":"Camera key","description":"The camera button of a call, built as a lens: seven aperture blades spiral open to show you and shut over you, so nobody wonders if their camera is on.","author":"Hairline UI","dependencies":[],"files":[{"path":"registry/camera-key.tsx","type":"registry:component","content":"// Hairline UI · camera-key · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n\"use client\";\n\n/* ─────────────────────────────────────────────────────────\n * CAMERA KEY: the camera button of a call, as a lens\n *\n *   off       a glass lens in a soft key, its seven aperture\n *             blades shut. Hover and they part a hair, as if\n *             waiting to look\n *   starting  while your onToggle asks for the camera, the\n *             blades open a crack and hunt back and forth, and\n *             the light beside the lens glows amber\n *   on        the blades spiral open, each on its own spring,\n *             and you appear in the lens over-bright and soft,\n *             then the picture finds its exposure and focus\n *             (it hunts once, like a real lens). The light turns\n *             green\n *   off again the blades spiral shut over you, the picture\n *             darkening as the light is cut, and meet with a\n *             small knock that the key feels\n *   blocked   if onToggle throws, the blades open a little and\n *             jam: they rattle, the key shakes, the light\n *             blinks red and they fall shut. The reason is the\n *             label\n *\n * Click as fast as you like: every blade keeps its speed when\n * it is turned round, so a closing iris opens again from\n * wherever it got to. The lens catches the light where your\n * pointer is.\n *\n * One line in your app: <CameraKey stream={stream}\n * onToggle={(on) => (on ? startCamera() : stopCamera())} />.\n * Your camera, your stream; the key only shows it.\n * ───────────────────────────────────────────────────────── */\n\nimport * as React from \"react\";\nimport { EASE_OUT, INTERACTION_FOCUS, createSpring, type Spring } from \"./ui-interaction-motion\";\nimport { playSound } from \"./ui-sounds\";\n\nexport type CameraKeyStatus = \"off\" | \"starting\" | \"on\" | \"blocked\";\n\nexport interface CameraKeyProps {\n  /** Controlled: whether the camera is on. */\n  on?: boolean;\n  /** Uncontrolled: whether it starts on. */\n  defaultOn?: boolean;\n  /** Start or stop your camera. Resolve when it is running (or stopped); throw an Error to show why it can't start. */\n  onToggle?: (next: boolean) => unknown | Promise<unknown>;\n  /** Every change between on and off. */\n  onOnChange?: (on: boolean) => void;\n  /** Your camera's stream, shown in the lens while it is on. */\n  stream?: MediaStream | null;\n  /** A picture to show in the lens instead of a stream (a placeholder or a still of the last frame). */\n  poster?: string;\n  /** Show the picture mirrored, as people expect to see themselves. */\n  mirror?: boolean;\n  /** The key's size in px. Everything is drawn to scale. */\n  size?: number;\n  /** Show the state under the key. */\n  showLabel?: boolean;\n  labels?: Partial<Record<\"off\" | \"starting\" | \"on\" | \"blocked\", string>>;\n  disabled?: boolean;\n  /** Soft synthesised sounds as the blades open, meet, or jam. */\n  sound?: boolean;\n  onStatusChange?: (status: CameraKeyStatus) => void;\n  className?: string;\n}\n\n// The iris, in a 100-unit drawing: seven blades pinned round a rim under the bezel.\nconst N = 7;\nconst STEP = (Math.PI * 2) / N;\nconst BASE = -Math.PI / 2;\nconst LENS = 31; // the glass you see, inside the bezel\nconst RIM = 40; // where the blades are pinned, hidden under the bezel\nconst OPEN = 33.5; // a blade's edge this far out is out of sight\nconst TWIST = 0.62; // how far the blades turn as they close (radians)\nconst SIDE_BOW = 0.3; // the cut of each blade, so the opening is round rather than a polygon\nconst LEAD_BOW = 0.1; // the slight curve of each blade's long edge\nconst LED_ANGLE = -0.72;\nconst LIGHT = (-3 * Math.PI) / 4; // where the light comes from: the top left // where the light sits on the key (radians, from three o'clock)\n\n// Springs. The blades are a little different from each other, so they ripple round the ring.\nconst bladeSpring = (k: number) => {\n  const stiffness = 250 + k * 11;\n  return { stiffness, damping: 2 * 0.64 * Math.sqrt(stiffness) };\n};\nconst PRESS = { stiffness: 620, damping: 30 };\nconst TILT = { stiffness: 170, damping: 20 };\nconst FOCUS = { stiffness: 90, damping: 9 }; // under-damped: the picture overshoots into focus and back, once\nconst LIVE = { stiffness: 140, damping: 24 };\nconst RATTLE = { stiffness: 1100, damping: 9 };\n\nconst clamp = (n: number, lo: number, hi: number) => (n < lo ? lo : n > hi ? hi : n);\n\nconst reducedQuery = \"(prefers-reduced-motion: reduce)\";\nconst subscribeReduced = (onChange: () => void) => {\n  const query = window.matchMedia(reducedQuery);\n  query.addEventListener(\"change\", onChange);\n  return () => query.removeEventListener(\"change\", onChange);\n};\nconst useReducedMotion = () => React.useSyncExternalStore(subscribeReduced, () => window.matchMedia(reducedQuery).matches, () => false);\n\ntype Springs = {\n  blades: Spring[];\n  press: Spring;\n  tiltX: Spring;\n  tiltY: Spring;\n  focus: Spring;\n  live: Spring;\n  rattle: Spring;\n};\n\ntype P = { x: number; y: number };\nconst f = (n: number) => n.toFixed(2);\nconst pt = (p: P) => `${f(p.x)} ${f(p.y)}`;\n\n/** The iris for seven blade openings (0 shut, 1 open): each blade's outline, its lit edge, and the shadow it throws. */\nfunction irisPaths(open: number[], rattle: number) {\n  const lines = open.map((a, k) => {\n    const o = clamp(a, 0, 1.08);\n    const phi = BASE + k * STEP + (1 - clamp(o, 0, 1)) * TWIST + rattle;\n    return { d: Math.max(0, o) * OPEN, n: { x: Math.cos(phi), y: Math.sin(phi) }, t: { x: -Math.sin(phi), y: Math.cos(phi) } };\n  });\n  // Where two neighbouring edges cross: a corner of the opening.\n  const corner = (a: (typeof lines)[number], b: (typeof lines)[number]): P => {\n    const det = a.n.x * b.n.y - a.n.y * b.n.x || 1e-6;\n    return { x: 50 + (a.d * b.n.y - b.d * a.n.y) / det, y: 50 + (a.n.x * b.d - b.n.x * a.d) / det };\n  };\n  const V = lines.map((_, k) => corner(lines[(k - 1 + N) % N], lines[k])); // V[k]: start of blade k's cut\n  const rimPoint = (l: (typeof lines)[number]): P => {\n    const u = Math.sqrt(Math.max(0, RIM * RIM - l.d * l.d));\n    return { x: 50 + l.n.x * l.d + l.t.x * u, y: 50 + l.n.y * l.d + l.t.y * u };\n  };\n  const Pk = lines.map(rimPoint); // where blade k's long edge meets the rim\n  const bend = (a: P, b: P, n: P, bow: number): P => {\n    const len = Math.hypot(b.x - a.x, b.y - a.y);\n    return { x: (a.x + b.x) / 2 + n.x * len * bow, y: (a.y + b.y) / 2 + n.y * len * bow };\n  };\n  const lead = lines.map((l, k) => bend(V[(k + 1) % N], Pk[k], l.n, LEAD_BOW));\n  return lines.map((l, k) => {\n    const v0 = V[k];\n    const v1 = V[(k + 1) % N];\n    const prev = (k - 1 + N) % N;\n    const side = bend(v0, v1, l.n, SIDE_BOW);\n    // How much this blade faces the light (top left), so the leaves read apart.\n    const mid = Math.atan2(l.n.y, l.n.x) + STEP / 2;\n    const lit = Math.cos(mid - LIGHT);\n    return {\n      lit,\n      blade: `M${pt(v0)}Q${pt(side)} ${pt(v1)}Q${pt(lead[k])} ${pt(Pk[k])}A${RIM} ${RIM} 0 0 0 ${pt(Pk[prev])}Q${pt(lead[prev])} ${pt(v0)}Z`,\n      edge: `M${pt(v0)}Q${pt(side)} ${pt(v1)}Q${pt(lead[k])} ${pt(Pk[k])}`,\n      shade: shadeOf(Pk[prev], lead[prev], v0, lines[prev].n),\n    };\n  });\n}\n\ntype PathRefs = React.RefObject<(SVGPathElement | null)[]>;\n\n/** The key and the bezel: drawn once, never re-rendered. */\nconst KeyBody = React.memo(function KeyBody({ id }: { id: string }) {\n  return (\n    <>\n      {/* The key and the bezel. */}\n      <svg viewBox=\"0 0 100 100\" className=\"absolute inset-0 size-full overflow-visible\">\n        <defs>\n          <linearGradient id={`${id}-key`} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n            <stop offset=\"0\" stopColor=\"color-mix(in oklab, var(--background) 86%, white)\" />\n            <stop offset=\"1\" stopColor=\"color-mix(in oklab, var(--background) 90%, var(--foreground))\" />\n          </linearGradient>\n          <linearGradient id={`${id}-bezel`} x1=\"0.15\" y1=\"0\" x2=\"0.85\" y2=\"1\">\n            <stop offset=\"0\" stopColor=\"oklch(0.44 0.004 260)\" />\n            <stop offset=\"0.45\" stopColor=\"oklch(0.25 0.004 260)\" />\n            <stop offset=\"1\" stopColor=\"oklch(0.15 0.004 260)\" />\n          </linearGradient>\n          <radialGradient id={`${id}-well`} cx=\"50\" cy=\"50\" r={LENS} gradientUnits=\"userSpaceOnUse\">\n            <stop offset=\"0\" stopColor=\"oklch(0.2 0.01 270)\" />\n            <stop offset=\"1\" stopColor=\"oklch(0.09 0.005 270)\" />\n          </radialGradient>\n        </defs>\n        <circle cx=\"50\" cy=\"50\" r=\"49.6\" fill={`url(#${id}-key)`} />\n        <circle cx=\"50\" cy=\"50\" r=\"49.6\" fill=\"none\" stroke=\"var(--border)\" strokeWidth=\"0.8\" />\n        <circle cx=\"50\" cy=\"50\" r=\"48.9\" fill=\"none\" stroke=\"white\" strokeOpacity=\"0.55\" strokeWidth=\"0.6\" className=\"dark:[stroke-opacity:0.14]\" style={{ clipPath: \"inset(0 0 55% 0)\" }} />\n        {/* The bezel: a dark metal ring with a knurled edge, lit from above. */}\n        {/* The groove the bezel sits in. */}\n        <circle cx=\"50\" cy=\"50\" r=\"42.3\" fill=\"black\" fillOpacity=\"0.07\" className=\"dark:[fill-opacity:0.4]\" />\n        <circle cx=\"50\" cy=\"50\" r=\"41.2\" fill=\"black\" fillOpacity=\"0.12\" transform=\"translate(0 0.9)\" />\n        <circle cx=\"50\" cy=\"50\" r=\"41\" fill={`url(#${id}-bezel)`} />\n        <g stroke=\"white\" strokeOpacity=\"0.09\" strokeWidth=\"0.45\">\n          {Array.from({ length: 72 }, (_, i) => {\n            const a = (i / 72) * Math.PI * 2;\n            return <line key={i} x1={f(50 + Math.cos(a) * 38.6)} y1={f(50 + Math.sin(a) * 38.6)} x2={f(50 + Math.cos(a) * 40.5)} y2={f(50 + Math.sin(a) * 40.5)} />;\n          })}\n        </g>\n        <circle cx=\"50\" cy=\"50\" r=\"40.75\" fill=\"none\" stroke=\"white\" strokeOpacity=\"0.2\" strokeWidth=\"0.5\" style={{ clipPath: \"inset(0 0 55% 0)\" }} />\n        <circle cx=\"50\" cy=\"50\" r={LENS + 1.6} fill=\"oklch(0.12 0 0)\" />\n        <circle cx=\"50\" cy=\"50\" r={LENS} fill={`url(#${id}-well)`} />\n      </svg>\n    </>\n  );\n});\n\n/** The aperture: seven blades, their shadows and their lit edges, written to by the springs. */\nconst Iris = React.memo(function Iris({ id, blades, edges, shades }: { id: string; blades: PathRefs; edges: PathRefs; shades: PathRefs }) {\n  return (\n    <>\n      {/* The aperture: seven blades. */}\n      <svg viewBox=\"0 0 100 100\" className=\"absolute inset-0 size-full will-change-transform\" style={{ clipPath: `circle(${LENS + 0.2}% at 50% 50%)` }}>\n        <defs>\n          <radialGradient id={`${id}-blade`} cx=\"50\" cy=\"50\" r={RIM} gradientUnits=\"userSpaceOnUse\">\n            <stop offset=\"0\" stopColor=\"oklch(0.42 0.006 260)\" />\n            <stop offset=\"0.55\" stopColor=\"oklch(0.3 0.005 260)\" />\n            <stop offset=\"1\" stopColor=\"oklch(0.17 0.004 260)\" />\n          </radialGradient>\n        </defs>\n        <g>\n          {Array.from({ length: N }, (_, k) => (\n            <path\n              key={k}\n              ref={(node) => {\n                blades.current[k] = node;\n              }}\n              fill={`url(#${id}-blade)`}\n            />\n          ))}\n          {/* Each blade lies under the next: the one above throws a soft shadow along its edge. */}\n          {Array.from({ length: N }, (_, k) => (\n            <path\n              key={k}\n              ref={(node) => {\n                shades.current[k] = node;\n              }}\n              fill=\"none\"\n              stroke=\"black\"\n              strokeOpacity=\"0.2\"\n              strokeWidth=\"3.7\"\n              strokeLinecap=\"round\"\n            />\n          ))}\n          {/* The cut edges catch the light. */}\n          {Array.from({ length: N }, (_, k) => (\n            <path\n              key={k}\n              ref={(node) => {\n                edges.current[k] = node;\n              }}\n              fill=\"none\"\n              stroke=\"white\"\n              strokeOpacity=\"0.2\"\n              strokeWidth=\"0.45\"\n              strokeLinecap=\"round\"\n            />\n          ))}\n        </g>\n      </svg>\n    </>\n  );\n});\n\n/** The front glass: its lip, the coating's colour, the room's reflection, and the glint that follows the pointer. */\ntype GRef = React.RefObject<SVGGElement | null>;\nconst Glass = React.memo(function Glass({ id, glint, coat, ghosts }: { id: string; glint: GRef; coat: GRef; ghosts: GRef }) {\n  return (\n    <svg viewBox=\"0 0 100 100\" className=\"pointer-events-none absolute inset-0 size-full will-change-transform\">\n      <defs>\n        <radialGradient id={`${id}-glare`} cx=\"0.36\" cy=\"0.28\" r=\"0.62\">\n          <stop offset=\"0\" stopColor=\"white\" stopOpacity=\"0.22\" />\n          <stop offset=\"0.55\" stopColor=\"white\" stopOpacity=\"0.04\" />\n          <stop offset=\"1\" stopColor=\"white\" stopOpacity=\"0\" />\n        </radialGradient>\n        <linearGradient id={`${id}-coat`} x1=\"36\" y1=\"76\" x2=\"75\" y2=\"61\" gradientUnits=\"userSpaceOnUse\">\n          <stop offset=\"0\" stopColor=\"var(--chart-4, var(--primary))\" stopOpacity=\"0\" />\n          <stop offset=\"0.45\" stopColor=\"var(--chart-4, var(--primary))\" stopOpacity=\"0.55\" />\n          <stop offset=\"0.75\" stopColor=\"var(--chart-2, var(--primary))\" stopOpacity=\"0.45\" />\n          <stop offset=\"1\" stopColor=\"var(--chart-2, var(--primary))\" stopOpacity=\"0\" />\n        </linearGradient>\n        <radialGradient id={`${id}-glint`}>\n          <stop offset=\"0\" stopColor=\"white\" stopOpacity=\"0.95\" />\n          <stop offset=\"0.4\" stopColor=\"white\" stopOpacity=\"0.4\" />\n          <stop offset=\"1\" stopColor=\"white\" stopOpacity=\"0\" />\n        </radialGradient>\n        <clipPath id={`${id}-glass`}>\n          <circle cx=\"50\" cy=\"50\" r={LENS} />\n        </clipPath>\n      </defs>\n      <g clipPath={`url(#${id}-glass)`}>\n        <circle cx=\"50\" cy=\"50\" r={LENS} fill={`url(#${id}-glare)`} />\n        <g ref={coat} fill=\"none\" strokeLinecap=\"round\">\n          <path d=\"M36.9 76.2 A27.5 27.5 0 0 0 74.6 61.4\" stroke={`url(#${id}-coat)`} strokeWidth=\"2.2\" opacity=\"0.55\" />\n          <path d=\"M30.6 36.9 A23.5 23.5 0 0 1 39.5 29.2\" stroke=\"var(--chart-2, var(--primary))\" strokeOpacity=\"0.28\" strokeWidth=\"1.4\" />\n        </g>\n        {/* The inner elements' reflections: seen in a dark lens, lost against a lit picture. */}\n        <g ref={ghosts}>\n          <circle cx=\"50\" cy=\"50\" r=\"21.5\" fill=\"none\" stroke=\"white\" strokeOpacity=\"0.06\" strokeWidth=\"0.5\" />\n          <circle cx=\"50\" cy=\"50\" r=\"12.5\" fill=\"none\" stroke=\"white\" strokeOpacity=\"0.05\" strokeWidth=\"0.5\" />\n          <circle cx=\"61\" cy=\"62.5\" r=\"1.1\" fill=\"white\" fillOpacity=\"0.35\" />\n        </g>\n        <g ref={glint}>\n          <ellipse cx=\"38.5\" cy=\"35\" rx=\"5.2\" ry=\"3.1\" fill={`url(#${id}-glint)`} transform=\"rotate(-32 38.5 35)\" />\n        </g>\n      </g>\n      <circle cx=\"50\" cy=\"50\" r={LENS} fill=\"none\" stroke=\"black\" strokeOpacity=\"0.7\" strokeWidth=\"1.1\" />\n      <circle cx=\"50\" cy=\"50\" r={LENS + 1.1} fill=\"none\" stroke=\"white\" strokeOpacity=\"0.13\" strokeWidth=\"0.45\" />\n    </svg>\n  );\n});\n\n/**\n * The shadow the blade above throws along a blade's trailing edge: the same curve, moved 2 units into the blade (the\n * side away from the edge's normal) and stopped short of the opening's corner, so it never needs a clip.\n */\nfunction shadeOf(from: P, control: P, to: P, n: P) {\n  const len = Math.hypot(to.x - from.x, to.y - from.y);\n  const t = clamp(1 - 4.5 / Math.max(len, 0.001), 0, 1);\n  const q: P = { x: from.x + (control.x - from.x) * t, y: from.y + (control.y - from.y) * t };\n  const r: P = { x: control.x + (to.x - control.x) * t, y: control.y + (to.y - control.y) * t };\n  const end: P = { x: q.x + (r.x - q.x) * t, y: q.y + (r.y - q.y) * t };\n  const o = (p: P): P => ({ x: p.x - n.x * 2, y: p.y - n.y * 2 });\n  return t <= 0 ? \"\" : `M${pt(o(from))}Q${pt(o(q))} ${pt(o(end))}`;\n}\n\nconst LINES = [\"off\", \"blocked\", \"starting\", \"on\"] as const;\ntype Line = (typeof LINES)[number];\n\nexport function CameraKey({\n  on,\n  defaultOn = false,\n  onToggle,\n  onOnChange,\n  stream,\n  poster,\n  mirror = true,\n  size = 64,\n  showLabel = true,\n  labels,\n  disabled = false,\n  sound = false,\n  onStatusChange,\n  className = \"\",\n}: CameraKeyProps) {\n  const reduced = useReducedMotion();\n  const rawId = React.useId();\n  const id = rawId.replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const words = { off: \"Camera off\", starting: \"Starting camera\", on: \"Camera on\", blocked: \"Camera blocked\", ...labels };\n\n  const [status, setStatus] = React.useState<CameraKeyStatus>(on ?? defaultOn ? \"on\" : \"off\");\n  const [reason, setReason] = React.useState<string | null>(null);\n  // Controlled: follow the parent when it changes its mind (and nothing is in flight).\n  const [lastOn, setLastOn] = React.useState(on);\n  if (on !== undefined && on !== lastOn) {\n    setLastOn(on);\n    if (status !== \"starting\") setStatus(on ? \"on\" : \"off\");\n  }\n\n  const rootRef = React.useRef<HTMLButtonElement>(null);\n  const faceRef = React.useRef<HTMLSpanElement>(null);\n  const shadowRef = React.useRef<HTMLSpanElement>(null);\n  const mediaRef = React.useRef<HTMLSpanElement>(null);\n  const videoRef = React.useRef<HTMLVideoElement>(null);\n  const bladeRefs = React.useRef<(SVGPathElement | null)[]>([]);\n  const edgeRefs = React.useRef<(SVGPathElement | null)[]>([]);\n  const shadeRefs = React.useRef<(SVGPathElement | null)[]>([]);\n  const glintRef = React.useRef<SVGGElement>(null);\n  const coatRef = React.useRef<SVGGElement>(null);\n  const ghostsRef = React.useRef<SVGGElement>(null);\n  const ledRef = React.useRef<HTMLSpanElement>(null);\n\n  const timers = React.useRef(new Set<ReturnType<typeof setTimeout>>());\n  const hunt = React.useRef<ReturnType<typeof setInterval> | null>(null);\n  const flow = React.useRef({ hover: false, down: false, closedKnock: true, token: 0 });\n  const latest = React.useRef({ onToggle, onOnChange, onStatusChange, sound, reduced, status, size });\n  React.useLayoutEffect(() => {\n    latest.current = { onToggle, onOnChange, onStatusChange, sound, reduced, status, size };\n  });\n\n  const later = (fn: () => void, ms: number) => {\n    const t = setTimeout(() => {\n      timers.current.delete(t);\n      fn();\n    }, ms);\n    timers.current.add(t);\n  };\n  const stopHunt = () => {\n    if (hunt.current) clearInterval(hunt.current);\n    hunt.current = null;\n  };\n\n  // Everything is drawn from these springs, once per frame, straight to the DOM.\n  const paintRef = React.useRef<() => void>(() => {});\n  const springsRef = React.useRef<Springs | null>(null);\n  const getSprings = React.useCallback(() => {\n    if (!springsRef.current) {\n      const paint = () => paintRef.current();\n      const start = latest.current.status === \"on\" ? 1 : 0;\n      springsRef.current = {\n        blades: Array.from({ length: N }, (_, k) => createSpring(start, bladeSpring(k), paint, 0.0015)),\n        press: createSpring(0, PRESS, paint, 0.002),\n        tiltX: createSpring(0, TILT, paint, 0.002),\n        tiltY: createSpring(0, TILT, paint, 0.002),\n        focus: createSpring(0, FOCUS, paint, 0.004),\n        live: createSpring(start, LIVE, paint, 0.003),\n        rattle: createSpring(0, RATTLE, paint, 0.0008),\n      };\n    }\n    return springsRef.current;\n  }, []);\n\n  React.useLayoutEffect(() => {\n    paintRef.current = () => {\n      const s = springsRef.current;\n      if (!s) return;\n      const px = latest.current.size / 100;\n      const open = s.blades.map((b) => b.get());\n      const rattle = s.rattle.get();\n      const paths = irisPaths(open, rattle * 0.35);\n      for (let k = 0; k < N; k++) {\n        const blade = bladeRefs.current[k];\n        if (blade) {\n          blade.setAttribute(\"d\", paths[k].blade);\n          blade.style.opacity = f(0.8 + 0.2 * paths[k].lit);\n        }\n        const edge = edgeRefs.current[k];\n        if (edge) {\n          edge.setAttribute(\"d\", paths[k].edge);\n          edge.style.strokeOpacity = f(0.14 + 0.16 * Math.max(0, paths[k].lit));\n        }\n        shadeRefs.current[k]?.setAttribute(\"d\", paths[k].shade);\n      }\n      const mean = open.reduce((sum, a) => sum + clamp(a, 0, 1), 0) / N;\n\n      // The blades meeting: a small knock the key feels (once per close).\n      const state = flow.current;\n      if (mean < 0.02 && !state.closedKnock && s.blades[0].getTarget() < 0.08) {\n        state.closedKnock = true;\n        if (!latest.current.reduced) s.press.push(5);\n        if (latest.current.sound) playSound(\"tick\", 0.35);\n      } else if (mean > 0.08) state.closedKnock = false;\n\n      // The key: pressed, leaning toward the pointer, and shaken when the blades jam.\n      const p = s.press.get();\n      const tx = s.tiltX.get();\n      const ty = s.tiltY.get();\n      if (faceRef.current) {\n        // Flat transforms only: a 3D turn resamples the drawn layer and breaks the blades' fine edges into dashes.\n        faceRef.current.style.transform = `translate3d(${f(rattle * px * 9 + tx * px * 0.9)}px, ${f(p * px * 1.6 + ty * px * 0.9)}px, 0) scale(${f(1 - p * 0.04)})`;\n      }\n      if (shadowRef.current) {\n        shadowRef.current.style.transform = `translate3d(${f(tx * px * 3)}px, ${f(px * (7 - p * 3.5) + ty * px * 2)}px, 0) scale(${f(0.9 - p * 0.06)})`;\n        shadowRef.current.style.opacity = f(0.95 - p * 0.35);\n      }\n\n      // The picture: there while the camera is live, darker as the blades cut the light, bright and soft until it finds focus.\n      const fo = Math.abs(s.focus.get());\n      const live = clamp(s.live.get(), 0, 1);\n      if (mediaRef.current) {\n        const bright = (0.22 + 0.78 * mean) * (1 + 0.75 * fo);\n        mediaRef.current.style.opacity = f(live);\n        mediaRef.current.style.filter = `brightness(${f(bright)}) blur(${f(fo * px * 2.4)}px) saturate(${f(1 - fo * 0.3)})`;\n        mediaRef.current.style.transform = `translate3d(${f(-tx * px * 1.6)}px, ${f(-ty * px * 1.6)}px, 0) scale(${f(1.04 + (1 - mean) * 0.08 + fo * 0.02)})`;\n      }\n\n      // The glass catches the light where the pointer is; the coating's colour slides the other way.\n      glintRef.current?.setAttribute(\"transform\", `translate(${f(tx * 9)} ${f(ty * 9)})`);\n      coatRef.current?.setAttribute(\"transform\", `translate(${f(-tx * 5)} ${f(-ty * 5)})`);\n      if (coatRef.current) coatRef.current.style.opacity = f(1 - live * 0.45);\n      if (ghostsRef.current) ghostsRef.current.style.opacity = f(1 - live * 0.9);\n    };\n    paintRef.current();\n  });\n\n  // First paint: the iris drawn where it starts, before any spring has moved.\n  React.useLayoutEffect(() => {\n    getSprings();\n    paintRef.current();\n  }, [getSprings]);\n\n  // The stream, in the lens.\n  React.useEffect(() => {\n    const video = videoRef.current;\n    if (!video) return;\n    video.srcObject = stream ?? null;\n    if (stream) void video.play().catch(() => {});\n  }, [stream]);\n\n  // Drive the springs from the state.\n  React.useEffect(() => {\n    const s = getSprings();\n    const quick = latest.current.reduced;\n    const aim = (value: number) => s.blades.forEach((b) => (quick ? b.jump(value) : b.set(value)));\n    stopHunt();\n    if (status === \"on\") {\n      aim(flow.current.hover ? 0.94 : 1);\n      if (quick) s.live.jump(1);\n      else s.live.set(1);\n    } else if (status === \"starting\") {\n      if (quick) aim(0.16);\n      else {\n        // Hunting: the blades open a crack and work back and forth while the camera is asked for.\n        let wide = true;\n        aim(0.2);\n        hunt.current = setInterval(() => {\n          wide = !wide;\n          s.blades.forEach((b, k) => b.set((wide ? 0.21 : 0.12) + (k % 2) * 0.012));\n        }, 420);\n      }\n    } else if (status === \"off\") {\n      aim(flow.current.hover ? 0.05 : 0);\n      if (quick) s.live.jump(0);\n      else s.live.set(0);\n    } else {\n      // Blocked: jam() moves the blades; the picture never came.\n      s.live.set(0);\n    }\n    latest.current.onStatusChange?.(status);\n    return stopHunt;\n  }, [status, getSprings]);\n\n  // The light beside the lens: green while live, a slow amber breath while starting, two red blinks when blocked.\n  React.useEffect(() => {\n    const led = ledRef.current;\n    if (!led || reduced) return;\n    if (status === \"starting\") {\n      const a = led.animate([{ opacity: 1 }, { opacity: 0.35 }, { opacity: 1 }], { duration: 840, iterations: Infinity, easing: \"ease-in-out\" });\n      return () => a.cancel();\n    }\n    if (status === \"blocked\") {\n      const a = led.animate([{ opacity: 1 }, { opacity: 0.15 }, { opacity: 1 }, { opacity: 0.15 }, { opacity: 1 }], { duration: 760, easing: \"linear\" });\n      return () => a.cancel();\n    }\n  }, [status, reduced]);\n\n  React.useEffect(() => {\n    const pending = timers.current;\n    return () => {\n      for (const t of pending) clearTimeout(t);\n      pending.clear();\n      stopHunt();\n      const s = springsRef.current;\n      if (s) [...s.blades, s.press, s.tiltX, s.tiltY, s.focus, s.live, s.rattle].forEach((sp) => sp.stop());\n    };\n  }, []);\n\n  const jam = () => {\n    const s = getSprings();\n    if (latest.current.sound) playSound(\"error\", 0.35);\n    if (latest.current.reduced) {\n      s.blades.forEach((b) => b.jump(0));\n      return;\n    }\n    // They get a little way open, catch on each other and rattle, the key shakes, then they fall shut.\n    s.blades.forEach((b, k) => b.set(0.3 + (k % 3) * 0.015));\n    later(() => {\n      s.rattle.push(7);\n      s.press.push(4);\n    }, 170);\n    later(() => s.rattle.push(-5), 260);\n    later(() => s.blades.forEach((b) => b.set(0)), 620);\n  };\n\n  const toggle = async () => {\n    if (disabled) return;\n    const s = getSprings();\n    const current = latest.current.status;\n    const token = ++flow.current.token;\n    if (current === \"on\" || current === \"starting\") {\n      // Off at once: the blades close from wherever they are, keeping their speed.\n      setStatus(\"off\");\n      setReason(null);\n      latest.current.onOnChange?.(false);\n      try {\n        await latest.current.onToggle?.(false);\n      } catch {}\n      return;\n    }\n    setReason(null);\n    const handler = latest.current.onToggle;\n    if (!handler) {\n      setStatus(\"on\");\n      openUp(s);\n      latest.current.onOnChange?.(true);\n      return;\n    }\n    setStatus(\"starting\");\n    try {\n      await handler(true);\n      if (token !== flow.current.token) return; // turned off again while it was starting\n      setStatus(\"on\");\n      openUp(s);\n      latest.current.onOnChange?.(true);\n    } catch (error) {\n      if (token !== flow.current.token) return;\n      setReason(error instanceof Error && error.message ? error.message : null);\n      setStatus(\"blocked\");\n      jam();\n    }\n  };\n\n  // Opening: the picture comes in over-bright and soft, then finds its exposure and focus (one hunt past it and back).\n  const openUp = (s: Springs) => {\n    if (latest.current.sound) playSound(\"unfold\", 0.3);\n    if (latest.current.reduced) return;\n    s.focus.jump(1);\n    later(() => s.focus.set(0), 120);\n  };\n\n  // Pointer: tilt toward it, and let the blades lean the way a press would take them.\n  const onPointerMove = (event: React.PointerEvent<HTMLButtonElement>) => {\n    if (latest.current.reduced || event.pointerType !== \"mouse\") return;\n    const rect = event.currentTarget.getBoundingClientRect();\n    const s = getSprings();\n    s.tiltX.set(clamp(((event.clientX - rect.left) / rect.width) * 2 - 1, -1, 1));\n    s.tiltY.set(clamp(((event.clientY - rect.top) / rect.width) * 2 - 1, -1, 1));\n  };\n  const lean = () => {\n    const s = getSprings();\n    const st = latest.current.status;\n    const { hover, down } = flow.current;\n    if (st === \"on\") s.blades.forEach((b) => b.set(down ? 0.86 : hover ? 0.94 : 1));\n    else if (st === \"off\") s.blades.forEach((b) => b.set(down ? 0.1 : hover ? 0.05 : 0));\n  };\n  const onPointerEnter = (event: React.PointerEvent) => {\n    if (event.pointerType !== \"mouse\" || latest.current.reduced) return;\n    flow.current.hover = true;\n    lean();\n  };\n  const onPointerLeave = () => {\n    const s = getSprings();\n    flow.current.hover = false;\n    flow.current.down = false;\n    s.tiltX.set(0);\n    s.tiltY.set(0);\n    s.press.set(0);\n    if (!latest.current.reduced) lean();\n  };\n  const onPointerDown = () => {\n    if (disabled) return;\n    const s = getSprings();\n    flow.current.down = true;\n    if (!latest.current.reduced) {\n      s.press.set(1);\n      lean();\n    }\n  };\n  const onPointerUp = () => {\n    const s = getSprings();\n    flow.current.down = false;\n    s.press.set(0);\n  };\n  const onClick = (event: React.MouseEvent) => {\n    // A keyboard press has no pointer: give the key its dip anyway.\n    if (event.detail === 0 && !latest.current.reduced) getSprings().press.push(7);\n    void toggle();\n  };\n\n  const line: Line = status;\n  const announce = status === \"on\" ? words.on : status === \"starting\" ? words.starting : status === \"blocked\" ? `${words.blocked}${reason ? `: ${reason}` : \"\"}` : words.off;\n  const fade = (ms: number, delay = 0) => (reduced ? \"none\" : `opacity ${ms}ms ${EASE_OUT} ${delay}ms, transform ${ms + 120}ms ${EASE_OUT} ${delay}ms, filter ${ms}ms ${EASE_OUT} ${delay}ms`);\n  const lineStyle = (name: Line): React.CSSProperties => {\n    const shown = name === line;\n    const offset = LINES.indexOf(name) < LINES.indexOf(line) ? -5 : 5;\n    return {\n      opacity: shown ? 1 : 0,\n      transform: shown ? \"none\" : `translate3d(0,${offset}px,0)`,\n      filter: shown ? \"blur(0px)\" : \"blur(3px)\",\n      transition: shown ? fade(280, 80) : fade(150),\n    };\n  };\n  const ledColor =\n    status === \"on\" ? \"bg-emerald-400\" : status === \"starting\" ? \"bg-amber-400\" : status === \"blocked\" ? \"bg-red-500\" : \"bg-[oklch(0.3_0_0)] dark:bg-[oklch(0.22_0_0)]\";\n  const ledLit = status !== \"off\";\n  const ledX = 50 + Math.cos(LED_ANGLE) * 45.6;\n  const ledY = 50 + Math.sin(LED_ANGLE) * 45.6;\n  const lensInset = `${50 - LENS}%`;\n\n  return (\n    <span className={`inline-flex flex-col items-center gap-2 ${className}`}>\n      <button\n        ref={rootRef}\n        type=\"button\"\n        role=\"switch\"\n        aria-checked={status === \"on\" || status === \"starting\"}\n        aria-label=\"Camera\"\n        aria-busy={status === \"starting\" || undefined}\n        aria-disabled={disabled || undefined}\n        onClick={onClick}\n        onPointerDown={onPointerDown}\n        onPointerUp={onPointerUp}\n        onPointerCancel={onPointerUp}\n        onPointerMove={onPointerMove}\n        onPointerEnter={onPointerEnter}\n        onPointerLeave={onPointerLeave}\n        className={`relative shrink-0 cursor-pointer touch-manipulation select-none rounded-full outline-none [-webkit-tap-highlight-color:transparent] aria-disabled:cursor-default aria-disabled:opacity-50 ${INTERACTION_FOCUS}`}\n        style={{ width: size, height: size }}\n      >\n        {/* The key's shadow on the surface it sits on: it tightens when the key is pressed. */}\n        <span\n          ref={shadowRef}\n          aria-hidden=\"true\"\n          className=\"pointer-events-none absolute inset-0 rounded-full bg-[radial-gradient(closest-side,rgb(0_0_0/0.2),rgb(0_0_0/0.07)_62%,transparent)] blur-[3px] will-change-transform dark:bg-[radial-gradient(closest-side,rgb(0_0_0/0.6),rgb(0_0_0/0.25)_62%,transparent)]\"\n          style={{ transform: `translate3d(0,${size * 0.07}px,0) scale(0.9)` }}\n        />\n        <span ref={faceRef} aria-hidden=\"true\" className=\"absolute inset-0 block rounded-full will-change-transform\">\n          <KeyBody id={id} />\n\n          {/* The picture, behind the blades. */}\n          <span\n            className=\"absolute overflow-hidden rounded-full\"\n            style={{ left: lensInset, top: lensInset, right: lensInset, bottom: lensInset }}\n          >\n            <span ref={mediaRef} className=\"absolute inset-0 block will-change-[transform,filter,opacity]\" style={{ opacity: 0 }}>\n              {stream ? (\n                <video ref={videoRef} muted playsInline autoPlay className={`size-full object-cover ${mirror ? \"-scale-x-100\" : \"\"}`} />\n              ) : poster ? (\n                // eslint-disable-next-line @next/next/no-img-element\n                <img src={poster} alt=\"\" draggable={false} className={`size-full object-cover ${mirror ? \"-scale-x-100\" : \"\"}`} />\n              ) : (\n                <span className=\"block size-full bg-[radial-gradient(circle_at_50%_40%,oklch(0.55_0.03_250),oklch(0.25_0.02_260))]\" />\n              )}\n            </span>\n            {/* The glass's own falloff toward its edge. */}\n            <span className=\"absolute inset-0 rounded-full shadow-[inset_0_0_0.6em_0.15em_rgb(0_0_0/0.55)]\" style={{ fontSize: size * 0.1 }} />\n          </span>\n\n          <Iris id={id} blades={bladeRefs} edges={edgeRefs} shades={shadeRefs} />\n\n          <Glass id={id} glint={glintRef} coat={coatRef} ghosts={ghostsRef} />\n\n          {/* The light that says the camera is on. */}\n          <span\n            ref={ledRef}\n            className={`absolute rounded-full transition-[background-color,box-shadow] duration-300 ${ledColor}`}\n            style={{\n              width: `${4.2}%`,\n              height: `${4.2}%`,\n              left: `${ledX - 2.1}%`,\n              top: `${ledY - 2.1}%`,\n              boxShadow: ledLit\n                ? `0 0 ${f(size * 0.05)}px ${f(size * 0.012)}px ${status === \"on\" ? \"rgb(52 211 153/0.75)\" : status === \"starting\" ? \"rgb(251 191 36/0.7)\" : \"rgb(239 68 68/0.75)\"}`\n                : \"inset 0 0.5px 1px rgb(0 0 0/0.6)\",\n            }}\n          />\n        </span>\n      </button>\n\n      {showLabel ? (\n        <span aria-hidden=\"true\" className=\"relative grid h-4 text-center text-[12.5px] leading-4 text-muted-foreground\">\n          {LINES.map((name) => (\n            <span\n              key={name}\n              className={`col-start-1 row-start-1 whitespace-nowrap ${name === \"blocked\" ? \"text-red-600 dark:text-red-400\" : \"\"}`}\n              style={lineStyle(name)}\n            >\n              {name === \"blocked\" ? reason ?? words.blocked : words[name]}\n            </span>\n          ))}\n        </span>\n      ) : null}\n      <span role=\"status\" className=\"sr-only\">\n        {announce}\n      </span>\n    </span>\n  );\n}\n\nexport default CameraKey;\n"},{"path":"registry/ui-interaction-motion.ts","type":"registry:component","content":"// Hairline UI · camera-key · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n'use client';\n\nimport * as React from 'react';\n\nexport const EASE_OUT = 'cubic-bezier(0.16, 1, 0.3, 1)';\nexport const EASE_SETTLE = 'cubic-bezier(0.22, 1.18, 0.36, 1)';\n/** Thrown things (indicators, thumbs): a slight overshoot on transform only. */\nexport const EASE_THROW = 'cubic-bezier(0.34, 1.36, 0.64, 1)';\n/**\n * The press every button primitive shares: a 3% give that eases in and settles back.\n * Tailwind v4's scale-* writes the `scale` property, so `scale` has to be in the list\n * or the press snaps.\n */\nexport const INTERACTION_PRESS =\n  'transition-[background-color,color,box-shadow,opacity,scale] duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] active:scale-[0.97] motion-reduce:transition-none motion-reduce:active:scale-100';\nexport const INTERACTION_FOCUS ='focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:ring-offset-2 focus-visible:ring-offset-background';\n\nconst query = '(prefers-reduced-motion: reduce)';\nconst subscribe = (notify: () => void) => {\n  const media = window.matchMedia(query);\n  media.addEventListener('change', notify);\n  return () => media.removeEventListener('change', notify);\n};\nexport const useInteractionReducedMotion = () => React.useSyncExternalStore(subscribe, () => window.matchMedia(query).matches, () => false);\n\nexport function useInteractionActivity<T extends Element>() {\n  const ref = React.useRef<T>(null);\n  const [visible, setVisible] = React.useState(false);\n  const [hidden, setHidden] = React.useState(false);\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const observer = new IntersectionObserver(([entry]) => setVisible(entry.isIntersecting));\n    observer.observe(el);\n    const visibility = () => setHidden(document.hidden);\n    visibility(); document.addEventListener('visibilitychange', visibility);\n    return () => { observer.disconnect(); document.removeEventListener('visibilitychange', visibility); };\n  }, []);\n  return { ref, active: visible && !hidden };\n}\n\nexport function interactionIcon(on: boolean, reduced: boolean): React.CSSProperties {\n  return { opacity: on ? 1 : 0, transform: on ? 'none' : 'scale(0.6)', filter: on ? 'blur(0px)' : 'blur(3px)', transition: reduced ? 'none' : `opacity 220ms ${EASE_OUT}, transform 380ms ${EASE_OUT}, filter 220ms ${EASE_OUT}` };\n}\n\n/** A raised object: one tight contact shadow, one short ambient, a hairline of light on its top edge. */\nexport const MATERIAL_LIFT =\n  'shadow-[0_1px_1.5px_rgb(0_0_0/0.07),0_3px_8px_-2px_rgb(0_0_0/0.1),inset_0_0.5px_0_rgb(255_255_255/0.8)] dark:shadow-[0_1px_2px_rgb(0_0_0/0.5),0_4px_10px_-2px_rgb(0_0_0/0.35),inset_0_0.5px_0_rgb(255_255_255/0.1)]';\n/** A trough something sits in, shaded from above, lit along its bottom edge. */\nexport const MATERIAL_RECESS =\n  'shadow-[inset_0_1px_2.5px_rgb(0_0_0/0.09),inset_0_-0.5px_0_rgb(255_255_255/0.7)] dark:shadow-[inset_0_1px_3px_rgb(0_0_0/0.45),inset_0_-0.5px_0_rgb(255_255_255/0.07)]';\n\nexport type SpringConfig = { stiffness: number; damping: number; mass?: number };\nexport interface Spring {\n  get(): number;\n  getVelocity(): number;\n  getTarget(): number;\n  /** Aim somewhere new from wherever it is now, keeping its speed. */\n  set(target: number): void;\n  /** Add speed (units per second), on top of what it already has. */\n  push(velocity: number): void;\n  /** Be there now, at rest. */\n  jump(value: number): void;\n  configure(config: SpringConfig): void;\n  stop(): void;\n}\n\n// Every moving spring on the page shares one frame loop, which sleeps when the last one rests. Each spring's onFrame runs\n// once per frame after all of them have stepped, so several springs that draw one shape paint it once.\nconst SPRING_STEP = 1 / 240;\ntype Running = { step: () => void };\nconst runningSprings = new Set<Running>();\nconst springPainters = new Set<() => void>();\nlet springFrame = 0;\nlet springLast = 0;\nlet springSpare = 0;\n\nfunction springTick(now: number) {\n  // A hidden tab stops the frames, so the first one back must not count the whole gap as time passed.\n  springSpare += Math.min((now - springLast) / 1000, 0.05);\n  springLast = now;\n  while (springSpare >= SPRING_STEP) {\n    runningSprings.forEach((spring) => spring.step());\n    springSpare -= SPRING_STEP;\n  }\n  const painters = [...springPainters];\n  springPainters.clear();\n  painters.forEach((paint) => paint());\n  springFrame = runningSprings.size ? requestAnimationFrame(springTick) : 0;\n}\n\nfunction wakeSprings(spring: Running) {\n  runningSprings.add(spring);\n  if (springFrame) return;\n  springSpare = 0;\n  springFrame = requestAnimationFrame((now) => {\n    springLast = now - 1000 / 60;\n    springTick(now);\n  });\n}\n\n/**\n * A spring that carries its speed: re-aim it mid-flight and it curves on from where it is, push it while it swings and the\n * push adds to the swing. Use it for anything that can be interrupted; a curve restarts from a standstill every time.\n * `onFrame` should write straight to the DOM. `precision` is how close counts as there, in the value's own units.\n */\nexport function createSpring(initial: number, config: SpringConfig, onFrame: () => void, precision = 0.01): Spring {\n  let value = initial;\n  let velocity = 0;\n  let target = initial;\n  let { stiffness, damping, mass = 1 } = config;\n  const running: Running = {\n    step() {\n      velocity += ((-stiffness * (value - target) - damping * velocity) / mass) * SPRING_STEP;\n      value += velocity * SPRING_STEP;\n      if (Math.abs(value - target) < precision && Math.abs(velocity) < precision * 10) {\n        value = target;\n        velocity = 0;\n        runningSprings.delete(running);\n      }\n      springPainters.add(onFrame);\n    },\n  };\n  return {\n    get: () => value,\n    getVelocity: () => velocity,\n    getTarget: () => target,\n    set(next) {\n      if (next === target && !runningSprings.has(running)) return;\n      target = next;\n      wakeSprings(running);\n    },\n    push(speed) {\n      velocity += speed;\n      wakeSprings(running);\n    },\n    jump(next) {\n      value = next;\n      target = next;\n      velocity = 0;\n      runningSprings.delete(running);\n      onFrame();\n    },\n    configure(next) {\n      ({ stiffness, damping, mass = 1 } = next);\n    },\n    stop() {\n      runningSprings.delete(running);\n    },\n  };\n}\n\n/** Sample recent movement rather than averaging a long drag and losing its release velocity. */\nexport type PointerSample = { x: number; time: number };\nexport function samplePointer(samples: PointerSample[], x: number, time: number) {\n  samples.push({ x, time });\n  while (samples.length > 2 && time - samples[0].time > 100) samples.shift();\n}\nexport function releaseVelocity(samples: PointerSample[], now: number) {\n  if (samples.length < 2 || now - samples[samples.length - 1].time > 100) return 0;\n  const first = samples[0], last = samples[samples.length - 1];\n  return (last.x - first.x) / Math.max(1, last.time - first.time);\n}\n\n/** Smooth Apple/rational rubber-band curve: continuous exponential-like resistance without linear kinks. */\nexport function rubberBand(overshoot: number, dimension = 320, constant = 0.55): number {\n  const d = dimension || 320;\n  const abs = Math.abs(overshoot);\n  return Math.sign(overshoot) * (1 - 1 / ((abs * constant) / d + 1)) * d;\n}\n\n/** Projects resting travel from release velocity (velocity in px/ms; time in seconds). */\nexport function projectInertia(distance: number, velocity: number, time = 0.12): number {\n  return distance + velocity * 1000 * time;\n}\n\n/** Smooths incoming release velocity toward a boundary so springs don't slam or clip into walls. */\nexport function softenVelocity(velocity: number, distanceToTarget: number, factor = 10): number {\n  const maxAllowed = Math.abs(distanceToTarget) * factor;\n  return Math.sign(velocity) * Math.min(Math.abs(velocity), maxAllowed);\n}\n\n/** A damped spring sampled by WAAPI: tuned for organic lightness with a hint of life (3% breath). */\nexport function springFrames(\n  from: number,\n  to: number,\n  velocity = 0,\n  duration = 480,\n  config: { omega?: number; damping?: number; steps?: number } = {},\n) {\n  const { omega = 16, damping = 0.74, steps = 36 } = config;\n  const damped = omega * Math.sqrt(Math.max(0.001, 1 - damping * damping));\n  const displacement = from - to;\n  const coefficient = (velocity * 1000 + damping * omega * displacement) / damped;\n  return Array.from({ length: steps + 1 }, (_, i) => {\n    const t = (i / steps) * (duration / 1000);\n    const value = to + Math.exp(-damping * omega * t) * (displacement * Math.cos(damped * t) + coefficient * Math.sin(damped * t));\n    return { value: i === steps ? to : value, offset: i / steps };\n  });\n}\n\n"},{"path":"registry/ui-sounds.ts","type":"registry:component","content":"// Hairline UI · camera-key · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n/* ─────────────────────────────────────────────────────────\n * UI SOUNDS: small interface sounds, made in code\n *\n * No files and nothing to license: every sound is built from a\n * tone or a burst of noise with the Web Audio API the moment it\n * plays. They're short and quiet, made to sit under an interface,\n * and components only play them when you pass `sound`.\n *\n *   fold     paper creasing: two short crisp bursts\n *   unfold   paper opening: a soft rising sweep\n *   drop     something small landing: a low, soft knock\n *   tick     a light click\n *   pop      a quick bright blip\n *   success  two soft rising notes\n *   error    two low falling notes\n *\n * Browsers only start audio after the visitor has pressed\n * something on the page, so a sound before that stays silent.\n * ───────────────────────────────────────────────────────── */\n\nexport type UiSound = \"fold\" | \"unfold\" | \"drop\" | \"tick\" | \"pop\" | \"success\" | \"error\";\n\nlet context: AudioContext | null = null;\nlet noise: AudioBuffer | null = null;\n\nfunction audio() {\n  if (typeof window === \"undefined\") return null;\n  if (!context) {\n    const Ctx = window.AudioContext ?? (window as unknown as { webkitAudioContext?: typeof AudioContext }).webkitAudioContext;\n    if (!Ctx) return null;\n    context = new Ctx();\n  }\n  if (context.state === \"suspended\") void context.resume().catch(() => {});\n  return context;\n}\n\nfunction noiseBuffer(ctx: AudioContext) {\n  if (noise && noise.sampleRate === ctx.sampleRate) return noise;\n  noise = ctx.createBuffer(1, Math.floor(ctx.sampleRate * 0.5), ctx.sampleRate);\n  const data = noise.getChannelData(0);\n  for (let i = 0; i < data.length; i++) data[i] = Math.random() * 2 - 1;\n  return noise;\n}\n\n/** A burst of filtered noise. */\nfunction burst(ctx: AudioContext, out: AudioNode, at: number, length: number, { type = \"bandpass\", from = 2000, to = from, q = 0.9, level = 0.5 }: { type?: BiquadFilterType; from?: number; to?: number; q?: number; level?: number }) {\n  const src = ctx.createBufferSource();\n  src.buffer = noiseBuffer(ctx);\n  const filter = ctx.createBiquadFilter();\n  filter.type = type;\n  filter.Q.value = q;\n  filter.frequency.setValueAtTime(from, at);\n  filter.frequency.exponentialRampToValueAtTime(Math.max(40, to), at + length);\n  const gain = ctx.createGain();\n  gain.gain.setValueAtTime(0.0001, at);\n  gain.gain.exponentialRampToValueAtTime(level, at + Math.min(0.012, length / 3));\n  gain.gain.exponentialRampToValueAtTime(0.0001, at + length);\n  src.connect(filter).connect(gain).connect(out);\n  src.start(at, Math.random() * 0.3, length + 0.02);\n}\n\n/** A tone that glides from one pitch to another. */\nfunction tone(ctx: AudioContext, out: AudioNode, at: number, length: number, { type = \"sine\", from, to = from, level = 0.4 }: { type?: OscillatorType; from: number; to?: number; level?: number }) {\n  const osc = ctx.createOscillator();\n  osc.type = type;\n  osc.frequency.setValueAtTime(from, at);\n  osc.frequency.exponentialRampToValueAtTime(Math.max(20, to), at + length);\n  const gain = ctx.createGain();\n  gain.gain.setValueAtTime(0.0001, at);\n  gain.gain.exponentialRampToValueAtTime(level, at + 0.006);\n  gain.gain.exponentialRampToValueAtTime(0.0001, at + length);\n  osc.connect(gain).connect(out);\n  osc.start(at);\n  osc.stop(at + length + 0.02);\n}\n\n/** Plays one sound. `volume` is 0 to 1; the default sits quietly under an interface. */\nexport function playSound(name: UiSound, volume = 0.5) {\n  const ctx = audio();\n  if (!ctx) return;\n  const out = ctx.createGain();\n  out.gain.value = Math.max(0, Math.min(1, volume)) * 0.5;\n  out.connect(ctx.destination);\n  const t = ctx.currentTime + 0.005;\n  switch (name) {\n    case \"fold\":\n      burst(ctx, out, t, 0.05, { type: \"highpass\", from: 2600, q: 0.7, level: 0.45 });\n      burst(ctx, out, t + 0.07, 0.07, { type: \"bandpass\", from: 3200, to: 1800, q: 1.2, level: 0.35 });\n      break;\n    case \"unfold\":\n      burst(ctx, out, t, 0.16, { type: \"bandpass\", from: 900, to: 2800, q: 0.8, level: 0.3 });\n      break;\n    case \"drop\":\n      tone(ctx, out, t, 0.12, { from: 180, to: 70, level: 0.55 });\n      burst(ctx, out, t, 0.03, { type: \"lowpass\", from: 1200, q: 0.5, level: 0.2 });\n      break;\n    case \"tick\":\n      tone(ctx, out, t, 0.025, { type: \"triangle\", from: 1900, to: 1500, level: 0.25 });\n      break;\n    case \"pop\":\n      tone(ctx, out, t, 0.06, { from: 620, to: 980, level: 0.3 });\n      break;\n    case \"success\":\n      tone(ctx, out, t, 0.11, { from: 660, level: 0.22 });\n      tone(ctx, out, t + 0.09, 0.16, { from: 990, level: 0.22 });\n      break;\n    case \"error\":\n      tone(ctx, out, t, 0.12, { type: \"triangle\", from: 330, level: 0.25 });\n      tone(ctx, out, t + 0.1, 0.18, { type: \"triangle\", from: 247, level: 0.25 });\n      break;\n  }\n  window.setTimeout(() => out.disconnect(), 600);\n}\n"}],"css":{},"docs":"Docs and live preview: https://hairlineui.com/ui/camera-key. MIT licensed: https://hairlineui.com/license#components","meta":{"license":"MIT"}}