{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ai-voice-01",
  "title": "AI Voice 01",
  "description": "A voice-assistant pill with a canvas audio-reactive visualizer, idle/listening/speaking states, a glowing edge ring, live word-by-word transcript, optional real microphone input, and custom/silver themes.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/ai-voice-01/ai-voice-01.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\ntype RGB = [number, number, number];\ntype Status = \"idle\" | \"listening\" | \"speaking\";\ntype InputSource = \"simulated\" | \"microphone\";\ntype ThemeName = \"custom\" | \"silver\";\n\nexport interface AiVoice01Props {\n  status?: Status;\n  interactive?: boolean;\n  autoFlow?: boolean;\n  flowSeconds?: number;\n  input?: InputSource;\n  sensitivity?: number;\n  idleText?: string;\n  listeningText?: string;\n  speakingText?: string;\n  transcript?: boolean;\n  phrases?: string[];\n  font?: React.CSSProperties;\n  textColor?: string;\n  mutedColor?: string;\n  listenColors?: string[];\n  speakColors?: string[];\n  ringIntensity?: number;\n  ringSize?: number;\n  ringSpeed?: number;\n  background?: string;\n  borderColor?: string;\n  radius?: number;\n  padding?: number;\n  gap?: number;\n  curves?: number;\n  curveWidth?: number;\n  curveAmp?: number;\n  curveColor?: string;\n  theme?: ThemeName;\n  onStart?: () => void;\n  onStop?: () => void;\n  className?: string;\n  style?: React.CSSProperties;\n}\n\nconst TAU = Math.PI * 2;\nconst BANDS = 32;\nconst DOTS = 3;\nconst CONTROL = 44;\nconst START_ANGLE = 40;\nconst STATIC_SHIMMER = 72;\nconst EASE = \"cubic-bezier(0.2, 0.8, 0.2, 1)\";\nconst FONT_FALLBACK = \"Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif\";\nconst HAIRLINE = \"rgba(255,255,255,0.14)\";\nconst HOVER_ON = \"inset 0 0 0 999px rgba(255,255,255,0.06)\";\nconst HOVER_OFF = \"inset 0 0 0 999px rgba(255,255,255,0)\";\nconst RING = \"0 0 0 2px rgba(255,255,255,0.35)\";\nconst NO_RING = \"0 0 0 0 rgba(255,255,255,0)\";\nconst SILVER_EDGE =\n  \"linear-gradient(135deg, rgba(255,255,255,0.75), rgba(255,255,255,0.12) 38%, rgba(255,255,255,0.06) 62%, rgba(255,255,255,0.5))\";\nconst SILVER_SHEEN =\n  \"linear-gradient(115deg, rgba(255,255,255,0.09) 0%, rgba(255,255,255,0.02) 28%, rgba(255,255,255,0) 45%, rgba(255,255,255,0.05) 72%, rgba(255,255,255,0) 100%), linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0) 60%)\";\nconst MIC_FALLBACK = \"Microphone unavailable\";\n\nconst DEFAULT_PHRASES = [\"What's the weather like today?\", \"Book a table for two tonight\", \"Summarize my last meeting\"];\nconst DEFAULT_LISTEN = [\"#7CF3FF\", \"#6EA8FF\", \"#9B7BFF\"];\nconst DEFAULT_SPEAK = [\"#FF7BD5\", \"#FFB86B\", \"#F5C84C\"];\nconst SILVER_GLOW = [\"#FFFFFF\", \"#E4E7EB\", \"#A7AEB8\", \"#F5F6F8\", \"#8E959F\"];\nconst SILVER_SPEAK = [\"#F5F6F8\", \"#D9DCE1\", \"#A7AEB8\", \"#FFFFFF\", \"#8E959F\"];\n\nconst SR_ONLY: React.CSSProperties = {\n  position: \"absolute\",\n  width: 1,\n  height: 1,\n  overflow: \"hidden\",\n  clip: \"rect(0 0 0 0)\",\n  whiteSpace: \"nowrap\",\n};\n\ntype Mic = {\n  stream: MediaStream;\n  ctx: AudioContext;\n  analyser: AnalyserNode;\n  data: ReturnType<typeof makeData>;\n};\n\nfunction makeData(n: number) {\n  return new Uint8Array(n);\n}\n\ntype Live = {\n  mode: Status;\n  input: InputSource;\n  sens: number;\n  level: number;\n  bands: Float32Array;\n  target: Float32Array;\n  time: number;\n  phase: number;\n  rot: number;\n  angle: number;\n  ringSpeed: number;\n  aura: number;\n  base: RGB;\n  accent: RGB;\n  vis: VisParams;\n};\n\nfunction clamp01(v: number) {\n  return Math.min(1, Math.max(0, v));\n}\n\nfunction parseRgb(input: string, fallback: RGB): RGB {\n  const s = (input || \"\").trim();\n  if (s.startsWith(\"#\")) {\n    let h = s.slice(1);\n    if (h.length === 3 || h.length === 4)\n      h = h\n        .split(\"\")\n        .map((c) => c + c)\n        .join(\"\");\n    const n = parseInt(h.slice(0, 6), 16);\n    if (h.length >= 6 && !Number.isNaN(n)) return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n  }\n  const m = s.match(/rgba?\\(\\s*([\\d.]+)[,\\s]+([\\d.]+)[,\\s]+([\\d.]+)/i);\n  if (m) return [Math.round(+m[1]), Math.round(+m[2]), Math.round(+m[3])];\n  return fallback;\n}\n\nfunction cleanList(list: string[] | undefined, fallback: string[]) {\n  const out = (list ?? []).filter((s): s is string => typeof s === \"string\" && s.trim() !== \"\");\n  return out.length ? out : fallback;\n}\n\nfunction buildGradient(colors: string[], spread: number) {\n  const arc = Math.max(0.15, Math.min(1, spread)) * 360;\n  const n = colors.length;\n  if (n === 0) return \"linear-gradient(transparent, transparent)\";\n  const stops = colors.map((c, i) => {\n    const at = n === 1 ? 0.5 : 0.1 + (0.8 * i) / (n - 1);\n    return `${c} ${(at * arc).toFixed(1)}deg`;\n  });\n  return `conic-gradient(from var(--gl-angle, ${START_ANGLE}deg), transparent 0deg, ${stops.join(\", \")}, transparent ${arc.toFixed(1)}deg, transparent 360deg)`;\n}\n\nfunction ringStyle(width: number): React.CSSProperties {\n  return {\n    position: \"absolute\",\n    inset: 0,\n    boxSizing: \"border-box\",\n    borderRadius: \"inherit\",\n    padding: width,\n    WebkitMask: \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n    WebkitMaskComposite: \"xor\",\n    mask: \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n    maskComposite: \"exclude\",\n  };\n}\n\nfunction simulateBands(t: number, mode: Status, out: Float32Array) {\n  const n = out.length;\n  let base = 0;\n  if (mode === \"idle\") {\n    base = 0.02 + 0.015 * Math.sin(t * 1.3);\n  } else if (mode === \"listening\") {\n    const x = 0.5 + 0.5 * Math.sin(t * 0.9 + 1.7 * Math.sin(t * 0.37));\n    const gate = clamp01((x - 0.35) / 0.3);\n    const syll = 0.55 + 0.45 * Math.sin(t * 7.3) * Math.sin(t * 2.1 + 0.6);\n    base = gate * gate * (3 - 2 * gate) * syll;\n  } else {\n    const syll = 0.6 + 0.4 * Math.sin(t * 5.2) * Math.sin(t * 1.6);\n    base = (0.85 + 0.15 * Math.sin(t * 1.1)) * syll;\n  }\n  for (let i = 0; i < n; i++) {\n    const f = i / (n - 1);\n    const shape = 0.25 + 0.75 * Math.exp(-Math.pow((f - 0.28) / 0.3, 2));\n    const v = 0.5 + 0.5 * Math.sin(t * (3.1 + i * 0.53) + i * 1.9) * Math.sin(t * (1.3 + i * 0.21) + i);\n    out[i] = clamp01(base * shape * (0.35 + 0.65 * v) * 0.9);\n  }\n}\n\nfunction readMic(mic: Mic, sens: number, out: Float32Array) {\n  mic.analyser.getByteFrequencyData(mic.data);\n  const n = out.length;\n  const bins = mic.data.length;\n  const lo = 1;\n  const hi = Math.min(bins - 1, 44);\n  for (let i = 0; i < n; i++) {\n    const a = lo + Math.floor(Math.pow(i / n, 1.5) * (hi - lo));\n    const b = Math.max(a + 1, lo + Math.floor(Math.pow((i + 1) / n, 1.5) * (hi - lo)));\n    const end = Math.min(b, bins);\n    let s = 0;\n    for (let j = a; j < end; j++) s += mic.data[j];\n    const v = s / Math.max(1, end - a) / 255;\n    out[i] = clamp01(Math.pow(v * sens, 1.15));\n  }\n}\n\nfunction updateAudio(L: Live, mic: Mic | null, dt: number) {\n  const n = L.bands.length;\n  if (L.mode === \"listening\" && L.input === \"microphone\" && mic) readMic(mic, L.sens, L.target);\n  else simulateBands(L.time, L.mode, L.target);\n  let sum = 0;\n  for (let i = 0; i < n; i++) {\n    const tv = L.target[i];\n    const cur = L.bands[i];\n    const k = tv > cur ? Math.min(1, dt * 22) : Math.min(1, dt * 6);\n    L.bands[i] = cur + (tv - cur) * k;\n    sum += L.bands[i];\n  }\n  const lv = clamp01((sum / n) * 2.4);\n  L.level += (lv - L.level) * Math.min(1, dt * 14);\n}\n\nconst SMOOTH_A = new Float32Array(BANDS);\nconst SMOOTH_B = new Float32Array(BANDS);\n\nfunction smoothBands(src: Float32Array): Float32Array {\n  const n = src.length;\n  for (let i = 0; i < n; i++) SMOOTH_A[i] = 0.25 * src[Math.max(0, i - 1)] + 0.5 * src[i] + 0.25 * src[Math.min(n - 1, i + 1)];\n  for (let i = 0; i < n; i++) SMOOTH_B[i] = 0.25 * SMOOTH_A[Math.max(0, i - 1)] + 0.5 * SMOOTH_A[i] + 0.25 * SMOOTH_A[Math.min(n - 1, i + 1)];\n  return SMOOTH_B;\n}\n\ntype VisParams = { curves: number; thick: number; amp: number; rgb: RGB };\n\nconst CURVE_POINTS = 96;\nconst REST_GAP = 3;\n\nfunction innerFrac(R: number) {\n  return Math.min(0.85, (CONTROL / 2 + REST_GAP) / Math.max(1, R));\n}\n\nfunction curveRadius(\n  l: number,\n  theta: number,\n  bands: Float32Array,\n  level: number,\n  phase: number,\n  rot: number,\n  amp: number,\n  R: number,\n  inner: number,\n) {\n  const dir = l % 2 === 0 ? 1 : -1;\n  const f = Math.abs(Math.sin((theta + rot * 0.3 * dir) / 2));\n  const bf = f * (bands.length - 1);\n  const i0 = Math.floor(bf);\n  const i1 = Math.min(bands.length - 1, i0 + 1);\n  const band = bands[i0] + (bands[i1] - bands[i0]) * (bf - i0);\n  const energy = 0.04 + band * 0.96 + level * 0.18;\n  const wave = 0.5 + 0.5 * Math.sin((3 + l) * theta + phase * (1.1 + l * 0.5) * dir + l * 1.9);\n  const base = inner + 0.03 * l;\n  return R * Math.min(0.98, base + (0.98 - base) * 0.5 * energy * wave * amp);\n}\n\nfunction visDraw(ctx: CanvasRenderingContext2D, w: number, h: number, L: Live) {\n  const { curves, thick, amp, rgb } = L.vis;\n  const [ar, ag, ab] = L.accent;\n  const [br, bg, bb] = rgb;\n  const cx = w / 2;\n  const cy = h / 2;\n  const R = (Math.min(w, h) / 2) * 0.98;\n  const inner = innerFrac(R);\n  const bands = smoothBands(L.bands);\n  ctx.globalCompositeOperation = \"lighter\";\n  ctx.lineJoin = \"round\";\n  for (let l = 0; l < curves; l++) {\n    ctx.beginPath();\n    for (let i = 0; i <= CURVE_POINTS; i++) {\n      const theta = (i / CURVE_POINTS) * TAU;\n      const r = curveRadius(l, theta, bands, L.level, L.phase, L.rot, amp, R, inner);\n      const x = cx + Math.sin(theta) * r;\n      const y = cy - Math.cos(theta) * r;\n      if (i === 0) ctx.moveTo(x, y);\n      else ctx.lineTo(x, y);\n    }\n    ctx.closePath();\n    const a = Math.max(0.3, 0.95 - l * 0.22);\n    let stroke: string | CanvasGradient = `rgba(${ar},${ag},${ab},${a.toFixed(2)})`;\n    if (typeof ctx.createConicGradient === \"function\") {\n      const g = ctx.createConicGradient(L.rot * 0.5 * (l % 2 === 0 ? 1 : -1) - Math.PI / 2, cx, cy);\n      g.addColorStop(0, `rgba(${br},${bg},${bb},${a.toFixed(2)})`);\n      g.addColorStop(0.35, `rgba(${ar},${ag},${ab},${(a * 0.9).toFixed(2)})`);\n      g.addColorStop(0.65, `rgba(${ar},${ag},${ab},${(a * 0.35).toFixed(2)})`);\n      g.addColorStop(1, `rgba(${br},${bg},${bb},${a.toFixed(2)})`);\n      stroke = g;\n    }\n    ctx.strokeStyle = stroke;\n    ctx.globalAlpha = 0.25;\n    ctx.lineWidth = (5 - l * 0.8) * thick;\n    ctx.stroke();\n    ctx.globalAlpha = 1;\n    ctx.lineWidth = Math.max(1, (2.2 - l * 0.4) * thick);\n    ctx.stroke();\n  }\n  ctx.globalCompositeOperation = \"source-over\";\n}\n\nfunction useFocusVisible() {\n  const [focusVisible, setFocusVisible] = React.useState(false);\n  return {\n    focusVisible,\n    onFocus: (e: React.FocusEvent<HTMLElement>) => {\n      try {\n        setFocusVisible(e.currentTarget.matches(\":focus-visible\"));\n      } catch {\n        setFocusVisible(true);\n      }\n    },\n    onBlur: () => setFocusVisible(false),\n  };\n}\n\nconst MicIcon = () => (\n  <svg\n    width={18}\n    height={18}\n    viewBox=\"0 0 24 24\"\n    fill=\"none\"\n    stroke=\"currentColor\"\n    strokeWidth={2}\n    strokeLinecap=\"round\"\n    strokeLinejoin=\"round\"\n    aria-hidden=\"true\"\n    focusable=\"false\"\n    style={{ display: \"block\" }}\n  >\n    <rect x=\"9\" y=\"3\" width=\"6\" height=\"11\" rx=\"3\" />\n    <path d=\"M5 11a7 7 0 0 0 14 0\" />\n    <path d=\"M12 18v3\" />\n  </svg>\n);\nconst StopIcon = () => (\n  <svg width={24} height={24} viewBox=\"0 0 24 24\" fill=\"currentColor\" aria-hidden=\"true\" focusable=\"false\" style={{ display: \"block\" }}>\n    <rect x=\"4\" y=\"4\" width=\"16\" height=\"16\" rx=\"4\" />\n  </svg>\n);\n\ntype RoundButtonProps = {\n  label: string;\n  pressed: boolean;\n  onClick: () => void;\n  background: string;\n  color: string;\n  size?: number;\n  children: React.ReactNode;\n};\n\nfunction RoundButton({ label, pressed: isOn, onClick, background, color, size = CONTROL, children }: RoundButtonProps) {\n  const [hover, setHover] = React.useState(false);\n  const [pressed, setPressed] = React.useState(false);\n  const focus = useFocusVisible();\n  const release = () => setPressed(false);\n  return (\n    <button\n      type=\"button\"\n      aria-label={label}\n      aria-pressed={isOn}\n      onClick={onClick}\n      onMouseEnter={() => setHover(true)}\n      onMouseLeave={() => setHover(false)}\n      onPointerDown={() => setPressed(true)}\n      onPointerUp={release}\n      onPointerLeave={release}\n      onPointerCancel={release}\n      onFocus={focus.onFocus}\n      onBlur={focus.onBlur}\n      style={{\n        width: size,\n        height: size,\n        flex: \"none\",\n        margin: 0,\n        padding: 0,\n        display: \"flex\",\n        alignItems: \"center\",\n        justifyContent: \"center\",\n        borderRadius: \"50%\",\n        border: `1px solid ${HAIRLINE}`,\n        background,\n        color,\n        cursor: \"pointer\",\n        outline: \"none\",\n        transform: pressed ? \"scale(0.92)\" : \"scale(1)\",\n        boxShadow: `${hover ? HOVER_ON : HOVER_OFF}, ${focus.focusVisible ? RING : NO_RING}`,\n        transition: \"background-color 0.25s ease, color 0.25s ease, box-shadow 0.2s ease, transform 0.15s ease\",\n      }}\n    >\n      {children}\n    </button>\n  );\n}\n\nexport function AiVoice01(props: AiVoice01Props) {\n  const {\n    status = \"idle\",\n    interactive = true,\n    autoFlow = true,\n    flowSeconds = 3.5,\n    input = \"simulated\",\n    sensitivity = 1.4,\n    idleText = \"Tap to speak\",\n    listeningText = \"Listening\",\n    speakingText = \"Speaking\",\n    transcript = true,\n    phrases = DEFAULT_PHRASES,\n    font = { fontSize: 16, lineHeight: 1.2 },\n    textColor = \"#EDEDED\",\n    mutedColor = \"#6B6B6B\",\n    listenColors = DEFAULT_LISTEN,\n    speakColors = DEFAULT_SPEAK,\n    ringIntensity = 0.7,\n    ringSize = 10,\n    ringSpeed = 40,\n    background = \"rgba(255,255,255,0.035)\",\n    borderColor = \"rgba(255,255,255,0.08)\",\n    radius = 999,\n    padding = 10,\n    gap = 12,\n    curves = 3,\n    curveWidth = 1,\n    curveAmp = 1,\n    curveColor = \"#FFFFFF\",\n    theme = \"custom\",\n    onStart,\n    onStop,\n    className,\n    style,\n  } = props;\n\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const visualRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const ringListenRef = React.useRef<HTMLDivElement>(null);\n  const ringSpeakRef = React.useRef<HTMLDivElement>(null);\n  const textEls = React.useRef<(HTMLSpanElement | null)[]>([]);\n  const dotEls = React.useRef<(HTMLSpanElement | null)[]>([]);\n  const isVisibleRef = React.useRef(true);\n  const micRef = React.useRef<Mic | null>(null);\n  const micGen = React.useRef(0);\n  const flowTimerRef = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n  const typeTimerRef = React.useRef<ReturnType<typeof setInterval> | null>(null);\n  const rafRef = React.useRef(0);\n  const prevMode = React.useRef<Status>(status);\n\n  const [manual, setManual] = React.useState<Status | null>(null);\n  const [typed, setTyped] = React.useState(\"\");\n  const [micError, setMicError] = React.useState(\"\");\n  const mode: Status = manual ?? status;\n\n  const isSilver = theme === \"silver\";\n\n  const resolvedText = isSilver ? \"#E4E6EA\" : textColor;\n  const resolvedMuted = isSilver ? \"#6F747B\" : mutedColor;\n  const resolvedBg = isSilver ? \"#1B1C1E\" : background;\n  const resolvedBorder = isSilver ? \"rgba(255,255,255,0.08)\" : borderColor;\n  const resolvedCurve = isSilver ? \"#F2F4F7\" : curveColor;\n  const idleBtnBg = isSilver ? \"#2A2C2F\" : \"rgba(255,255,255,0.08)\";\n  const stopBtnFg = isSilver ? \"#141414\" : \"#0E0E10\";\n\n  const listenList = React.useMemo(() => cleanList(isSilver ? SILVER_GLOW : listenColors, DEFAULT_LISTEN), [isSilver, listenColors]);\n  const speakList = React.useMemo(() => cleanList(isSilver ? SILVER_SPEAK : speakColors, DEFAULT_SPEAK), [isSilver, speakColors]);\n  const phraseList = React.useMemo(() => cleanList(phrases, DEFAULT_PHRASES), [phrases]);\n  const listenGradient = React.useMemo(() => buildGradient(listenList, 0.55), [listenList]);\n  const speakGradient = React.useMemo(() => buildGradient(speakList, 0.55), [speakList]);\n  const listenRgb = React.useMemo(() => parseRgb(listenList[0], [124, 243, 255]), [listenList]);\n  const speakRgb = React.useMemo(() => parseRgb(speakList[0], [255, 123, 213]), [speakList]);\n  const curveCount = Math.max(1, Math.min(4, Math.round(curves)));\n  const visBase = React.useMemo(() => parseRgb(resolvedCurve, [255, 255, 255]), [resolvedCurve]);\n  const visParams = React.useMemo<VisParams>(\n    () => ({ curves: curveCount, thick: curveWidth, amp: curveAmp, rgb: visBase }),\n    [curveCount, curveWidth, curveAmp, visBase],\n  );\n  const visKey = `${curveCount}`;\n  const accent = mode === \"speaking\" ? speakRgb : listenRgb;\n  const liveInput: InputSource = input === \"microphone\" && !micError ? \"microphone\" : \"simulated\";\n\n  const liveRef = React.useRef<Live>({\n    mode,\n    input: liveInput,\n    sens: sensitivity,\n    level: 0,\n    bands: new Float32Array(BANDS),\n    target: new Float32Array(BANDS),\n    time: 0,\n    phase: 0,\n    rot: 0,\n    angle: START_ANGLE,\n    ringSpeed,\n    aura: 0,\n    base: visBase,\n    accent,\n    vis: visParams,\n  });\n  React.useLayoutEffect(() => {\n    liveRef.current.mode = mode;\n    liveRef.current.input = liveInput;\n    liveRef.current.sens = sensitivity;\n    liveRef.current.ringSpeed = ringSpeed;\n    liveRef.current.aura = 0;\n    liveRef.current.base = visBase;\n    liveRef.current.accent = accent;\n    liveRef.current.vis = visParams;\n  });\n\n  const stopMic = () => {\n    micGen.current += 1;\n    const m = micRef.current;\n    micRef.current = null;\n    if (m) {\n      m.stream.getTracks().forEach((t) => t.stop());\n      m.ctx.close().catch(() => undefined);\n    }\n  };\n\n  const startMic = async () => {\n    stopMic();\n    setMicError(\"\");\n    const gen = micGen.current;\n    const devices = typeof navigator !== \"undefined\" ? navigator.mediaDevices : undefined;\n    if (!devices || typeof devices.getUserMedia !== \"function\") {\n      setMicError(MIC_FALLBACK);\n      return;\n    }\n    const Ctor = window.AudioContext || (window as Window & { webkitAudioContext?: typeof AudioContext }).webkitAudioContext;\n    if (!Ctor) {\n      setMicError(MIC_FALLBACK);\n      return;\n    }\n    let ctx: AudioContext | null = null;\n    try {\n      ctx = new Ctor();\n      const stream = await devices.getUserMedia({ audio: true });\n      if (gen !== micGen.current) {\n        stream.getTracks().forEach((t) => t.stop());\n        ctx.close().catch(() => undefined);\n        return;\n      }\n      const analyser = ctx.createAnalyser();\n      analyser.fftSize = 512;\n      analyser.smoothingTimeConstant = 0.6;\n      ctx.createMediaStreamSource(stream).connect(analyser);\n      micRef.current = { stream, ctx, analyser, data: makeData(analyser.frequencyBinCount) };\n      setMicError(\"\");\n    } catch {\n      if (ctx) ctx.close().catch(() => undefined);\n      if (gen === micGen.current) setMicError(MIC_FALLBACK);\n    }\n  };\n\n  const toggle = () => {\n    const next: Status = mode === \"idle\" ? \"listening\" : \"idle\";\n    setManual(next);\n    if (next === \"idle\") {\n      setMicError(\"\");\n      stopMic();\n      return;\n    }\n    if (input === \"microphone\") void startMic();\n    else stopMic();\n  };\n\n  const [prevExternal, setPrevExternal] = React.useState({ status, input });\n  if (prevExternal.status !== status || prevExternal.input !== input) {\n    setPrevExternal({ status, input });\n    setManual(null);\n    setMicError(\"\");\n  }\n\n  React.useEffect(() => {\n    if (!autoFlow || input === \"microphone\" || manual === null) return;\n    if (manual === \"idle\") return;\n    if (flowTimerRef.current) clearTimeout(flowTimerRef.current);\n    flowTimerRef.current = setTimeout(\n      () => {\n        setManual(manual === \"listening\" ? \"speaking\" : \"idle\");\n      },\n      Math.max(0.5, flowSeconds) * 1000,\n    );\n    return () => {\n      if (flowTimerRef.current) clearTimeout(flowTimerRef.current);\n    };\n  }, [autoFlow, input, manual, flowSeconds]);\n\n  React.useEffect(() => {\n    if (mode !== \"listening\") stopMic();\n    const prev = prevMode.current;\n    prevMode.current = mode;\n    if (prev === \"idle\" && mode !== \"idle\") onStart?.();\n    else if (prev !== \"idle\" && mode === \"idle\") onStop?.();\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [mode]);\n\n  React.useEffect(() => {\n    return () => {\n      stopMic();\n      if (flowTimerRef.current) clearTimeout(flowTimerRef.current);\n      if (typeTimerRef.current) clearInterval(typeTimerRef.current);\n      if (rafRef.current) cancelAnimationFrame(rafRef.current);\n    };\n  }, []);\n\n  const shouldType = mode === \"listening\" && transcript && !micError;\n  const [prevShouldType, setPrevShouldType] = React.useState(shouldType);\n  if (prevShouldType !== shouldType) {\n    setPrevShouldType(shouldType);\n    if (!shouldType) setTyped(\"\");\n  }\n\n  React.useEffect(() => {\n    if (!shouldType) return;\n    let p = 0;\n    let w = 0;\n    let hold = 0;\n    if (typeTimerRef.current) clearInterval(typeTimerRef.current);\n    typeTimerRef.current = setInterval(() => {\n      if (!isVisibleRef.current) return;\n      const words = phraseList[p % phraseList.length].split(\" \");\n      if (w < words.length) {\n        w += 1;\n        setTyped(words.slice(0, w).join(\" \"));\n      } else if (hold < 8) {\n        hold += 1;\n      } else {\n        p += 1;\n        w = 0;\n        hold = 0;\n        setTyped(\"\");\n      }\n    }, 210);\n    return () => {\n      if (typeTimerRef.current) clearInterval(typeTimerRef.current);\n    };\n  }, [shouldType, phraseList]);\n\n  React.useEffect(() => {\n    const el = rootRef.current;\n    if (!el) return;\n    const io = new IntersectionObserver(\n      ([entry]) => {\n        isVisibleRef.current = entry.isIntersecting;\n      },\n      { threshold: 0 },\n    );\n    io.observe(el);\n    return () => io.disconnect();\n  }, []);\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const wrap = visualRef.current;\n    const canvas = canvasRef.current;\n    if (!root || !wrap || !canvas) return;\n    const ctx = canvas.getContext(\"2d\");\n    if (!ctx) return;\n\n    let w = 0;\n    let h = 0;\n    let last = performance.now();\n\n    const fit = () => {\n      const dpr = Math.min(window.devicePixelRatio || 1, 2);\n      w = wrap.clientWidth;\n      h = wrap.clientHeight;\n      canvas.width = Math.max(2, Math.round(w * dpr));\n      canvas.height = Math.max(2, Math.round(h * dpr));\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n    };\n    const draw = () => {\n      if (w <= 0 || h <= 0) return;\n      ctx.clearRect(0, 0, w, h);\n      visDraw(ctx, w, h, liveRef.current);\n    };\n    const updateDom = (L: Live) => {\n      const t = L.time;\n      const pos = 100 - 100 * ((t / 2.4) % 1);\n      for (const node of textEls.current) if (node) node.style.backgroundPosition = `${pos.toFixed(2)}% 50%`;\n      for (let i = 0; i < dotEls.current.length; i++) {\n        const node = dotEls.current[i];\n        if (!node) continue;\n        const d = i % DOTS;\n        node.style.opacity = (0.2 + 0.7 * (0.5 + 0.5 * Math.sin(t * 4.2 - d * 0.9))).toFixed(3);\n      }\n      const ringOpacity = (0.3 + 0.7 * L.level).toFixed(3);\n      if (ringListenRef.current) ringListenRef.current.style.opacity = ringOpacity;\n      if (ringSpeakRef.current) ringSpeakRef.current.style.opacity = ringOpacity;\n    };\n\n    fit();\n    const ro = new ResizeObserver(() => {\n      fit();\n      draw();\n    });\n    ro.observe(wrap);\n\n    const reduce = typeof window.matchMedia === \"function\" && window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    if (reduce) {\n      const L = liveRef.current;\n      simulateBands(1.2, L.mode === \"idle\" ? \"listening\" : L.mode, L.bands);\n      L.level = 0.3;\n      root.style.setProperty(\"--gl-angle\", `${START_ANGLE}deg`);\n      draw();\n      return () => ro.disconnect();\n    }\n\n    const frame = (now: number) => {\n      const dt = Math.min((now - last) / 1000, 0.05);\n      last = now;\n      if (isVisibleRef.current) {\n        const L = liveRef.current;\n        L.time += dt;\n        L.angle = (L.angle + L.ringSpeed * (L.mode === \"idle\" ? 0.5 : 1) * dt) % 360;\n        updateAudio(L, micRef.current, dt);\n        L.phase += dt * (1 + 1.6 * L.level);\n        L.rot += dt * 0.45 * (1 + L.level);\n        root.style.setProperty(\"--gl-angle\", `${L.angle.toFixed(2)}deg`);\n        draw();\n        updateDom(L);\n      }\n      rafRef.current = requestAnimationFrame(frame);\n    };\n    rafRef.current = requestAnimationFrame(frame);\n\n    return () => {\n      cancelAnimationFrame(rafRef.current);\n      ro.disconnect();\n    };\n  }, [visKey]);\n\n  const typography: React.CSSProperties = {\n    fontFamily: FONT_FALLBACK,\n    lineHeight: 1.2,\n    ...font,\n    margin: 0,\n  };\n\n  const listenLabel = micError ? MIC_FALLBACK : typed || listeningText;\n  const items = [\n    { text: idleText, dots: false },\n    { text: listenLabel, dots: false },\n    { text: speakingText, dots: true },\n  ];\n  const cur = mode === \"idle\" ? 0 : mode === \"listening\" ? 1 : 2;\n  const liveLabel = mode === \"idle\" ? idleText : mode === \"listening\" ? listenLabel : speakingText;\n  const shimmerGradient = `linear-gradient(90deg, ${resolvedMuted} 0%, ${resolvedMuted} 32%, ${resolvedText} 50%, ${resolvedMuted} 68%, ${resolvedMuted} 100%)`;\n  const softRing = Math.max(2, Math.min(18, ringSize * 0.45));\n  const softBlur = ringSize * 0.7;\n\n  const ringLayer = (active: boolean, gradient: string, ref: { current: HTMLDivElement | null }) => (\n    <div\n      aria-hidden=\"true\"\n      style={{\n        position: \"absolute\",\n        inset: 0,\n        borderRadius: \"inherit\",\n        pointerEvents: \"none\",\n        opacity: active ? ringIntensity : 0,\n        transition: \"opacity 0.5s ease\",\n      }}\n    >\n      <div ref={ref} style={{ position: \"absolute\", inset: 0, borderRadius: \"inherit\", opacity: 0.55 }}>\n        <div style={{ position: \"absolute\", inset: 0, borderRadius: \"inherit\", filter: `blur(${softBlur}px)` }}>\n          <div style={{ ...ringStyle(softRing), background: gradient }} />\n        </div>\n        <div style={{ ...ringStyle(1.5), background: gradient }} />\n      </div>\n    </div>\n  );\n\n  const visualNode = (\n    <div ref={visualRef} aria-hidden=\"true\" style={{ position: \"absolute\", inset: 0 }}>\n      <canvas ref={canvasRef} style={{ position: \"relative\", width: \"100%\", height: \"100%\", display: \"block\" }} />\n    </div>\n  );\n\n  const textNode = (\n    <div style={{ display: \"flex\", alignItems: \"center\", overflow: \"hidden\", flex: 1, minWidth: 0 }}>\n      <p style={{ ...typography, ...SR_ONLY, color: resolvedText, WebkitTextFillColor: resolvedText }}>Voice assistant. {liveLabel}</p>\n      <div aria-hidden=\"true\" style={{ display: \"grid\", gridTemplateColumns: \"minmax(0, 1fr)\", width: \"100%\", minWidth: 0 }}>\n        {items.map((item, i) => {\n          const on = i === cur;\n          return (\n            <div\n              key={i}\n              style={{\n                gridArea: \"1 / 1\",\n                display: \"flex\",\n                alignItems: \"baseline\",\n                justifyContent: \"flex-start\",\n                minWidth: 0,\n                opacity: on ? 1 : 0,\n                transform: on ? \"translateY(0px)\" : \"translateY(6px)\",\n                transition: `opacity 0.45s ease, transform 0.45s ${EASE}`,\n              }}\n            >\n              <span\n                ref={(el) => {\n                  textEls.current[i] = el;\n                }}\n                style={{\n                  ...typography,\n                  display: \"block\",\n                  minWidth: 0,\n                  overflow: \"hidden\",\n                  textOverflow: \"ellipsis\",\n                  whiteSpace: \"nowrap\",\n                  color: \"transparent\",\n                  backgroundImage: shimmerGradient,\n                  backgroundSize: \"300% 100%\",\n                  backgroundPosition: `${STATIC_SHIMMER}% 50%`,\n                  WebkitBackgroundClip: \"text\",\n                  backgroundClip: \"text\",\n                  WebkitTextFillColor: \"transparent\",\n                }}\n              >\n                {item.text}\n              </span>\n              {item.dots && (\n                <span style={{ ...typography, display: \"flex\", flex: \"none\", color: resolvedText, marginLeft: 1 }}>\n                  {Array.from({ length: DOTS }, (_, d) => (\n                    <span\n                      key={d}\n                      ref={(el) => {\n                        dotEls.current[i * DOTS + d] = el;\n                      }}\n                      style={{ opacity: 0.55 }}\n                    >\n                      .\n                    </span>\n                  ))}\n                </span>\n              )}\n            </div>\n          );\n        })}\n      </div>\n    </div>\n  );\n\n  const buttonNode = interactive ? (\n    <RoundButton\n      label={mode === \"idle\" ? \"Start voice input\" : \"Stop voice input\"}\n      pressed={mode !== \"idle\"}\n      onClick={toggle}\n      size={44}\n      background={mode === \"idle\" ? idleBtnBg : resolvedText}\n      color={mode === \"idle\" ? resolvedText : stopBtnFg}\n    >\n      {mode === \"idle\" ? <MicIcon /> : <StopIcon />}\n    </RoundButton>\n  ) : null;\n\n  return (\n    <div className={cn(\"relative flex h-full w-full flex-col overflow-hidden\", className)} style={style}>\n      <div\n        ref={rootRef}\n        role=\"region\"\n        aria-label=\"Voice assistant\"\n        aria-busy={mode !== \"idle\"}\n        style={{\n          position: \"relative\",\n          display: \"flex\",\n          gap,\n          boxSizing: \"border-box\",\n          width: \"100%\",\n          flex: 1,\n          minHeight: 0,\n          padding,\n          overflow: \"hidden\",\n          borderRadius: radius,\n          background: resolvedBg,\n          backgroundImage: isSilver ? SILVER_SHEEN : \"linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0) 60%)\",\n          border: `1px solid ${resolvedBorder}`,\n          boxShadow: isSilver ? \"inset 0 0 0 1px rgba(255,255,255,0.08), inset 0 1px 0 rgba(255,255,255,0.22)\" : undefined,\n          backdropFilter: isSilver ? \"none\" : \"blur(14px)\",\n          WebkitBackdropFilter: isSilver ? \"none\" : \"blur(14px)\",\n          alignItems: \"center\",\n        }}\n      >\n        <span role=\"status\" aria-live=\"polite\" aria-atomic=\"true\" style={SR_ONLY}>\n          {liveLabel}\n        </span>\n\n        {ringLayer(mode === \"listening\", listenGradient, ringListenRef)}\n        {ringLayer(mode === \"speaking\", speakGradient, ringSpeakRef)}\n        {isSilver && <div aria-hidden=\"true\" style={{ ...ringStyle(1), background: SILVER_EDGE, opacity: 0.85, pointerEvents: \"none\" }} />}\n\n        <div style={{ position: \"relative\", flex: \"none\", height: \"100%\", aspectRatio: \"1 / 1\" }}>\n          {visualNode}\n          <div style={{ position: \"absolute\", inset: 0, display: \"flex\", alignItems: \"center\", justifyContent: \"center\" }}>{buttonNode}</div>\n        </div>\n        {textNode}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}