{
  "name": "ai-token-alternatives",
  "type": "registry:component",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "files": [
    {
      "type": "registry:component",
      "content": "\"use client\";\n\n/**\n * @author: @kokonutui\n * @description: AI Token Alternatives\n * @version: 1.1.0\n * @date: 2026-10-21\n * @license: MIT\n * @website: https://kokonutui.com\n * @github: https://github.com/kokonut-labs/kokonutui\n */\n\nimport { Check, RotateCcw, X } from \"lucide-react\";\nimport {\n  AnimatePresence,\n  MotionConfig,\n  motion,\n  useReducedMotion,\n} from \"motion/react\";\nimport {\n  type KeyboardEvent,\n  useCallback,\n  useEffect,\n  useMemo,\n  useRef,\n  useState,\n} from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface TokenOption {\n  text: string;\n  /** How likely the model was to pick this word, from 0 to 1. */\n  p: number;\n}\n\nexport interface TokenSlot {\n  id: string;\n  /** Most likely first. The first one is what the model wrote. */\n  options: TokenOption[];\n}\n\n/**\n * Plain text, plain text with the model's probability for it, or a word the\n * model nearly wrote differently.\n */\nexport type AnswerPiece =\n  | string\n  | { text: string; p: number }\n  | { slot: string };\n\n/** An answer, with its own slots when they change from one take to the next. */\nexport type ComposedAnswer =\n  | AnswerPiece[]\n  | { pieces: AnswerPiece[]; slots: TokenSlot[] };\n\nexport interface AITokenAlternativesProps {\n  /** The user's message, drawn as a bubble. Only the demo draws one by default. */\n  prompt?: string;\n  /** The words with alternatives. `compose` can return new ones instead. */\n  slots?: TokenSlot[];\n  /**\n   * Builds the answer from the word picked in each slot. Return it or a\n   * Promise of it: after a pick, the words up to that one stay and the rest\n   * is written again once it arrives. `signal` aborts when another pick\n   * replaces this one. Throw and the answer shows the error's message.\n   */\n  compose?: (\n    choice: Record<string, string>,\n    signal: AbortSignal\n  ) => ComposedAnswer | Promise<ComposedAnswer>;\n  className?: string;\n}\n\n/** One token of an OpenAI-style `logprobs.content` list. */\nexport interface LogprobToken {\n  token: string;\n  logprob: number;\n  top_logprobs?: { token: string; logprob: number }[];\n}\n\ninterface Token {\n  key: string;\n  /** Whitespace before the word, kept outside the button. */\n  lead: string;\n  word: string;\n  p: number;\n  slot?: string;\n}\n\ninterface Open {\n  slot: string;\n  x: number;\n  y: number;\n}\n\nconst EASE_OUT = [0.23, 1, 0.32, 1] as const;\nconst MENU_WIDTH = 252;\nconst TOKEN_PATTERN = /\\s+|[^\\s,.?!]+|[,.?!]/g;\nconst SPACE = /^\\s+$/;\n\nconst DEMO_SLOTS: TokenSlot[] = [\n  {\n    id: \"greet\",\n    options: [\n      { text: \"Sure\", p: 0.58 },\n      { text: \"Yes\", p: 0.23 },\n      { text: \"Good call\", p: 0.12 },\n    ],\n  },\n  {\n    id: \"day\",\n    options: [\n      { text: \"Thursday\", p: 0.41 },\n      { text: \"Friday\", p: 0.34 },\n      { text: \"next Monday\", p: 0.17 },\n    ],\n  },\n  {\n    id: \"time\",\n    options: [\n      { text: \"2pm\", p: 0.38 },\n      { text: \"10am\", p: 0.31 },\n      { text: \"after lunch\", p: 0.22 },\n    ],\n  },\n  {\n    id: \"length\",\n    options: [\n      { text: \"30 minutes\", p: 0.52 },\n      { text: \"an hour\", p: 0.29 },\n      { text: \"15 minutes\", p: 0.13 },\n    ],\n  },\n];\n\nconst dayReason: Record<string, string> = {\n  Friday: \" since the build lands Thursday night.\",\n  \"next Monday\": \", so we get the weekend to fix the last bugs.\",\n};\n\nconst demoCompose = (c: Record<string, string>): AnswerPiece[] => [\n  { slot: \"greet\" },\n  \", \",\n  { slot: \"day\" },\n  \" works better for me\",\n  dayReason[c.day] ?? \", and it gives design a day to finish the flows.\",\n  \" Want to do \",\n  { slot: \"time\" },\n  c.time === \"after lunch\" ? \" when everyone is back\" : \"\",\n  \"? Let's keep it to \",\n  { slot: \"length\" },\n  c.length === \"15 minutes\"\n    ? \" and only go through the blockers.\"\n    : \" and walk through the launch checklist together.\",\n];\n\n/** Words the model was less sure of, so the confidence view has texture. */\nconst SOFT: Record<string, number> = {\n  design: 0.62,\n  flows: 0.71,\n  build: 0.68,\n  bugs: 0.64,\n  blockers: 0.6,\n  checklist: 0.57,\n  together: 0.74,\n  everyone: 0.7,\n};\n\n/** A steady, high probability for a plain word, so renders match. */\nconst plainP = (word: string, index: number) => {\n  if (SOFT[word] !== undefined) {\n    return SOFT[word];\n  }\n  let h = index * 31;\n  for (const ch of word) {\n    h = (h * 33 + ch.charCodeAt(0)) % 997;\n  }\n  return 0.86 + (h % 13) / 100;\n};\n\nconst LEADING_SPACE = /^\\s+/;\nconst WORDLIKE = /\\p{L}/u;\n\n/**\n * Turns a model's logprobs into an answer: each token where another word was\n * at least `minAlternative` likely becomes a slot with those words.\n */\nexport function fromLogprobs(\n  content: LogprobToken[],\n  { minAlternative = 0.08, maxOptions = 4 } = {}\n): { pieces: AnswerPiece[]; slots: TokenSlot[] } {\n  const pieces: AnswerPiece[] = [];\n  const slots: TokenSlot[] = [];\n  content.forEach((t, i) => {\n    const p = Math.exp(t.logprob);\n    const lead = t.token.match(LEADING_SPACE)?.[0] ?? \"\";\n    const word = t.token.slice(lead.length);\n    const others = (t.top_logprobs ?? [])\n      .map((o) => ({ text: o.token.trim(), p: Math.exp(o.logprob) }))\n      .filter((o) => o.text && o.text !== word && o.p >= minAlternative);\n    if (!WORDLIKE.test(word) || others.length === 0) {\n      pieces.push({ text: t.token, p });\n      return;\n    }\n    const id = `t${i}`;\n    if (lead) {\n      pieces.push(lead);\n    }\n    pieces.push({ slot: id });\n    slots.push({\n      id,\n      options: [{ text: word, p }, ...others].slice(0, maxOptions),\n    });\n  });\n  return { pieces, slots };\n}\n\nconst normalize = (answer: ComposedAnswer, fallback: TokenSlot[]) =>\n  Array.isArray(answer)\n    ? { pieces: answer, slots: fallback }\n    : { pieces: answer.pieces, slots: answer.slots };\n\nconst reasonOf = (error: unknown) =>\n  error instanceof Error && error.message\n    ? error.message\n    : \"Couldn’t write the rest. Try another word.\";\n\n/** A piece's text and known probability, or null for a slot. */\nconst plainText = (piece: AnswerPiece): [string, number?] | null => {\n  if (typeof piece === \"string\") {\n    return [piece];\n  }\n  return \"text\" in piece ? [piece.text, piece.p] : null;\n};\n\nconst tokenize = (\n  pieces: AnswerPiece[],\n  choice: Record<string, string>,\n  slots: TokenSlot[]\n) => {\n  const tokens: Token[] = [];\n  let lead = \"\";\n  const push = (word: string, p: number, slot?: string) => {\n    const index = tokens.length;\n    tokens.push({ key: `${index}:${word}`, lead, word, p, slot });\n    lead = \"\";\n  };\n  for (const piece of pieces) {\n    const plain = plainText(piece);\n    if (plain) {\n      const [text, known] = plain;\n      for (const part of text.match(TOKEN_PATTERN) ?? []) {\n        if (SPACE.test(part)) {\n          lead += part;\n        } else {\n          push(part, known ?? plainP(part, tokens.length));\n        }\n      }\n      continue;\n    }\n    const id = (piece as { slot: string }).slot;\n    const slot = slots.find((s) => s.id === id);\n    const picked =\n      slot?.options.find((o) => o.text === choice[id]) ?? slot?.options[0];\n    if (picked) {\n      push(picked.text, picked.p, id);\n    }\n  }\n  return tokens;\n};\n\nconst defaults = (slots: TokenSlot[]) =>\n  Object.fromEntries(slots.map((s) => [s.id, s.options[0]?.text ?? \"\"]));\n\n/**\n * The answer for the current choice. A Promise holds the old answer (cut at\n * `keep` words by the caller) until the new one lands.\n */\nfunction useAnswer(\n  compose: NonNullable<AITokenAlternativesProps[\"compose\"]>,\n  choice: Record<string, string>,\n  fallback: TokenSlot[]\n) {\n  const [answer, setAnswer] = useState<{\n    pieces: AnswerPiece[];\n    slots: TokenSlot[];\n  }>({ pieces: [], slots: fallback });\n  const [loading, setLoading] = useState(false);\n  const [error, setError] = useState<string>();\n  const composeRef = useRef(compose);\n  composeRef.current = compose;\n\n  useEffect(() => {\n    const controller = new AbortController();\n    const result = composeRef.current(choice, controller.signal);\n    setError(undefined);\n    if (!(result instanceof Promise)) {\n      setAnswer(normalize(result, fallback));\n      setLoading(false);\n      return;\n    }\n    setLoading(true);\n    result.then(\n      (next) => {\n        if (!controller.signal.aborted) {\n          setAnswer(normalize(next, fallback));\n          setLoading(false);\n        }\n      },\n      (e: unknown) => {\n        if (!controller.signal.aborted) {\n          setError(reasonOf(e));\n          setLoading(false);\n        }\n      }\n    );\n    return () => controller.abort();\n  }, [choice, fallback]);\n\n  return { ...answer, loading, error };\n}\n\nexport default function AITokenAlternatives({\n  prompt,\n  slots: slotsProp,\n  compose: composeProp,\n  className,\n}: AITokenAlternativesProps) {\n  const isDemo = composeProp === undefined;\n  const compose = composeProp ?? demoCompose;\n  const shownPrompt = isDemo\n    ? (prompt ??\n      \"Sam wants to push the launch review. Can you draft a quick reply?\")\n    : prompt;\n  const reduceMotion = useReducedMotion();\n  const [startSlots] = useState(() => slotsProp ?? (isDemo ? DEMO_SLOTS : []));\n  const [choice, setChoice] = useState(() => defaults(startSlots));\n  const answer = useAnswer(compose, choice, startSlots);\n  const { slots } = answer;\n  // Words up to the last pick stay while the rest is being written again.\n  const [keep, setKeep] = useState(0);\n  const [shown, setShown] = useState(0);\n  const [open, setOpen] = useState<Open | null>(null);\n  const [heat, setHeat] = useState(false);\n  // Only a rewrite the user asked for is announced, not the first answer.\n  const [edited, setEdited] = useState(false);\n  const answerRef = useRef<HTMLDivElement>(null);\n  const textRef = useRef<HTMLParagraphElement>(null);\n  /** Holds the height while a rewrite streams, so the card does not jump. */\n  const [minHeight, setMinHeight] = useState<number>();\n  const tokenRefs = useRef(new Map<string, HTMLButtonElement>());\n\n  const tokens = useMemo(\n    () => tokenize(answer.pieces, choice, slots),\n    [answer.pieces, choice, slots]\n  );\n  const waiting = answer.loading;\n  // While the rest is on its way, or failed to come, only the kept words show.\n  const cut = waiting || Boolean(answer.error);\n  const visible = cut ? Math.min(shown, keep) : shown;\n  const streaming = waiting || (!cut && shown < tokens.length);\n\n  // Stream the answer in a word at a time.\n  useEffect(() => {\n    if (!streaming || waiting) {\n      return;\n    }\n    if (reduceMotion) {\n      setShown(tokens.length);\n      return;\n    }\n    const word = tokens[shown]?.word ?? \"\";\n    const id = setTimeout(\n      () => setShown((n) => n + 1),\n      26 + Math.min(40, word.length * 6)\n    );\n    return () => clearTimeout(id);\n  }, [shown, streaming, waiting, tokens, reduceMotion]);\n\n  const pick = useCallback(\n    (slotId: string, text: string) => {\n      const index = tokens.findIndex((t) => t.slot === slotId);\n      setOpen(null);\n      // The list unmounts, so focus goes back to the word either way.\n      requestAnimationFrame(() =>\n        tokenRefs.current.get(slotId)?.focus({ preventScroll: true })\n      );\n      if (choice[slotId] === text) {\n        return;\n      }\n      setMinHeight(textRef.current?.offsetHeight);\n      setEdited(true);\n      setChoice((c) => ({ ...c, [slotId]: text }));\n      // Keep everything up to the new word, then write the rest again.\n      setShown(index + 1);\n      setKeep(index + 1);\n    },\n    [choice, tokens]\n  );\n\n  const toggle = (token: Token) => {\n    const slotId = token.slot;\n    const button = slotId ? tokenRefs.current.get(slotId) : undefined;\n    const box = answerRef.current;\n    if (!(slotId && button && box)) {\n      return;\n    }\n    if (open?.slot === slotId) {\n      setOpen(null);\n      return;\n    }\n    const b = button.getBoundingClientRect();\n    const r = box.getBoundingClientRect();\n    setOpen({\n      slot: slotId,\n      x: Math.max(0, Math.min(b.left - r.left - 10, r.width - MENU_WIDTH)),\n      y: b.bottom - r.top + 6,\n    });\n  };\n\n  const close = useCallback(() => {\n    const slotId = open?.slot;\n    setOpen(null);\n    if (slotId) {\n      tokenRefs.current.get(slotId)?.focus({ preventScroll: true });\n    }\n  }, [open]);\n\n  // Click outside closes the list.\n  useEffect(() => {\n    if (!open) {\n      return;\n    }\n    const onDown = (event: PointerEvent) => {\n      const target = event.target as Node;\n      if (!answerRef.current?.contains(target)) {\n        setOpen(null);\n      }\n    };\n    document.addEventListener(\"pointerdown\", onDown);\n    return () => document.removeEventListener(\"pointerdown\", onDown);\n  }, [open]);\n\n  const edits = slots.filter(\n    (s) => s.id in choice && choice[s.id] !== s.options[0]?.text\n  );\n  const openSlot = slots.find((s) => s.id === open?.slot);\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <div\n        className={cn(\n          \"w-full max-w-md rounded-2xl bg-white ring-1 ring-black/[0.08] dark:bg-zinc-900 dark:ring-white/10\",\n          className\n        )}\n        data-state={streaming ? \"streaming\" : \"idle\"}\n      >\n        {shownPrompt ? (\n          <div className=\"flex justify-end px-4 pt-4\">\n            <p className=\"max-w-[85%] rounded-2xl rounded-br-md bg-zinc-100 px-3.5 py-2 text-[13px] text-zinc-700 leading-snug dark:bg-zinc-800 dark:text-zinc-200\">\n              {shownPrompt}\n            </p>\n          </div>\n        ) : null}\n\n        <div className=\"relative px-4 pt-4 pb-5\" ref={answerRef}>\n          <p\n            className=\"text-[15px] text-zinc-800 leading-7 dark:text-zinc-200\"\n            ref={textRef}\n            style={{ minHeight: streaming ? minHeight : undefined }}\n          >\n            {tokens.slice(0, visible).map((token) => (\n              <TokenView\n                active={open?.slot === token.slot && Boolean(token.slot)}\n                edited={\n                  Boolean(token.slot) && edits.some((s) => s.id === token.slot)\n                }\n                heat={heat}\n                key={token.key}\n                onToggle={() => toggle(token)}\n                ref={(el) => {\n                  if (token.slot && el) {\n                    tokenRefs.current.set(token.slot, el);\n                  }\n                }}\n                token={token}\n              />\n            ))}\n            {streaming && (\n              <span\n                aria-hidden=\"true\"\n                className=\"ml-0.5 inline-block h-4 w-[7px] translate-y-[3px] animate-pulse rounded-[2px] bg-zinc-800 motion-reduce:animate-none dark:bg-zinc-200\"\n              />\n            )}\n          </p>\n          {answer.error ? (\n            <p\n              className=\"mt-2 text-[12.5px] text-rose-600 dark:text-rose-400\"\n              role=\"alert\"\n            >\n              {answer.error}\n            </p>\n          ) : null}\n\n          <AnimatePresence>\n            {open && openSlot && (\n              <Alternatives\n                current={choice[openSlot.id]}\n                key={openSlot.id}\n                onClose={close}\n                onPick={(text) => pick(openSlot.id, text)}\n                slot={openSlot}\n                x={open.x}\n                y={open.y}\n              />\n            )}\n          </AnimatePresence>\n        </div>\n\n        <footer className=\"flex min-h-12 flex-wrap items-center gap-2 border-black/[0.06] border-t px-4 py-2.5 dark:border-white/[0.08]\">\n          <HeatSwitch on={heat} onToggle={() => setHeat((h) => !h)} />\n          <div className=\"ml-auto flex flex-wrap items-center justify-end gap-1.5\">\n            {edits.length === 0 ? (\n              <p className=\"text-[12px] text-zinc-500 dark:text-zinc-400\">\n                Click a dotted word to swap it\n              </p>\n            ) : (\n              <EditChips\n                choice={choice}\n                edits={edits}\n                onReset={() => {\n                  const first = tokens.findIndex(\n                    (t) => t.slot && edits.some((s) => s.id === t.slot)\n                  );\n                  setMinHeight(textRef.current?.offsetHeight);\n                  setEdited(true);\n                  setChoice(defaults(slots));\n                  // Like a pick: the word itself lands at once, the rest\n                  // is written again.\n                  setShown(first + 1);\n                  setKeep(first + 1);\n                  // Reset leaves with the chips; focus goes to the first\n                  // word that changed back.\n                  const slot = tokens[first]?.slot;\n                  requestAnimationFrame(() => {\n                    if (slot) {\n                      tokenRefs.current\n                        .get(slot)\n                        ?.focus({ preventScroll: true });\n                    }\n                  });\n                }}\n                onRevert={(slot) => pick(slot.id, slot.options[0].text)}\n              />\n            )}\n          </div>\n        </footer>\n        <p aria-live=\"polite\" className=\"sr-only\">\n          {edited && !streaming ? \"Answer updated\" : \"\"}\n        </p>\n      </div>\n    </MotionConfig>\n  );\n}\n\nfunction TokenView({\n  token,\n  heat,\n  active,\n  edited,\n  onToggle,\n  ref,\n}: {\n  token: Token;\n  heat: boolean;\n  active: boolean;\n  edited: boolean;\n  onToggle: () => void;\n  ref: (el: HTMLButtonElement | null) => void;\n}) {\n  // The less sure the model was, the warmer the word in the confidence view.\n  const warmth = heat ? Math.max(0, (0.95 - token.p) / 0.75) : 0;\n  const style = {\n    backgroundColor: `rgb(234 88 12 / ${(warmth * 0.32).toFixed(3)})`,\n  };\n  const enter = {\n    initial: { opacity: 0, filter: \"blur(3px)\" },\n    animate: { opacity: 1, filter: \"blur(0px)\" },\n    transition: { duration: 0.28, ease: EASE_OUT },\n  };\n\n  if (!token.slot) {\n    return (\n      <>\n        {token.lead}\n        <motion.span\n          {...enter}\n          className=\"rounded-[3px] transition-[background-color] duration-300 [box-decoration-break:clone]\"\n          style={style}\n        >\n          {token.word}\n        </motion.span>\n      </>\n    );\n  }\n\n  return (\n    <>\n      {token.lead}\n      <motion.button\n        {...enter}\n        aria-expanded={active}\n        aria-haspopup=\"listbox\"\n        aria-label={`${token.word}, ${Math.round(token.p * 100)}% likely. Show alternatives`}\n        className={cn(\n          \"-mx-0.5 cursor-pointer rounded-[4px] px-0.5 underline decoration-[1.5px] underline-offset-[5px] outline-hidden transition-[background-color,text-decoration-color] duration-150 [box-decoration-break:clone] focus-visible:ring-2 focus-visible:ring-orange-600/40\",\n          edited\n            ? \"decoration-orange-600 decoration-solid dark:decoration-orange-400\"\n            : \"decoration-zinc-400 decoration-dotted dark:decoration-zinc-500\",\n          active\n            ? \"bg-zinc-900/[0.07] dark:bg-white/10\"\n            : \"hover:bg-zinc-900/[0.05] dark:hover:bg-white/[0.07]\"\n        )}\n        onClick={onToggle}\n        ref={ref}\n        style={heat ? style : undefined}\n        type=\"button\"\n      >\n        {token.word}\n      </motion.button>\n    </>\n  );\n}\n\nfunction Alternatives({\n  slot,\n  current,\n  x,\n  y,\n  onPick,\n  onClose,\n}: {\n  slot: TokenSlot;\n  current: string;\n  x: number;\n  y: number;\n  onPick: (text: string) => void;\n  onClose: () => void;\n}) {\n  const listRef = useRef<HTMLDivElement>(null);\n  const options = [...slot.options].sort((a, b) => b.p - a.p);\n\n  useEffect(() => {\n    const selected = listRef.current?.querySelector<HTMLButtonElement>(\n      '[aria-selected=\"true\"]'\n    );\n    selected?.focus({ preventScroll: true });\n  }, []);\n\n  const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n    const items = [\n      ...(listRef.current?.querySelectorAll<HTMLButtonElement>(\n        '[role=\"option\"]'\n      ) ?? []),\n    ];\n    const at = items.indexOf(document.activeElement as HTMLButtonElement);\n    if (event.key === \"ArrowDown\" || event.key === \"ArrowUp\") {\n      event.preventDefault();\n      const step = event.key === \"ArrowDown\" ? 1 : -1;\n      items.at((at + step + items.length) % items.length)?.focus();\n    } else if (event.key === \"Escape\" || event.key === \"Tab\") {\n      event.preventDefault();\n      onClose();\n    }\n  };\n\n  return (\n    <motion.div\n      animate={{ opacity: 1, scale: 1, y: 0 }}\n      aria-label=\"Other words the model considered\"\n      className=\"absolute z-20 origin-top-left rounded-xl bg-white p-1.5 shadow-[0_12px_32px_-12px_rgb(0_0_0/0.25)] ring-1 ring-black/[0.08] dark:bg-zinc-800 dark:shadow-[0_12px_32px_-12px_rgb(0_0_0/0.7)] dark:ring-white/10\"\n      exit={{ opacity: 0, transition: { duration: 0.1 } }}\n      initial={{ opacity: 0, scale: 0.97, y: -4 }}\n      onKeyDown={onKeyDown}\n      ref={listRef}\n      role=\"listbox\"\n      style={{ left: x, top: y, width: MENU_WIDTH }}\n      transition={{ duration: 0.16, ease: EASE_OUT }}\n    >\n      <p className=\"px-2 pt-1 pb-1.5 text-[11px] text-zinc-500 dark:text-zinc-400\">\n        Words it weighed here\n      </p>\n      {options.map((option) => {\n        const selected = option.text === current;\n        return (\n          <button\n            aria-selected={selected}\n            className=\"flex w-full items-center gap-2.5 rounded-lg px-2 py-1.5 text-left outline-hidden transition-colors duration-100 hover:bg-zinc-100 focus-visible:bg-zinc-100 dark:focus-visible:bg-white/[0.07] dark:hover:bg-white/[0.07]\"\n            key={option.text}\n            onClick={() => onPick(option.text)}\n            role=\"option\"\n            type=\"button\"\n          >\n            <span className=\"min-w-0 flex-1 truncate font-medium text-[13px] text-zinc-900 dark:text-zinc-100\">\n              {option.text}\n            </span>\n            <span className=\"h-1 w-14 shrink-0 overflow-hidden rounded-full bg-zinc-900/[0.07] dark:bg-white/10\">\n              <motion.span\n                animate={{ scaleX: option.p }}\n                className={cn(\n                  \"block h-full origin-left rounded-full\",\n                  selected\n                    ? \"bg-orange-600 dark:bg-orange-400\"\n                    : \"bg-zinc-400 dark:bg-zinc-500\"\n                )}\n                initial={{ scaleX: 0 }}\n                transition={{ duration: 0.25, ease: EASE_OUT }}\n              />\n            </span>\n            <span className=\"w-8 shrink-0 text-right font-mono text-[11px] text-zinc-500 tabular-nums dark:text-zinc-400\">\n              {Math.round(option.p * 100)}%\n            </span>\n            <Check\n              aria-hidden=\"true\"\n              className={cn(\n                \"size-3.5 shrink-0 text-zinc-900 dark:text-zinc-100\",\n                !selected && \"invisible\"\n              )}\n            />\n          </button>\n        );\n      })}\n    </motion.div>\n  );\n}\n\nfunction HeatSwitch({ on, onToggle }: { on: boolean; onToggle: () => void }) {\n  return (\n    <button\n      aria-checked={on}\n      className=\"group flex items-center gap-2 rounded-md py-1 text-[12px] text-zinc-600 outline-hidden focus-visible:ring-2 focus-visible:ring-orange-600/40 dark:text-zinc-300\"\n      onClick={onToggle}\n      role=\"switch\"\n      type=\"button\"\n    >\n      <span\n        className={cn(\n          \"relative h-4 w-7 rounded-full transition-colors duration-200\",\n          on\n            ? \"bg-orange-600 dark:bg-orange-500\"\n            : \"bg-zinc-300 dark:bg-zinc-600\"\n        )}\n      >\n        <span\n          className={cn(\n            \"absolute top-0.5 left-0.5 size-3 rounded-full bg-white shadow-sm transition-transform duration-200 ease-[cubic-bezier(0.23,1,0.32,1)]\",\n            on && \"translate-x-3\"\n          )}\n        />\n      </span>\n      Confidence\n    </button>\n  );\n}\n\nfunction EditChips({\n  edits,\n  choice,\n  onRevert,\n  onReset,\n}: {\n  edits: TokenSlot[];\n  choice: Record<string, string>;\n  onRevert: (slot: TokenSlot) => void;\n  onReset: () => void;\n}) {\n  return (\n    <>\n      <AnimatePresence initial={false} mode=\"popLayout\">\n        {edits.map((slot) => (\n          <motion.span\n            animate={{ opacity: 1 }}\n            className=\"flex h-6 items-center gap-1 rounded-full bg-zinc-100 pr-1 pl-2 text-[11px] text-zinc-600 dark:bg-zinc-800 dark:text-zinc-300\"\n            exit={{ opacity: 0 }}\n            initial={{ opacity: 0 }}\n            key={slot.id}\n            layout\n            transition={{ duration: 0.18, ease: EASE_OUT }}\n          >\n            <span className=\"text-zinc-400 line-through decoration-zinc-400/70 dark:text-zinc-500\">\n              {slot.options[0].text}\n            </span>\n            <span className=\"font-medium text-zinc-900 dark:text-zinc-100\">\n              {choice[slot.id]}\n            </span>\n            <button\n              aria-label={`Back to ${slot.options[0].text}`}\n              className=\"flex size-4 items-center justify-center rounded-full text-zinc-400 transition-colors duration-100 hover:bg-zinc-200 hover:text-zinc-700 dark:hover:bg-white/10 dark:hover:text-zinc-100\"\n              onClick={() => onRevert(slot)}\n              type=\"button\"\n            >\n              <X className=\"size-3\" />\n            </button>\n          </motion.span>\n        ))}\n      </AnimatePresence>\n      {edits.length > 1 && (\n        <button\n          className=\"flex h-6 items-center gap-1 rounded-full px-2 text-[11px] text-zinc-500 transition-colors duration-100 hover:bg-zinc-100 hover:text-zinc-900 dark:text-zinc-400 dark:hover:bg-white/[0.07] dark:hover:text-white\"\n          onClick={onReset}\n          type=\"button\"\n        >\n          <RotateCcw className=\"size-3\" />\n          Reset\n        </button>\n      )}\n    </>\n  );\n}\n",
      "path": "/components/kokonutui/ai-token-alternatives.tsx",
      "target": "components/kokonutui/ai-token-alternatives.tsx"
    }
  ]
}