{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "voice-memo",
  "title": "Voice memo",
  "author": "Tori Bryan",
  "description": "An aluminum recorder with a live transcript beside it.",
  "dependencies": [
    "class-variance-authority",
    "lucide-react"
  ],
  "registryDependencies": [
    "https://fibo.toribryan.com/r/button.json",
    "utils"
  ],
  "files": [
    {
      "path": "registry/ui/voice-memo.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { cva } from \"class-variance-authority\"\nimport { CheckIcon, CopyIcon, FileDownIcon, XIcon } from \"lucide-react\"\n\nimport { Button } from \"@/components/ui/button\"\nimport { cn } from \"@/lib/utils\"\n\ntype VoiceMemoSegment = {\n  /** Milliseconds from the start, when the phrase was settled. Unknown for text from your own service. */\n  at?: number\n  /** The phrase. */\n  text: string\n}\n\ntype VoiceMemoResult = {\n  /** The memo's title, the Markdown heading. */\n  title: string\n  /** The whole transcript as one string. */\n  transcript: string\n  /** The transcript a phrase at a time, with when each was said. */\n  segments: VoiceMemoSegment[]\n  /** When listening started. */\n  startedAt: Date\n  /** Milliseconds spent listening. */\n  duration: number\n  /** The transcript as a Markdown document, ready to save as a .md file. */\n  markdown: string\n  /** A file name for it, such as voice-memo-2026-10-02-1405.md. */\n  filename: string\n}\n\ntype VoiceMemoProps = Omit<\n  React.ComponentProps<\"div\">,\n  \"onChange\" | \"title\"\n> & {\n  /** The memo's name, used as the Markdown heading and the file name. */\n  title?: string\n  /** Whether it's listening, when controlled. */\n  recording?: boolean\n  /** Whether an uncontrolled device starts listening. */\n  defaultRecording?: boolean\n  /** Whether the device starts awake, so the first press listens rather than waking it. */\n  defaultAwake?: boolean\n  /** Called when the device is pressed to start or stop, and with false when transcription fails. */\n  onRecordingChange?: (recording: boolean) => void\n  /** The finished text so far, when you transcribe with your own service. The browser's recognizer stays off. */\n  transcript?: string\n  /** Words still being worked out, shown fainter after `transcript`. */\n  interim?: string\n  /** Called as each phrase is settled, with the whole transcript so far. */\n  onTranscriptChange?: (transcript: string) => void\n  /** Called once listening stops, with the finished transcript and the memo, Markdown included. */\n  onComplete?: (transcript: string, memo: VoiceMemoResult) => void\n  /** The language spoken, as a BCP 47 tag, for the browser's recognizer. */\n  lang?: string\n  /** Text to speak in place of a microphone, a word at a time. For previews and demos. */\n  simulate?: string\n  /** The word raised on the device. */\n  wordmark?: string\n  /** Which side of the device the transcript opens on. */\n  side?: \"right\" | \"bottom\"\n  /** `sm` for a toolbar or sidebar, `default` on its own. */\n  size?: \"sm\" | \"default\"\n  /** The device's finish: aluminum that takes the theme, or burgundy in both. */\n  variant?: \"default\" | \"burgundy\"\n}\n\nconst voiceMemoVariants = cva(\n  \"group/device relative block shrink-0 cursor-pointer touch-manipulation rounded-[7%/11%] outline-none select-none focus-visible:ring-[3px] focus-visible:ring-ring-subtle\",\n  {\n    variants: {\n      size: {\n        sm: \"w-40\",\n        default: \"w-56\",\n      },\n      // The metal, the light it catches, the shade it falls into and how\n      // bright its chamfer shows, which the drawing reads in place of fixed\n      // roles.\n      variant: {\n        default:\n          \"[--metal-chamfer:0.8] [--metal-edge:var(--color-border)] [--metal-highlight:var(--color-background)] [--metal-shadow:var(--color-foreground)] [--metal:var(--color-muted)]\",\n        burgundy:\n          \"[--metal-chamfer:0.25] [--metal-edge:var(--color-finish-burgundy-shadow)] [--metal-highlight:var(--color-finish-burgundy-highlight)] [--metal-shadow:var(--color-finish-burgundy-shadow)] [--metal:var(--color-finish-burgundy)]\",\n      },\n    },\n    defaultVariants: { size: \"default\", variant: \"default\" },\n  }\n)\n\n// 85 by 55, a bank card's proportions, in a unit of 2.\nconst DEVICE = { width: 170, height: 110, radius: 12 }\n\n// The parts of the Web Speech API this uses, declared here: TypeScript's DOM\n// library leaves the recognizer out, since only some browsers ship it, and\n// older versions of the library lack its events too.\ntype RecognitionEvent = {\n  resultIndex: number\n  results: ArrayLike<{ isFinal: boolean } & ArrayLike<{ transcript: string }>>\n}\n\ntype RecognitionErrorEvent = { error: string }\n\ntype Recognizer = {\n  continuous: boolean\n  interimResults: boolean\n  lang: string\n  start: () => void\n  stop: () => void\n  abort: () => void\n  onresult: ((event: RecognitionEvent) => void) | null\n  onerror: ((event: RecognitionErrorEvent) => void) | null\n  onend: (() => void) | null\n}\n\nfunction getRecognizer() {\n  if (typeof window === \"undefined\") return undefined\n  const scope = window as unknown as {\n    SpeechRecognition?: new () => Recognizer\n    webkitSpeechRecognition?: new () => Recognizer\n  }\n  return scope.SpeechRecognition ?? scope.webkitSpeechRecognition\n}\n\nfunction noop() {\n  return () => {}\n}\n\nfunction formatElapsed(ms: number) {\n  const seconds = Math.max(0, Math.floor(ms / 1000))\n  const pad = (n: number) => String(n).padStart(2, \"0\")\n  return `${pad(Math.floor(seconds / 60))}:${pad(seconds % 60)}`\n}\n\nfunction join(...parts: string[]) {\n  return parts\n    .map((part) => part.trim())\n    .filter(Boolean)\n    .join(\" \")\n}\n\nconst FILLERS = /,?\\s*\\b(?:u+m+|u+h+|e+r+m+|h+m+|u+h+m+)\\b,?/gi\nconst ASKS =\n  /^(?:who|what|when|where|why|how|which|whose|is|are|am|was|were|can|could|would|should|shall|will|do|does|did|have|has|had|may|might|isn't|aren't|can't|won't|don't|doesn't|didn't)\\b/i\n\n/*\n * Light grammar for a settled phrase, since browser recognizers mostly\n * return lowercase words with no punctuation. Drops filler sounds and a\n * word said twice in a row, except the doubles English allows, capitalizes\n * \"I\" and each sentence, and ends the phrase with a period, or a\n * question mark when it opens like a question. Punctuation the recognizer\n * already added is kept.\n */\nfunction tidyPhrase(phrase: string) {\n  let text = phrase\n    .replace(FILLERS, \" \")\n    .replace(/\\b(?!(?:had|that)\\b)(\\w+)(\\s+\\1\\b)+/gi, \"$1\")\n    .replace(/\\bi\\b(?=$|\\s|'|’)/g, \"I\")\n    .replace(/\\s+([,.?!])/g, \"$1\")\n    .replace(/\\s+/g, \" \")\n    .replace(/^[\\s,]+|[\\s,]+$/g, \"\")\n  if (!text) return \"\"\n  text = text.replace(\n    /(^|[.?!]\\s+)(\\p{Ll})/gu,\n    (_, lead, letter) => lead + letter.toUpperCase()\n  )\n  if (!/[.?!…]$/.test(text)) text += ASKS.test(text) ? \"?\" : \".\"\n  return text\n}\n\nfunction countWords(text: string) {\n  return text.split(/\\s+/).filter(Boolean).length\n}\n\nfunction slugify(text: string) {\n  return (\n    text\n      .toLowerCase()\n      .normalize(\"NFKD\")\n      .replace(/[^a-z0-9]+/g, \"-\")\n      .replace(/^-|-$/g, \"\") || \"voice-memo\"\n  )\n}\n\n/**\n * Writes a memo as Markdown: the title, a line saying when and how long, then\n * a paragraph per phrase, each led by when it was said if that's known.\n */\nfunction transcriptToMarkdown(\n  memo: Pick<VoiceMemoResult, \"title\" | \"segments\" | \"startedAt\" | \"duration\">,\n  locale = \"en-US\"\n) {\n  const when = new Intl.DateTimeFormat(locale, {\n    dateStyle: \"long\",\n    timeStyle: \"short\",\n  }).format(memo.startedAt)\n  const words = countWords(memo.segments.map((s) => s.text).join(\" \"))\n  const body = memo.segments.length\n    ? memo.segments\n        .map((segment) =>\n          segment.at === undefined\n            ? segment.text\n            : `**${formatElapsed(segment.at)}** ${segment.text}`\n        )\n        .join(\"\\n\\n\")\n    : \"_Nothing was heard._\"\n  return `# ${memo.title}\\n\\n${when} · ${formatElapsed(memo.duration)} · ${words} ${words === 1 ? \"word\" : \"words\"}\\n\\n${body}\\n`\n}\n\nfunction memoFilename(title: string, startedAt: Date) {\n  const pad = (n: number) => String(n).padStart(2, \"0\")\n  const date = `${startedAt.getFullYear()}-${pad(startedAt.getMonth() + 1)}-${pad(startedAt.getDate())}`\n  const time = `${pad(startedAt.getHours())}${pad(startedAt.getMinutes())}`\n  return `${slugify(title)}-${date}-${time}.md`\n}\n\nfunction download(markdown: string, filename: string) {\n  const url = URL.createObjectURL(\n    new Blob([markdown], { type: \"text/markdown;charset=utf-8\" })\n  )\n  const link = document.createElement(\"a\")\n  link.href = url\n  link.download = filename\n  link.click()\n  // Revoked a beat later; Safari cancels a download whose URL goes at once.\n  window.setTimeout(() => URL.revokeObjectURL(url), 1000)\n}\n\n/**\n * A bead-blasted aluminum recorder that writes down what you say. Press it and a\n * transcript opens beside it, filling in as you talk; press it again and the\n * transcript stays, ready to copy. It uses the browser's own speech\n * recognition, or shows text from your own service through `transcript`.\n */\nfunction VoiceMemo({\n  title = \"Voice memo\",\n  recording: recordingProp,\n  defaultRecording = false,\n  defaultAwake = false,\n  onRecordingChange,\n  transcript: transcriptProp,\n  interim: interimProp,\n  onTranscriptChange,\n  onComplete,\n  lang = \"en-US\",\n  simulate,\n  wordmark = \"fibo\",\n  side = \"right\",\n  size = \"default\",\n  variant = \"default\",\n  className,\n  ...props\n}: VoiceMemoProps) {\n  const [uncontrolled, setUncontrolled] = React.useState(defaultRecording)\n  const recording = recordingProp ?? uncontrolled\n  // Asleep until pressed once; listening wakes it too.\n  const [woken, setWoken] = React.useState(defaultAwake)\n  const awake = woken || recording\n  const [waking, setWaking] = React.useState(false)\n\n  const external = transcriptProp !== undefined\n  const [heard, setHeard] = React.useState(\"\")\n  const [guess, setGuess] = React.useState(\"\")\n  const transcript = external ? transcriptProp : heard\n  const interim = external ? (interimProp ?? \"\") : guess\n\n  const [dismissed, setDismissed] = React.useState(false)\n  const [failure, setFailure] = React.useState(\"\")\n  // The server can't tell, so it assumes support and the browser corrects it.\n  const supported = React.useSyncExternalStore(\n    noop,\n    () => getRecognizer() !== undefined,\n    () => true\n  )\n  const usesRecognizer = !external && simulate === undefined\n  const error =\n    failure ||\n    (recording && usesRecognizer && !supported\n      ? \"Transcription isn't available in this browser.\"\n      : \"\")\n  const [announcement, setAnnouncement] = React.useState(\"\")\n  const [memo, setMemo] = React.useState<VoiceMemoResult | null>(null)\n  const open =\n    recording ||\n    (!dismissed && (memo !== null || transcript !== \"\" || error !== \"\"))\n\n  // The settled text as it stands, so a recognizer rebuilt mid-session for a\n  // new language carries on from it rather than starting the page over.\n  const said = React.useRef(\"\")\n\n  const settle = React.useEffectEvent((text: string) => {\n    said.current = text\n    setHeard(text)\n    onTranscriptChange?.(text)\n  })\n\n  // Each settled phrase and when it came, for the timestamps in the file.\n  const segments = React.useRef<VoiceMemoSegment[]>([])\n  const started = React.useRef({ at: 0, date: new Date(0) })\n  const elapsed = React.useCallback(\n    () => performance.now() - started.current.at,\n    []\n  )\n  // Set when the recognizer gives up, so that stop hands back no memo.\n  const failed = React.useRef(false)\n\n  const begin = React.useEffectEvent(() => {\n    segments.current = []\n    started.current = { at: performance.now(), date: new Date() }\n    failed.current = false\n    setWoken(true)\n    setMemo(null)\n    said.current = \"\"\n    setHeard(\"\")\n    setGuess(\"\")\n    setFailure(\"\")\n    setDismissed(false)\n    setAnnouncement(\"Listening\")\n  })\n\n  const finish = React.useEffectEvent(() => {\n    setGuess(\"\")\n    if (failed.current) return\n    // Whatever was still being worked out is the best guess there is.\n    const final = join(transcript, interim)\n    if (!external && interim) settle(final)\n    setAnnouncement(\n      final\n        ? `Transcript ready, ${countWords(final)} words`\n        : \"Stopped, nothing heard\"\n    )\n    // Text the phrases don't cover, from your own service or a last guess,\n    // goes in as one more phrase.\n    const covered = join(...segments.current.map((s) => s.text))\n    const rest = final.startsWith(covered)\n      ? final.slice(covered.length).trim()\n      : final\n    const all = final.startsWith(covered) ? [...segments.current] : []\n    if (rest) all.push({ at: external ? undefined : elapsed(), text: rest })\n    const base = {\n      title,\n      transcript: final,\n      segments: all,\n      startedAt: started.current.date,\n      duration: elapsed(),\n    }\n    const result: VoiceMemoResult = {\n      ...base,\n      markdown: transcriptToMarkdown(base, lang),\n      filename: memoFilename(title, base.startedAt),\n    }\n    setMemo(result)\n    onComplete?.(final, result)\n  })\n\n  // Starts and stops a session on each change of the resolved value, so a\n  // device switched on by `defaultRecording` or by its parent gets the same\n  // session as one that's pressed. A layout effect, so the session has begun\n  // before the recognizer's effect starts listening.\n  const previous = React.useRef(false)\n  React.useLayoutEffect(() => {\n    if (recording === previous.current) return\n    previous.current = recording\n    // The change is the event here: a session's state resets, or its memo\n    // is made and handed to onComplete, as one step.\n    // eslint-disable-next-line react-hooks/set-state-in-effect\n    if (recording) begin()\n    else finish()\n  }, [recording])\n\n  const setRecording = (next: boolean) => {\n    if (recordingProp === undefined) setUncontrolled(next)\n    onRecordingChange?.(next)\n  }\n\n  // A recognizer that can't go on switches the device off, and its message\n  // stays in place of a memo.\n  const halt = React.useEffectEvent((message: string) => {\n    failed.current = true\n    setFailure(message)\n    setRecording(false)\n  })\n\n  // The browser's recognizer, unless the text comes from elsewhere.\n  React.useEffect(() => {\n    const Recognizer = getRecognizer()\n    if (!recording || !usesRecognizer || !Recognizer) return\n    const recognizer = new Recognizer()\n    recognizer.continuous = true\n    recognizer.interimResults = true\n    recognizer.lang = lang\n    let settled = said.current\n    let stopped = false\n    recognizer.onresult = (event) => {\n      let pending = \"\"\n      for (let i = event.resultIndex; i < event.results.length; i++) {\n        const result = event.results[i]!\n        if (result.isFinal) {\n          const text = tidyPhrase(result[0]!.transcript)\n          settled = join(settled, text)\n          if (text) segments.current.push({ at: elapsed(), text })\n        } else pending = join(pending, result[0]!.transcript)\n      }\n      settle(settled)\n      setGuess(pending)\n    }\n    recognizer.onerror = (event) => {\n      if (event.error === \"no-speech\" || event.error === \"aborted\") return\n      stopped = true\n      halt(\n        event.error === \"not-allowed\" || event.error === \"service-not-allowed\"\n          ? \"Allow the microphone to transcribe.\"\n          : event.error === \"audio-capture\"\n            ? \"No microphone was found.\"\n            : event.error === \"network\"\n              ? \"Transcription needs a connection. Press the device to try again.\"\n              : \"Transcription stopped. Press the device to try again.\"\n      )\n    }\n    // Recognizers end on their own after a silence; a device that's still\n    // switched on keeps listening.\n    recognizer.onend = () => {\n      if (stopped) return\n      try {\n        recognizer.start()\n      } catch {\n        stopped = true\n        halt(\"Transcription stopped. Press the device to try again.\")\n      }\n    }\n    recognizer.start()\n    // Aborted rather than stopped: a stop sends one last result after\n    // onComplete has already had the text. The guess on screen stands in.\n    return () => {\n      stopped = true\n      recognizer.onresult = null\n      recognizer.onerror = null\n      recognizer.onend = null\n      recognizer.abort()\n    }\n  }, [recording, usesRecognizer, lang, elapsed])\n\n  // A script spoken a word at a time, the newest word still a guess.\n  React.useEffect(() => {\n    if (!recording || external || simulate === undefined) return\n    const words = simulate.split(/\\s+/).filter(Boolean)\n    let index = 0\n    let from = 0\n    const id = window.setInterval(() => {\n      if (index > words.length) return\n      const done = Math.max(0, index - 1)\n      // A sentence settles as a phrase, as the browser's recognizer would.\n      if (done > from && /[.?!]$/.test(words[done - 1]!)) {\n        segments.current.push({\n          at: elapsed(),\n          text: words.slice(from, done).join(\" \"),\n        })\n        from = done\n      }\n      settle(words.slice(0, done).join(\" \"))\n      setGuess(index > 0 ? (words[index - 1] ?? \"\") : \"\")\n      index++\n    }, 240)\n    return () => window.clearInterval(id)\n  }, [recording, external, simulate, elapsed])\n\n  // The clock is written straight to the page, so it costs no renders.\n  const clock = React.useRef<HTMLSpanElement>(null)\n  React.useEffect(() => {\n    if (!recording) return\n    const started = performance.now()\n    const paint = () => {\n      if (clock.current)\n        clock.current.textContent = formatElapsed(performance.now() - started)\n    }\n    paint()\n    const id = window.setInterval(paint, 250)\n    return () => window.clearInterval(id)\n  }, [recording])\n\n  // Follows the newest words, unless someone has scrolled up to reread.\n  const body = React.useRef<HTMLDivElement>(null)\n  const pinned = React.useRef(true)\n  React.useLayoutEffect(() => {\n    const element = body.current\n    if (element && pinned.current) element.scrollTop = element.scrollHeight\n  }, [transcript, interim])\n\n  const [copied, setCopied] = React.useState(false)\n  React.useEffect(() => {\n    if (!copied) return\n    const id = window.setTimeout(() => setCopied(false), 1500)\n    return () => window.clearTimeout(id)\n  }, [copied])\n\n  const transcriptId = React.useId()\n  const device = React.useRef<HTMLButtonElement>(null)\n\n  return (\n    <div\n      data-slot=\"voice-memo\"\n      data-recording={recording ? \"\" : undefined}\n      data-awake={awake ? \"\" : undefined}\n      data-side={side}\n      data-size={size}\n      data-variant={variant}\n      className={cn(\n        \"relative inline-flex\",\n        side === \"bottom\" && \"flex-col items-start\",\n        className\n      )}\n      {...props}\n    >\n      <button\n        ref={device}\n        type=\"button\"\n        aria-pressed={recording}\n        aria-label={awake ? \"Transcribe\" : \"Wake\"}\n        aria-controls={open ? transcriptId : undefined}\n        data-slot=\"voice-memo-device\"\n        onClick={() => {\n          if (awake) return setRecording(!recording)\n          setWoken(true)\n          setWaking(true)\n          setAnnouncement(\"Ready\")\n        }}\n        className={voiceMemoVariants({ size, variant })}\n      >\n        <Device\n          light={recording ? \"recording\" : awake ? \"ready\" : \"off\"}\n          waking={waking}\n          onWoken={() => setWaking(false)}\n          wordmark={wordmark}\n          tinted={variant === \"default\"}\n        />\n      </button>\n\n      {open ? (\n        <div\n          id={transcriptId}\n          role=\"region\"\n          aria-label=\"Transcript\"\n          data-slot=\"voice-memo-transcript\"\n          className={cn(\n            \"absolute z-10 flex w-72 max-w-[calc(100vw-2rem)] flex-col rounded-2xl border border-border bg-popover text-popover-foreground shadow-lg\",\n            // Grows out of the device, and holds still under reduced motion.\n            \"origin-left transition-[opacity,scale,translate] duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-opacity starting:scale-95 starting:opacity-0 motion-reduce:starting:scale-100\",\n            // A notch pointing back at the device.\n            \"before:absolute before:size-3 before:rotate-45 before:border-border before:bg-popover\",\n            side === \"right\"\n              ? \"top-3 left-full ml-4 before:top-5 before:-left-[7px] before:border-b before:border-l starting:-translate-x-2 motion-reduce:starting:translate-x-0\"\n              : \"top-full mt-4 origin-top before:-top-[7px] before:left-6 before:border-t before:border-l starting:-translate-y-2 motion-reduce:starting:translate-y-0\"\n          )}\n        >\n          <div\n            data-slot=\"voice-memo-header\"\n            className=\"relative flex items-center justify-between gap-2 px-3 pt-3 text-xs text-muted-foreground\"\n          >\n            <span className=\"flex items-center gap-1.5\">\n              <span\n                aria-hidden\n                className={cn(\n                  \"size-1.5 rounded-full\",\n                  recording\n                    ? \"animate-pulse bg-destructive motion-reduce:animate-none\"\n                    : \"bg-border\"\n                )}\n              />\n              {recording ? \"Listening…\" : \"Transcript\"}\n            </span>\n            {recording ? (\n              <span\n                ref={clock}\n                data-slot=\"voice-memo-time\"\n                className=\"font-mono tabular-nums\"\n              >\n                00:00\n              </span>\n            ) : (\n              <span className=\"-my-1 -mr-1.5 flex items-center\">\n                {transcript ? (\n                  <Button\n                    variant=\"ghost\"\n                    size=\"icon-xs\"\n                    aria-label={copied ? \"Copied\" : \"Copy transcript\"}\n                    data-slot=\"voice-memo-copy\"\n                    onClick={() => {\n                      // A browser without the clipboard, or one that refuses\n                      // it, says so rather than leaving the press unanswered.\n                      void Promise.resolve()\n                        .then(() => navigator.clipboard.writeText(transcript))\n                        .then(\n                          () => setCopied(true),\n                          () => setAnnouncement(\"Couldn't copy\")\n                        )\n                    }}\n                  >\n                    {copied ? <CheckIcon /> : <CopyIcon />}\n                  </Button>\n                ) : null}\n                {memo && transcript ? (\n                  <Button\n                    variant=\"ghost\"\n                    size=\"icon-xs\"\n                    aria-label=\"Download as Markdown\"\n                    data-slot=\"voice-memo-download\"\n                    onClick={() => download(memo.markdown, memo.filename)}\n                  >\n                    <FileDownIcon />\n                  </Button>\n                ) : null}\n                <Button\n                  variant=\"ghost\"\n                  size=\"icon-xs\"\n                  aria-label=\"Close transcript\"\n                  data-slot=\"voice-memo-close\"\n                  onClick={() => {\n                    setDismissed(true)\n                    // The button closing it goes with the transcript.\n                    device.current?.focus({ preventScroll: true })\n                  }}\n                >\n                  <XIcon />\n                </Button>\n              </span>\n            )}\n          </div>\n          <div\n            ref={body}\n            tabIndex={0}\n            role=\"log\"\n            aria-label=\"Transcript text\"\n            data-slot=\"voice-memo-text\"\n            onScroll={(event) => {\n              const element = event.currentTarget\n              pinned.current =\n                element.scrollHeight -\n                  element.scrollTop -\n                  element.clientHeight <\n                8\n            }}\n            className=\"relative max-h-40 min-h-16 overflow-y-auto rounded-b-2xl px-3 pt-1.5 pb-3 text-sm leading-relaxed outline-none focus-visible:ring-[3px] focus-visible:ring-ring-subtle\"\n          >\n            {error ? (\n              <p className=\"m-0 text-muted-foreground\">{error}</p>\n            ) : transcript || interim ? (\n              <p className=\"m-0\">\n                {transcript}\n                {interim ? (\n                  <span className=\"text-muted-foreground\">\n                    {transcript ? \" \" : \"\"}\n                    {interim}\n                  </span>\n                ) : null}\n              </p>\n            ) : (\n              <p className=\"m-0 text-muted-foreground\">\n                {recording ? \"Start talking…\" : \"Nothing was heard.\"}\n              </p>\n            )}\n          </div>\n        </div>\n      ) : null}\n\n      <span role=\"status\" data-slot=\"voice-memo-announcer\" className=\"sr-only\">\n        {error || announcement}\n      </span>\n    </div>\n  )\n}\n\n/*\n * The aluminum face, drawn rather than photographed so it takes the theme:\n * silver in light, space gray in dark, or burgundy in both. Hover lifts it\n * and slides the reflection along; pressing pushes it in. Waking, it hops\n * and shakes once.\n */\nfunction Device({\n  wordmark,\n  light,\n  waking,\n  onWoken,\n  tinted,\n}: {\n  wordmark: string\n  light: \"off\" | \"ready\" | \"recording\"\n  waking: boolean\n  onWoken: () => void\n  tinted: boolean\n}) {\n  const id = React.useId()\n  const ids = {\n    pits: `${id}-pits`,\n    glints: `${id}-glints`,\n    shade: `${id}-shade`,\n    sheen: `${id}-sheen`,\n    clip: `${id}-clip`,\n    edges: `${id}-edges`,\n    halo: `${id}-halo`,\n    lens: `${id}-lens`,\n  }\n  const { width, height, radius } = DEVICE\n\n  return (\n    <span\n      aria-hidden\n      onAnimationEnd={(event) => {\n        if (event.animationName === \"voice-memo-wake\") onWoken()\n      }}\n      className={cn(\n        waking && \"motion-safe:animate-voice-memo-wake\",\n        \"relative block aspect-[85/55] transition-[translate,scale] duration-300 ease-[cubic-bezier(0.22,1,0.36,1)]\",\n        \"motion-safe:group-hover/device:-translate-y-0.5 motion-safe:group-active/device:translate-y-px motion-safe:group-active/device:scale-[0.985] motion-safe:group-active/device:duration-100\"\n      )}\n    >\n      {/* Fixed shadows crossfade, so lifting and pressing animate only\n          opacity. */}\n      <span className=\"absolute inset-0 rounded-[7%/11%] shadow-sm transition-opacity duration-300 group-hover/device:opacity-0\" />\n      <span className=\"absolute inset-0 rounded-[7%/11%] opacity-0 shadow-lg transition-opacity duration-300 group-hover/device:opacity-100 group-active/device:opacity-0\" />\n      <span className=\"absolute inset-0 rounded-[7%/11%] opacity-0 shadow-xs transition-opacity duration-100 group-active/device:opacity-100\" />\n\n      <svg\n        viewBox={`0 0 ${width} ${height}`}\n        className=\"absolute inset-0 size-full overflow-visible\"\n      >\n        <defs>\n          {/* Bead-blasted grain: fine noise, the same in every direction,\n              pushed hard so only its peaks survive as specks. The red\n              channel becomes alpha, so the specks take the fill's color.\n              Two seeds give dark pits and bright glints that don't line up. */}\n          {[\n            { id: ids.pits, seed: 4 },\n            { id: ids.glints, seed: 11 },\n          ].map((grain) => (\n            <filter\n              key={grain.id}\n              id={grain.id}\n              x=\"0\"\n              y=\"0\"\n              width=\"100%\"\n              height=\"100%\"\n            >\n              <feTurbulence\n                type=\"fractalNoise\"\n                baseFrequency=\"1.6\"\n                numOctaves=\"2\"\n                seed={grain.seed}\n              />\n              <feColorMatrix\n                type=\"matrix\"\n                values=\"0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  2.4 0 0 0 -1.05\"\n              />\n              <feComposite in=\"SourceGraphic\" operator=\"in\" />\n            </filter>\n          ))}\n          {/* Lit from the top left. */}\n          <linearGradient\n            id={ids.shade}\n            gradientUnits=\"userSpaceOnUse\"\n            x1=\"0\"\n            y1=\"0\"\n            x2={width * 0.6}\n            y2={height}\n          >\n            <stop\n              offset=\"0\"\n              style={{ stopColor: \"var(--metal-highlight)\", stopOpacity: 0.6 }}\n            />\n            <stop\n              offset=\"0.45\"\n              style={{ stopColor: \"var(--metal-highlight)\", stopOpacity: 0 }}\n            />\n            <stop\n              offset=\"1\"\n              style={{\n                stopColor: \"var(--metal-shadow)\",\n                stopOpacity: 0.13,\n              }}\n            />\n          </linearGradient>\n          <linearGradient id={ids.sheen} x1=\"0\" y1=\"0\" x2=\"1\" y2=\"0\">\n            <stop\n              offset=\"0\"\n              style={{ stopColor: \"var(--metal-highlight)\", stopOpacity: 0 }}\n            />\n            <stop\n              offset=\"0.5\"\n              style={{\n                stopColor: \"var(--metal-highlight)\",\n                stopOpacity: 0.55,\n              }}\n            />\n            <stop\n              offset=\"1\"\n              style={{ stopColor: \"var(--metal-highlight)\", stopOpacity: 0 }}\n            />\n          </linearGradient>\n          {/* The rim of raised lettering lit from the top left: a bright\n              line along the edges facing the light, where the shape shifted\n              away from it leaves them uncovered, a hard shadow along the far\n              edges and a soft one cast beyond them. */}\n          <filter\n            id={ids.edges}\n            x=\"-5%\"\n            y=\"-20%\"\n            width=\"110%\"\n            height=\"140%\"\n            colorInterpolationFilters=\"sRGB\"\n          >\n            <feOffset in=\"SourceAlpha\" dx=\"0.7\" dy=\"0.8\" result=\"down\" />\n            <feComposite\n              in=\"SourceAlpha\"\n              in2=\"down\"\n              operator=\"out\"\n              result=\"top\"\n            />\n            <feComposite\n              in=\"down\"\n              in2=\"SourceAlpha\"\n              operator=\"out\"\n              result=\"under\"\n            />\n            <feFlood\n              style={{\n                floodColor: \"var(--metal-highlight)\",\n                floodOpacity: 0.85,\n              }}\n            />\n            <feComposite in2=\"top\" operator=\"in\" result=\"lit\" />\n            <feFlood\n              style={{\n                floodColor: \"var(--metal-shadow)\",\n                floodOpacity: 0.3,\n              }}\n            />\n            <feComposite in2=\"under\" operator=\"in\" result=\"shade\" />\n            <feGaussianBlur in=\"down\" stdDeviation=\"0.9\" result=\"soft\" />\n            <feComposite\n              in=\"soft\"\n              in2=\"SourceAlpha\"\n              operator=\"out\"\n              result=\"cast\"\n            />\n            <feFlood\n              style={{\n                floodColor: \"var(--metal-shadow)\",\n                floodOpacity: 0.12,\n              }}\n            />\n            <feComposite in2=\"cast\" operator=\"in\" result=\"glow\" />\n            <feMerge>\n              <feMergeNode in=\"glow\" />\n              <feMergeNode in=\"shade\" />\n              <feMergeNode in=\"lit\" />\n            </feMerge>\n          </filter>\n          <clipPath id={ids.clip}>\n            <rect width={width} height={height} rx={radius} />\n          </clipPath>\n        </defs>\n\n        {/* The button on the bottom edge, pushed in with the press. */}\n        <rect\n          x={width - 58}\n          y={height - 1}\n          width={22}\n          height={3}\n          rx={1.25}\n          strokeWidth={0.75}\n          className=\"fill-(--metal) stroke-(--metal-edge) transition-transform duration-100 group-active/device:-translate-y-[1.5px]\"\n        />\n\n        <rect\n          width={width}\n          height={height}\n          rx={radius}\n          className=\"fill-(--metal)\"\n        />\n        <rect\n          width={width}\n          height={height}\n          rx={radius}\n          fill={`url(#${ids.shade})`}\n        />\n        {/* Anodized aluminum is a mid gray; the muted role alone is near\n            white in the light theme. */}\n        {tinted ? (\n          <rect\n            width={width}\n            height={height}\n            rx={radius}\n            className=\"fill-foreground opacity-[0.12] dark:opacity-0\"\n          />\n        ) : null}\n        <rect\n          width={width}\n          height={height}\n          rx={radius}\n          filter={`url(#${ids.pits})`}\n          className=\"fill-(--metal-shadow) opacity-20\"\n        />\n        <rect\n          width={width}\n          height={height}\n          rx={radius}\n          filter={`url(#${ids.glints})`}\n          className=\"fill-(--metal-highlight) opacity-35\"\n        />\n\n        {/* Raised lettering, over the grain so speckle can't break up its\n            edges. A filter draws them from the word's merged shape, so where\n            letters overlap, as the f and i do, no edge shows inside the\n            join. */}\n        <text\n          x={14}\n          y={height - 16}\n          fontSize={50}\n          filter={`url(#${ids.edges})`}\n          className=\"font-serif\"\n        >\n          {wordmark}\n        </text>\n\n        {/* The reflection slides along as the device lifts, the way light\n            moves across metal you tilt. */}\n        <g clipPath={`url(#${ids.clip})`}>\n          <rect\n            x={-20}\n            y={-height}\n            width={36}\n            height={height * 3}\n            fill={`url(#${ids.sheen})`}\n            transform={`rotate(24 ${width / 2} ${height / 2})`}\n            className=\"transition-transform duration-700 ease-[cubic-bezier(0.22,1,0.36,1)] motion-safe:group-hover/device:translate-x-[60px]\"\n          />\n        </g>\n\n        {/* A machined chamfer: a bright line just inside the edge, a dark\n            one on it. */}\n        <rect\n          x={0.9}\n          y={0.9}\n          width={width - 1.8}\n          height={height - 1.8}\n          rx={radius - 0.9}\n          fill=\"none\"\n          strokeWidth={1.2}\n          className=\"stroke-(--metal-highlight) opacity-(--metal-chamfer)\"\n        />\n        <rect\n          width={width}\n          height={height}\n          rx={radius}\n          fill=\"none\"\n          strokeWidth={0.75}\n          className=\"stroke-(--metal-shadow) opacity-15\"\n        />\n\n        {/* The microphone pinhole: dark while it sleeps, green once it's\n            awake and ready, pulsing red while it listens. */}\n        <circle\n          cx={width - 16}\n          cy={16}\n          r={1.8}\n          className=\"fill-(--metal-shadow) opacity-50\"\n        />\n        {/* An LED behind the pinhole, seen flat: a disc of its hue, a\n            touch brighter at the middle, with a halo on the metal.\n            Both states share it, in the light's own hue. */}\n        {light !== \"off\" ? (\n          <g\n            data-slot=\"voice-memo-light\"\n            data-state={light}\n            className={cn(\n              light === \"recording\"\n                ? \"animate-pulse [--led:var(--color-destructive)] motion-reduce:animate-none\"\n                : \"[--led:var(--color-success)]\"\n            )}\n          >\n            <radialGradient id={ids.halo}>\n              <stop\n                offset=\"0\"\n                style={{ stopColor: \"var(--led)\", stopOpacity: 0.6 }}\n              />\n              <stop\n                offset=\"0.35\"\n                style={{ stopColor: \"var(--led)\", stopOpacity: 0.22 }}\n              />\n              <stop\n                offset=\"1\"\n                style={{ stopColor: \"var(--led)\", stopOpacity: 0 }}\n              />\n            </radialGradient>\n            <radialGradient id={ids.lens}>\n              <stop\n                offset=\"0\"\n                style={{\n                  stopColor: \"oklch(from var(--led) calc(l + 0.12) c h)\",\n                }}\n              />\n              <stop offset=\"0.6\" style={{ stopColor: \"var(--led)\" }} />\n              <stop offset=\"1\" style={{ stopColor: \"var(--led)\" }} />\n            </radialGradient>\n            <circle cx={width - 16} cy={16} r={7} fill={`url(#${ids.halo})`} />\n            <circle cx={width - 16} cy={16} r={2} fill={`url(#${ids.lens})`} />\n          </g>\n        ) : null}\n      </svg>\n    </span>\n  )\n}\n\nexport {\n  VoiceMemo,\n  voiceMemoVariants,\n  formatElapsed,\n  transcriptToMarkdown,\n  tidyPhrase,\n  type VoiceMemoProps,\n  type VoiceMemoResult,\n  type VoiceMemoSegment,\n}\n",
      "type": "registry:ui"
    }
  ],
  "cssVars": {
    "theme": {
      "color-burgundy-950": "oklch(0.21 0.035 12)",
      "color-burgundy-700": "oklch(0.44 0.05 12)",
      "color-highlight": "var(--highlight)",
      "color-success": "var(--success)",
      "color-ring-subtle": "var(--ring-subtle)",
      "color-finish-burgundy": "var(--finish-burgundy)",
      "color-finish-burgundy-highlight": "var(--finish-burgundy-highlight)",
      "color-finish-burgundy-shadow": "var(--finish-burgundy-shadow)",
      "background-color-destructive": "var(--destructive)",
      "animate-voice-memo-wake": "voice-memo-wake 0.6s linear"
    },
    "light": {
      "highlight": "var(--color-neutral-200)",
      "success": "var(--color-green-700)",
      "ring-subtle": "color-mix(in oklch, var(--color-neutral-400) 50%, transparent)",
      "finish-burgundy": "var(--color-burgundy-950)",
      "finish-burgundy-highlight": "var(--color-burgundy-700)",
      "finish-burgundy-shadow": "var(--color-black)"
    },
    "dark": {
      "highlight": "var(--color-neutral-700)",
      "success": "var(--color-green-400)",
      "ring-subtle": "color-mix(in oklch, var(--color-neutral-500) 50%, transparent)",
      "finish-burgundy": "var(--color-burgundy-950)",
      "finish-burgundy-highlight": "var(--color-burgundy-700)",
      "finish-burgundy-shadow": "var(--color-black)"
    }
  },
  "css": {
    "@keyframes voice-memo-wake": {
      "0%": {
        "transform": "perspective(600px) scale(1) rotateY(0deg)",
        "animation-timing-function": "ease-out"
      },
      "14%": {
        "transform": "perspective(600px) scale(1.035) rotateY(-18deg)",
        "animation-timing-function": "ease-in-out"
      },
      "28%": {
        "transform": "perspective(600px) scale(1.06) rotateY(18deg)",
        "animation-timing-function": "ease-in-out"
      },
      "42%": {
        "transform": "perspective(600px) scale(1.06) rotateY(-15deg)",
        "animation-timing-function": "ease-in-out"
      },
      "56%": {
        "transform": "perspective(600px) scale(1.05) rotateY(12deg)",
        "animation-timing-function": "ease-in-out"
      },
      "70%": {
        "transform": "perspective(600px) scale(1.03) rotateY(-7.5deg)",
        "animation-timing-function": "ease-in-out"
      },
      "84%": {
        "transform": "perspective(600px) scale(1.012) rotateY(3deg)",
        "animation-timing-function": "ease-out"
      },
      "100%": {
        "transform": "perspective(600px) scale(1) rotateY(0deg)"
      }
    }
  },
  "meta": {
    "tier": "special-components",
    "group": "Forms",
    "docs": "https://fibo.toribryan.com/?path=/docs/special-components-voice-memo--docs"
  },
  "docs": "Docs and live examples: https://fibo.toribryan.com/?path=/docs/special-components-voice-memo--docs",
  "categories": [
    "special-components",
    "forms"
  ],
  "type": "registry:ui"
}