{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dictation-web",
  "title": "Dictation (Web Components)",
  "description": "A mic button that turns speech into text through a source the host chooses, with a live waveform.",
  "dependencies": [
    "@kind-ui/agent-ui@0.9.0",
    "@ui-sdk/core@0.1.0-beta.17",
    "@ui-sdk/web@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/web/dictation.ts",
      "content": "import {\n  type DictationApi,\n  type DictationSource,\n  type DictationTextReason,\n  dictationButtonPrimitive,\n} from \"@kind-ui/agent-ui/core\";\nimport { createParts, wrappedButton } from \"@ui-sdk/web\";\nimport type { AttributeProperties, UiChangeEvent, UiElement, UiPartElement } from \"@ui-sdk/web/events\";\n\nconst DEFAULT_PARTS =\n  \"<kind-dictation-waveform></kind-dictation-waveform>\" +\n  \"<kind-dictation-status><kind-dictation-status-icon></kind-dictation-status-icon><span data-dictation-text></span></kind-dictation-status>\" +\n  \"<kind-dictation-start><button></button></kind-dictation-start>\" +\n  \"<kind-dictation-cancel><button></button></kind-dictation-cancel>\" +\n  \"<kind-dictation-stop><button></button></kind-dictation-stop>\";\n\n/** Gives the waveform one `kind-dictation-bar` per level, adding or removing bars at its end. */\nconst drawBars = (waveform: Element | null, count: number) => {\n  if (!waveform) return;\n  const bars = waveform.querySelectorAll(\":scope > kind-dictation-bar\");\n  for (let i = bars.length; i < count; i++) {\n    const bar = waveform.ownerDocument.createElement(\"kind-dictation-bar\");\n    bar.setAttribute(\"value\", String(i));\n    waveform.append(bar);\n  }\n  for (let i = count; i < bars.length; i++) bars[i]?.remove();\n};\n\n/**\n * `<kind-dictation>` fills in its waveform, status, mic button, Cancel and Stop when it has no children, and an empty\n * `<kind-dictation-status>` with its mark and a `[data-dictation-text]` span, where the status text goes. Set `source`\n * as a property; the final text arrives as a `dictationtext` event.\n */\nexport function defineDictation(): void {\n  if (customElements.get(\"kind-dictation\")) return;\n  createParts(dictationButtonPrimitive, {\n    root: {\n      tag: \"kind-dictation\",\n      events: { onText: \"dictationtext\" },\n      defaults: { agentConfirm: true },\n      render: (el, instance) => {\n        if (!el.firstElementChild) el.innerHTML = DEFAULT_PARTS;\n        const api = instance.api as DictationApi;\n        const draw = () => {\n          const state = instance.get();\n          drawBars(el.querySelector(\"kind-dictation-waveform\"), state.levels.length);\n          const status = el.querySelector(\"kind-dictation-status\");\n          if (status && !status.firstElementChild)\n            status.innerHTML =\n              \"<kind-dictation-status-icon></kind-dictation-status-icon><span data-dictation-text></span>\";\n          const text = status?.querySelector(\"[data-dictation-text]\");\n          const { text: words } = api.statusState(state);\n          if (text && text.textContent !== words) text.textContent = words;\n        };\n        draw();\n        return instance.subscribe(draw);\n      },\n    },\n    start: { tag: \"kind-dictation-start\", target: wrappedButton, display: \"contents\" },\n    waveform: \"kind-dictation-waveform\",\n    bar: \"kind-dictation-bar\",\n    status: \"kind-dictation-status\",\n    \"status-icon\": \"kind-dictation-status-icon\",\n    stop: { tag: \"kind-dictation-stop\", target: wrappedButton, display: \"contents\" },\n    cancel: { tag: \"kind-dictation-cancel\", target: wrappedButton, display: \"contents\" },\n  });\n}\n\nexport type KindDictationEvents = {\n  dictationtext: UiChangeEvent<string, DictationTextReason>;\n};\n\nexport interface KindDictationElement\n  extends UiElement<KindDictationEvents>,\n    AttributeProperties<typeof dictationButtonPrimitive, \"source\"> {\n  source?: DictationSource;\n}\n\ndeclare global {\n  interface HTMLElementTagNameMap {\n    \"kind-dictation\": KindDictationElement;\n    \"kind-dictation-start\": HTMLElement;\n    \"kind-dictation-waveform\": HTMLElement;\n    \"kind-dictation-bar\": UiPartElement<typeof dictationButtonPrimitive, \"bar\", \"value\">;\n    \"kind-dictation-status\": HTMLElement;\n    \"kind-dictation-status-icon\": HTMLElement;\n    \"kind-dictation-stop\": HTMLElement;\n    \"kind-dictation-cancel\": HTMLElement;\n  }\n}\n",
      "type": "registry:ui",
      "target": "@ui/web/dictation.ts"
    }
  ],
  "meta": {
    "layer": "web"
  },
  "type": "registry:ui"
}
