{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "transcript-vue",
  "title": "Transcript (Vue)",
  "description": "Speaker-labelled, timed segments with search, marking the segment and word playing and seeking on a press.",
  "dependencies": [
    "@kind-ui/agent-ui@0.9.0",
    "@ui-sdk/core@0.1.0-beta.17",
    "@ui-sdk/vue@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/vue/transcript.ts",
      "content": "import { type TranscriptSearchState, transcriptPrimitive } from \"@kind-ui/agent-ui/core\";\nimport { Input, InputClear, InputGroup } from \"@ui-sdk/vue/input\";\nimport { createParts } from \"@ui-sdk/vue/primitive\";\nimport { defineComponent, Fragment, h } from \"vue\";\n\ntype MatchSegment = { text: string; match: boolean };\n\n// `@ui-sdk/vue`'s `createParts` hands the primitive an emitter for every callback, whether or not anything listens, so\n// `onSeek`, whose presence makes each time a button, is declared a function prop instead, which `@seek` binds.\nconst primitive = Object.defineProperty(\n  Object.assign((options: never) => transcriptPrimitive(options), transcriptPrimitive, {\n    options: { ...transcriptPrimitive.options, onSeek: \"action\" },\n  }),\n  \"name\",\n  { value: transcriptPrimitive.name },\n) as typeof transcriptPrimitive;\n\nconst parts = createParts(primitive, {\n  root: \"div\",\n  search: \"div\",\n  count: \"span\",\n  viewport: \"div\",\n  list: \"div\",\n  segment: \"div\",\n  speaker: \"span\",\n  seek: \"button\",\n  time: \"span\",\n  text: \"p\",\n  word: \"span\",\n});\n\n// `$stable` tells Vue these slots never change, so a part that renders again doesn't render the parts inside it.\nconst stable = (slot: () => unknown) => ({ default: slot, $stable: true });\n\n// A part that fills an empty default slot from its state.\nconst withDefault = <Part>(part: Part, name: string, fill: (state: never) => unknown) =>\n  defineComponent({\n    name,\n    inheritAttrs: false,\n    setup(_, { attrs, slots }) {\n      return () =>\n        h(part as never, attrs, {\n          ...slots,\n          default: slots.default ?? (({ state }: { state: never }) => fill(state)),\n        });\n    },\n  }) as unknown as Part;\n\nconst marked = (segments: readonly MatchSegment[]) =>\n  segments.map((segment, index) => (segment.match ? h(\"mark\", { key: index }, segment.text) : segment.text));\n\n/** A time as a button that seeks to its segment, rendered only while `on-seek` is set. Holds a `TranscriptTime`. */\nexport const TranscriptSeek = parts.Seek;\n/** Scrolls the segments. Holds a `TranscriptList`. */\nexport const TranscriptViewport = parts.Viewport;\n\n/** \"3 matches\" while there's a search, unless you fill the default slot. */\nexport const TranscriptCount = withDefault(\n  parts.Count,\n  \"TranscriptCount\",\n  (state: { text: string }) => state.text,\n);\n\n/**\n * A search field with the match count and a clear button, unless you fill the default slot. Pass the state to UI SDK\n * Input.\n */\nexport const TranscriptSearch = withDefault(\n  parts.Search,\n  \"TranscriptSearch\",\n  (state: TranscriptSearchState) =>\n    h(InputGroup, null, () => [\n      h(Input, {\n        type: \"search\",\n        controller: state.controller,\n        defaultValue: state.defaultValue,\n        \"aria-label\": state.label,\n        placeholder: \"Search\",\n        \"data-agent-hidden\": \"\",\n      }),\n      h(TranscriptCount),\n      h(InputClear, { \"aria-label\": \"Clear search\", \"data-agent-hidden\": \"\" }),\n    ]),\n);\n\n/** The speaker, with what the search matched marked, unless you fill the default slot. */\nexport const TranscriptSpeaker = withDefault(\n  parts.Speaker,\n  \"TranscriptSpeaker\",\n  (state: { speaker: readonly MatchSegment[] }) => marked(state.speaker),\n);\n\n/** When the segment starts, like \"1:05\", unless you fill the default slot. */\nexport const TranscriptTime = withDefault(\n  parts.Time,\n  \"TranscriptTime\",\n  (state: { time: string }) => state.time,\n);\n\n/**\n * The word whose `value` is `\"<segment id>/<index>\"`, or a segment's whole text without words, with what the search\n * matched marked, unless you fill the default slot. Playback writes its mark without rendering it.\n */\nexport const TranscriptWord = withDefault(\n  parts.Word,\n  \"TranscriptWord\",\n  (state: { text: readonly MatchSegment[] }) => marked(state.text),\n);\n\n/**\n * A `TranscriptWord` for each of the segment's words, a space apart, or its whole text, unless you fill the default\n * slot.\n */\nexport const TranscriptText = withDefault(\n  parts.Text,\n  \"TranscriptText\",\n  (state: { words: readonly string[] }) =>\n    state.words.map((value, index) =>\n      h(Fragment, { key: value }, [index > 0 ? \" \" : null, h(TranscriptWord, { value })]),\n    ),\n);\n\nconst seekTime = stable(() => h(TranscriptTime));\n\n/**\n * The segment whose id is `value`: its speaker, its time, and its text, unless you fill the default slot. A segment\n * renders again only when its own parts change, since Vue renders a child again only when its props do.\n */\nexport const TranscriptSegment = withDefault(\n  parts.Segment,\n  \"TranscriptSegment\",\n  (state: { canSeek: boolean }) => [\n    h(\"div\", { \"data-transcript-header\": \"\" }, [\n      h(TranscriptSpeaker),\n      state.canSeek ? h(TranscriptSeek, null, seekTime) : h(TranscriptTime),\n    ]),\n    h(TranscriptText),\n  ],\n);\n\n/** A `TranscriptSegment` for each segment in view, unless you fill the default slot. */\nexport const TranscriptList = withDefault(\n  parts.List,\n  \"TranscriptList\",\n  (state: { rows: readonly { key: string }[] }) =>\n    state.rows.map((row) => h(TranscriptSegment, { key: row.key, value: row.key })),\n);\n\nconst defaultParts = () => [\n  h(TranscriptSearch),\n  h(\n    TranscriptViewport,\n    null,\n    stable(() => h(TranscriptList)),\n  ),\n];\n\n/**\n * Speaker-labelled, timed segments with a search, marking the segment and word playing at `current-time`. A default\n * slot replaces the default parts.\n */\nexport const Transcript = defineComponent({\n  name: \"Transcript\",\n  inheritAttrs: false,\n  setup(_, { attrs, slots }) {\n    return () => h(parts.Root, attrs, { ...slots, default: slots.default ?? defaultParts });\n  },\n}) as unknown as typeof parts.Root;\n",
      "type": "registry:ui",
      "target": "@ui/vue/transcript.ts"
    }
  ],
  "meta": {
    "layer": "vue"
  },
  "type": "registry:ui"
}
