{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ai-voice-05",
  "title": "AI Voice 05",
  "description": "A portrait voice-assistant card with a canvas audio-reactive curve visualizer, a mic button that grows on tap, idle/listening/speaking states, and live word-by-word transcript.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/ai-voice-05/ai-voice-05.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\";\n\nexport interface AiVoice05Props {\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  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 CURVE_POINTS = 96;\nconst REST_GAP = 3;\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)\";\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\"];\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  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 mixRgb(a: RGB, b: RGB, t: number): RGB {\n  return [Math.round(a[0] + (b[0] - a[0]) * t), Math.round(a[1] + (b[1] - a[1]) * t), Math.round(a[2] + (b[2] - a[2]) * t)];\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 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\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  curves: number,\n) {\n  const t = curves === 1 ? 0.5 : l / (curves - 1);\n  const dir = l % 2 === 0 ? 1 : -1;\n  const f = Math.abs(Math.sin((theta + rot * 0.6 * dir + l * 0.4) / 2));\n  const v = bands[Math.min(bands.length - 1, Math.floor(f * (bands.length - 1)))];\n  const e = clamp01(0.65 * v + 0.35 * level);\n  const wave = Math.sin(theta * (2.5 + 0.9 * t) + phase * (1.7 + 0.35 * l) + rot * dir) * Math.sin(theta * (1.2 + 0.35 * l) - phase * 0.6);\n  const base = inner + 0.06 + t * 0.18;\n  const ripple = (0.02 + 0.055 * e) * amp * (0.75 + 0.45 * (1 - t));\n  const swell = 0.012 * amp * wave;\n  const rFrac = base + ripple + swell;\n  return Math.min(0.98, Math.max(inner + 0.015, rFrac)) * R;\n}\n\nfunction visDraw(ctx: CanvasRenderingContext2D, w: number, h: number, L: Live) {\n  const vis = L.vis;\n  const cx = w / 2;\n  const cy = h / 2;\n  const R = (Math.min(w, h) / 2) * 0.94;\n  const inner = innerFrac(R);\n  const bands = smoothBands(L.bands);\n  ctx.clearRect(0, 0, w, h);\n  const fallback = `rgba(${vis.rgb[0]},${vis.rgb[1]},${vis.rgb[2]},0.92)`;\n  let stroke: CanvasGradient | string = fallback;\n  if (typeof ctx.createConicGradient === \"function\") {\n    const grad = ctx.createConicGradient(L.rot * 0.8, cx, cy);\n    const m0 = mixRgb(vis.rgb, L.accent, 0.15);\n    const m1 = mixRgb(vis.rgb, L.accent, 0.72);\n    const m2 = mixRgb(vis.rgb, L.accent, 0.25);\n    grad.addColorStop(0, `rgb(${m0.join(\",\")})`);\n    grad.addColorStop(0.38, `rgb(${m1.join(\",\")})`);\n    grad.addColorStop(0.74, `rgb(${m2.join(\",\")})`);\n    grad.addColorStop(1, `rgb(${m0.join(\",\")})`);\n    stroke = grad;\n  }\n  ctx.globalCompositeOperation = \"source-over\";\n  for (let l = 0; l < vis.curves; l++) {\n    ctx.beginPath();\n    for (let i = 0; i <= CURVE_POINTS; i++) {\n      const theta = (i / CURVE_POINTS) * TAU;\n      const radius = curveRadius(l, theta, bands, L.level, L.phase, L.rot, vis.amp, R, inner, vis.curves);\n      const x = cx + Math.sin(theta) * radius;\n      const y = cy - Math.cos(theta) * radius;\n      if (i === 0) ctx.moveTo(x, y);\n      else ctx.lineTo(x, y);\n    }\n    ctx.closePath();\n    ctx.strokeStyle = stroke;\n    ctx.lineCap = \"round\";\n    ctx.lineJoin = \"round\";\n    ctx.globalAlpha = 1;\n    ctx.lineWidth = Math.max(0.4, vis.thick * (1.08 - l * 0.13));\n    ctx.stroke();\n  }\n  ctx.globalAlpha = 1;\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    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);\n\nconst StopIcon = () => (\n  <svg width={44} height={44} viewBox=\"0 0 24 24\" fill=\"currentColor\" aria-hidden=\"true\" style={{ display: \"block\" }}>\n    <rect x=\"4.5\" y=\"4.5\" width=\"15\" height=\"15\" 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: ariaPressed, 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={ariaPressed}\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 AiVoice05(props: AiVoice05Props) {\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    background = \"rgba(255,255,255,0.035)\",\n    borderColor = \"rgba(255,255,255,0.08)\",\n    radius = 44,\n    padding = 16,\n    gap = 10,\n    curves = 3,\n    curveWidth = 1,\n    curveAmp = 1,\n    curveColor = \"#FFFFFF\",\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 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 prevMode = React.useRef<Status>(status);\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\n  const [manual, setManual] = React.useState<Status | null>(null);\n  const [typed, setTyped] = React.useState(\"\");\n  const mode: Status = manual ?? status;\n\n  const listenList = React.useMemo(() => cleanList(listenColors, DEFAULT_LISTEN), [listenColors]);\n  const speakList = React.useMemo(() => cleanList(speakColors, DEFAULT_SPEAK), [speakColors]);\n  const phraseList = React.useMemo(() => cleanList(phrases, DEFAULT_PHRASES), [phrases]);\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(curveColor, [255, 255, 255]), [curveColor]);\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}-${curveWidth}-${curveAmp}`;\n  const accent = mode === \"speaking\" ? speakRgb : listenRgb;\n\n  const liveRef = React.useRef<Live>({\n    mode,\n    input,\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: 0,\n    base: visBase,\n    accent,\n    vis: visParams,\n  });\n  React.useLayoutEffect(() => {\n    liveRef.current.mode = mode;\n    liveRef.current.input = input;\n    liveRef.current.sens = sensitivity;\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    const gen = micGen.current;\n    const devices = typeof navigator !== \"undefined\" ? navigator.mediaDevices : undefined;\n    if (!devices || typeof devices.getUserMedia !== \"function\") return;\n    const Ctor = window.AudioContext || (window as Window & { webkitAudioContext?: typeof AudioContext }).webkitAudioContext;\n    if (!Ctor) return;\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    } catch {\n      if (ctx) ctx.close().catch(() => undefined);\n    }\n  };\n\n  const toggle = () => {\n    const next: Status = mode === \"idle\" ? \"listening\" : \"idle\";\n    setManual(next);\n    if (next === \"listening\" && input === \"microphone\") void startMic();\n    else stopMic();\n  };\n\n  const [prevStatus, setPrevStatus] = React.useState(status);\n  if (prevStatus !== status) {\n    setPrevStatus(status);\n    setManual(null);\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(() => setManual(manual === \"listening\" ? \"speaking\" : \"idle\"), Math.max(0.5, flowSeconds) * 1000);\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  }, [mode, onStart, onStop]);\n\n  React.useEffect(() => {\n    return () => stopMic();\n  }, []);\n\n  const shouldType = mode === \"listening\" && transcript;\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 wrap = visualRef.current;\n    const canvas = canvasRef.current;\n    const ctx = canvas ? canvas.getContext(\"2d\") : null;\n    if (!wrap) return;\n\n    let last = performance.now();\n    let w = 0;\n    let h = 0;\n\n    const fit = () => {\n      if (!wrap || !canvas || !ctx) return;\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 (!ctx || w <= 0 || h <= 0) return;\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    };\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      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        updateAudio(L, micRef.current, dt);\n        L.phase += dt * (1 + 1.6 * L.level);\n        L.rot += dt * 0.45 * (1 + L.level);\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 items = [\n    { text: idleText, dots: false },\n    { text: typed || listeningText, dots: false },\n    { text: speakingText, dots: true },\n  ];\n  const cur = mode === \"idle\" ? 0 : mode === \"listening\" ? 1 : 2;\n  const shimmerGradient = `linear-gradient(90deg, ${mutedColor} 0%, ${mutedColor} 32%, ${textColor} 50%, ${mutedColor} 68%, ${mutedColor} 100%)`;\n  const statusLabel = mode === \"idle\" ? idleText : mode === \"listening\" ? typed || listeningText : speakingText;\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 aria-hidden=\"true\" style={{ display: \"flex\", alignItems: \"center\", overflow: \"hidden\", flex: \"none\", width: \"100%\", justifyContent: \"center\" }}>\n      <div 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: \"center\",\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: textColor, 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={mode === \"idle\" ? 64 : 62}\n      background={mode === \"idle\" ? \"rgba(255,255,255,0.08)\" : \"#F4F4F5\"}\n      color={mode === \"idle\" ? textColor : \"#111113\"}\n    >\n      {mode === \"idle\" ? <MicIcon /> : <StopIcon />}\n    </RoundButton>\n  ) : null;\n\n  return (\n    <div\n      ref={rootRef}\n      role=\"group\"\n      aria-label=\"Voice assistant\"\n      aria-busy={mode === \"listening\"}\n      itemScope\n      itemType=\"https://schema.org/SoftwareApplication\"\n      className={cn(\"relative flex h-full w-full flex-col items-center justify-center overflow-hidden\", className)}\n      style={{\n        ...style,\n        gap,\n        boxSizing: \"border-box\",\n        padding,\n        borderRadius: radius,\n        background,\n        border: `1px solid ${borderColor}`,\n      }}\n    >\n      <meta itemProp=\"name\" content=\"AI Voice Assistant\" />\n      <meta itemProp=\"applicationCategory\" content=\"MultimediaApplication\" />\n      <meta itemProp=\"description\" content=\"Interactive AI voice assistant interface with idle, listening, and speaking states.\" />\n      <meta itemProp=\"operatingSystem\" content=\"Web\" />\n      <h2 style={SR_ONLY}>AI Voice Assistant</h2>\n      <p style={SR_ONLY}>Tap the microphone to start voice input. Status updates as the assistant listens and speaks.</p>\n      <span role=\"status\" aria-live=\"polite\" style={SR_ONLY}>\n        {statusLabel}\n      </span>\n\n      <div style={{ position: \"relative\", flex: 1, minHeight: 0, width: \"100%\", display: \"flex\", alignItems: \"center\", justifyContent: \"center\" }}>\n        {visualNode}\n        <div style={{ position: \"relative\" }}>{buttonNode}</div>\n      </div>\n      {textNode}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}