{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chat-bubble-typing",
  "type": "registry:component",
  "title": "Chat Bubble Typing",
  "description": "A chat preview with a business avatar, a typing indicator and messages that appear word by word with a natural rhythm, followed by a reply button.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "ordering",
    "chat",
    "typing",
    "message",
    "preview",
    "notification",
    "animation"
  ],
  "docs": "https://hyperblur.dev/effects/chat-bubble-typing",
  "files": [
    {
      "path": "registry/hyperblur/chat-bubble-typing.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/chat-bubble-typing.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ChatBubbleTypingLabels {\n  online: string;\n  typing: string;\n  reply: string;\n}\n\nexport interface ChatBubbleTypingProps extends React.HTMLAttributes<HTMLDivElement> {\n  name?: string;\n  initials?: string;\n  messages?: string[];\n  time?: string;\n  phone?: string;\n  message?: string;\n  href?: string;\n  typingDuration?: number;\n  wordDelay?: number;\n  messageGap?: number;\n  startDelay?: number;\n  loop?: boolean;\n  loopDelay?: number;\n  showHeader?: boolean;\n  showReply?: boolean;\n  theme?: \"dark\" | \"light\";\n  accent?: string;\n  labels?: Partial<ChatBubbleTypingLabels>;\n}\n\nconst defaultLabels: ChatBubbleTypingLabels = {\n  online: \"online\",\n  typing: \"typing...\",\n  reply: \"Reply on chat\",\n};\n\nconst defaultMessages = [\n  \"Hi Sam! Your order #2048 is on the grill right now.\",\n  \"Ready for pickup in about 15 minutes. Want to add a cold drink?\",\n];\n\nconst css = `\n.hb-ob4 {\n  --hb-ob4-bg: #0d0d0d;\n  --hb-ob4-bubble: #1b1b1b;\n  --hb-ob4-line: #262626;\n  --hb-ob4-text: #ededed;\n  --hb-ob4-muted: #8f8f8f;\n  box-sizing: border-box;\n  display: flex;\n  flex-direction: column;\n  gap: 10px;\n  width: 100%;\n  min-height: 0;\n  padding: 12px;\n  border: 1px solid var(--hb-ob4-line);\n  border-radius: 20px;\n  background:\n    radial-gradient(120% 70% at 0% 0%, color-mix(in srgb, var(--hb-ob4-accent) 7%, transparent) 0%, transparent 60%),\n    var(--hb-ob4-bg);\n  color: var(--hb-ob4-text);\n  font-family: inherit;\n  font-size: 13.5px;\n  line-height: 1.42;\n  container-type: inline-size;\n}\n.hb-ob4 *, .hb-ob4 *::before, .hb-ob4 *::after { box-sizing: border-box; }\n.hb-ob4[data-theme=\"light\"] {\n  --hb-ob4-bg: #f3f1ec;\n  --hb-ob4-bubble: #ffffff;\n  --hb-ob4-line: #e3dfd6;\n  --hb-ob4-text: #161616;\n  --hb-ob4-muted: #75716a;\n}\n.hb-ob4-head { display: flex; flex: none; align-items: center; gap: 10px; }\n.hb-ob4-av {\n  position: relative;\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: 34px;\n  height: 34px;\n  border-radius: 50%;\n  background: linear-gradient(140deg, #f59e0b 0%, #ea580c 55%, #9a3412 100%);\n  color: #fff;\n  font-size: 12.5px;\n  font-weight: 700;\n  letter-spacing: 0.02em;\n  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);\n}\n.hb-ob4-on {\n  position: absolute;\n  right: -1px;\n  bottom: -1px;\n  width: 11px;\n  height: 11px;\n  border: 2px solid var(--hb-ob4-bg);\n  border-radius: 50%;\n  background: var(--hb-ob4-accent);\n}\n.hb-ob4-who { display: flex; min-width: 0; flex-direction: column; }\n.hb-ob4-name { overflow: hidden; font-size: 14px; font-weight: 650; line-height: 1.2; white-space: nowrap; text-overflow: ellipsis; }\n.hb-ob4-status { color: var(--hb-ob4-muted); font-size: 12px; line-height: 1.3; transition: color 0.2s ease; }\n.hb-ob4-status[data-typing=\"true\"] { color: var(--hb-ob4-accent); }\n.hb-ob4-log { display: flex; flex: 1 1 auto; min-height: 0; flex-direction: column; justify-content: flex-end; gap: 6px; overflow: hidden; padding-top: 2px; }\n.hb-ob4-msg {\n  position: relative;\n  align-self: flex-start;\n  max-width: 88%;\n  padding: 8px 12px 7px;\n  border: 1px solid var(--hb-ob4-line);\n  border-radius: 4px 16px 16px 16px;\n  background: var(--hb-ob4-bubble);\n  animation: hb-ob4-pop 0.32s cubic-bezier(0.25, 1.3, 0.5, 1) both;\n  transform-origin: 0 0;\n}\n.hb-ob4-msg + .hb-ob4-msg { border-radius: 16px; }\n.hb-ob4[data-theme=\"light\"] .hb-ob4-msg { box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06); }\n.hb-ob4-w { animation: hb-ob4-word 0.28s ease both; }\n.hb-ob4-time { float: right; margin: 6px 0 -2px 10px; color: var(--hb-ob4-muted); font-size: 10.5px; line-height: 1; font-variant-numeric: tabular-nums; }\n.hb-ob4-dots { display: inline-flex; align-items: center; gap: 4px; height: 19px; padding: 0 2px; }\n.hb-ob4-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--hb-ob4-muted); animation: hb-ob4-dot 1.2s ease-in-out infinite; }\n.hb-ob4-dots span:nth-child(2) { animation-delay: 0.16s; }\n.hb-ob4-dots span:nth-child(3) { animation-delay: 0.32s; }\n.hb-ob4-reply {\n  display: inline-flex;\n  flex: none;\n  align-items: center;\n  align-self: flex-start;\n  gap: 7px;\n  height: 32px;\n  padding: 0 14px 0 11px;\n  border-radius: 999px;\n  background: var(--hb-ob4-accent);\n  color: #062a14;\n  font-size: 12.5px;\n  font-weight: 650;\n  text-decoration: none;\n  opacity: 0;\n  visibility: hidden;\n  transform: translateY(4px);\n  transition: opacity 0.35s ease, transform 0.35s ease, visibility 0s 0.35s, filter 0.15s ease;\n}\n.hb-ob4-reply[data-show=\"true\"] { opacity: 1; visibility: visible; transform: none; transition: opacity 0.35s ease, transform 0.35s ease, visibility 0s, filter 0.15s ease; }\n.hb-ob4-reply:hover { filter: brightness(1.08); }\n.hb-ob4-reply:focus-visible { outline: 2px solid var(--hb-ob4-accent); outline-offset: 3px; }\n.hb-ob4-reply svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }\n.hb-ob4-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }\n@container (max-width: 300px) {\n  .hb-ob4-av { width: 28px; height: 28px; font-size: 11px; }\n  .hb-ob4-msg { max-width: 94%; }\n  .hb-ob4 { font-size: 13px; }\n}\n@container (min-width: 520px) {\n  .hb-ob4 { padding: 16px; font-size: 14.5px; }\n  .hb-ob4-msg { max-width: 70%; }\n}\n@keyframes hb-ob4-pop { from { opacity: 0; transform: scale(0.86) translateY(4px); } to { opacity: 1; transform: none; } }\n@keyframes hb-ob4-word { from { opacity: 0; filter: blur(2px); } to { opacity: 1; filter: blur(0); } }\n@keyframes hb-ob4-dot { 0%, 60%, 100% { transform: translateY(0); opacity: 0.45; } 30% { transform: translateY(-4px); opacity: 1; } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-ob4-msg, .hb-ob4-w, .hb-ob4-dots span { animation: none; }\n  .hb-ob4-reply, .hb-ob4-reply[data-show=\"true\"], .hb-ob4-status { transition: none; }\n}\n`;\n\nfunction chatHref(phone: string, message?: string) {\n  const digits = phone.replace(/\\D/g, \"\");\n  return `https://wa.me/${digits}${message ? `?text=${encodeURIComponent(message)}` : \"\"}`;\n}\n\nfunction hash(n: number) {\n  let x = (n ^ 0x9e3779b9) >>> 0;\n  x = Math.imul(x ^ (x >>> 16), 0x85ebca6b) >>> 0;\n  x = Math.imul(x ^ (x >>> 13), 0xc2b2ae35) >>> 0;\n  return (x ^ (x >>> 16)) >>> 0;\n}\n\nfunction initialsOf(name: string) {\n  return name\n    .split(/\\s+/)\n    .filter((w) => /[A-Za-z0-9]/.test(w.charAt(0)))\n    .slice(0, 2)\n    .map((w) => w.charAt(0).toUpperCase())\n    .join(\"\");\n}\n\ntype Step = { msg: number; words: number; typing: boolean; done: boolean };\n\nexport function ChatBubbleTyping({\n  name = \"Corner Kitchen\",\n  initials,\n  messages = defaultMessages,\n  time = \"7:42 PM\",\n  phone = \"1 555 555 0142\",\n  message = \"Hi! Yes, please add a lemonade.\",\n  href,\n  typingDuration = 1300,\n  wordDelay = 95,\n  messageGap = 700,\n  startDelay = 400,\n  loop = false,\n  loopDelay = 4200,\n  showHeader = true,\n  showReply = true,\n  theme = \"dark\",\n  accent = \"#25d366\",\n  labels,\n  className,\n  style,\n  ...rest\n}: ChatBubbleTypingProps) {\n  const l = { ...defaultLabels, ...labels };\n  const key = messages.join(\"\\u0001\");\n  const split = React.useMemo(() => key.split(\"\\u0001\").map((m) => m.split(/\\s+/).filter(Boolean)), [key]);\n  const [step, setStep] = React.useState<Step>({ msg: 0, words: 0, typing: true, done: false });\n\n  React.useEffect(() => {\n    const timers: ReturnType<typeof setTimeout>[] = [];\n    let cancelled = false;\n    const wait = (ms: number, fn: () => void) => {\n      timers.push(\n        setTimeout(() => {\n          if (!cancelled) fn();\n        }, ms),\n      );\n    };\n    const total = split.length;\n    if (!total) return;\n    const reduce = typeof window !== \"undefined\" && window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    if (reduce) {\n      wait(0, () => setStep({ msg: total - 1, words: split[total - 1].length, typing: false, done: true }));\n      return () => {\n        cancelled = true;\n        timers.forEach(clearTimeout);\n      };\n    }\n    const delayFor = (i: number, w: number) => {\n      const word = split[i][w - 1] ?? \"\";\n      let ms = wordDelay + word.length * 9 + (hash(i * 131 + w * 17) % 70);\n      if (/[.!?][\"')]?$/.test(word)) ms += 320;\n      else if (/[,;:]$/.test(word)) ms += 170;\n      return ms;\n    };\n    const reveal = (i: number, w: number) => {\n      setStep({ msg: i, words: w, typing: false, done: false });\n      if (w < split[i].length) wait(delayFor(i, w), () => reveal(i, w + 1));\n      else if (i + 1 < total) wait(messageGap, () => type(i + 1));\n      else {\n        wait(120, () => setStep({ msg: i, words: w, typing: false, done: true }));\n        if (loop) wait(loopDelay, () => type(0));\n      }\n    };\n    const type = (i: number) => {\n      setStep({ msg: i, words: 0, typing: true, done: false });\n      wait(typingDuration, () => reveal(i, 1));\n    };\n    wait(startDelay, () => type(0));\n    return () => {\n      cancelled = true;\n      timers.forEach(clearTimeout);\n    };\n  }, [split, typingDuration, wordDelay, messageGap, startDelay, loop, loopDelay]);\n\n  const replyHref = href ?? chatHref(phone, message);\n  const shown = split.slice(0, step.msg + 1);\n\n  return (\n    <div\n      className={[\"hb-ob4\", className].filter(Boolean).join(\" \")}\n      data-theme={theme}\n      style={{ \"--hb-ob4-accent\": accent, ...style } as React.CSSProperties}\n      {...rest}\n    >\n      <style href=\"hb-chat-bubble-typing\" precedence=\"default\">{css}</style>\n      {showHeader ? (\n        <div className=\"hb-ob4-head\">\n          <span className=\"hb-ob4-av\" aria-hidden=\"true\">\n            {initials ?? initialsOf(name)}\n            <span className=\"hb-ob4-on\" />\n          </span>\n          <span className=\"hb-ob4-who\">\n            <span className=\"hb-ob4-name\">{name}</span>\n            <span className=\"hb-ob4-status\" data-typing={step.typing ? \"true\" : \"false\"}>\n              {step.typing ? l.typing : l.online}\n            </span>\n          </span>\n        </div>\n      ) : null}\n      <div className=\"hb-ob4-log\">\n        {shown.map((words, i) => {\n          const isCurrent = i === step.msg;\n          if (isCurrent && step.typing) {\n            return (\n              <div key={`t${i}`} className=\"hb-ob4-msg\" aria-label={l.typing}>\n                <span className=\"hb-ob4-dots\" aria-hidden=\"true\">\n                  <span />\n                  <span />\n                  <span />\n                </span>\n              </div>\n            );\n          }\n          const visible = isCurrent ? words.slice(0, step.words) : words;\n          const complete = visible.length === words.length;\n          return (\n            <div key={`m${i}`} className=\"hb-ob4-msg\">\n              <span className=\"hb-ob4-sr\">{words.join(\" \")}</span>\n              <span aria-hidden=\"true\">\n                {visible.map((w, j) => (\n                  <span key={j} className=\"hb-ob4-w\">\n                    {j ? \" \" : \"\"}\n                    {w}\n                  </span>\n                ))}\n              </span>\n              {complete && time ? (\n                <span className=\"hb-ob4-time\" aria-hidden=\"true\">\n                  {time}\n                </span>\n              ) : null}\n            </div>\n          );\n        })}\n      </div>\n      {showReply ? (\n        <a\n          className=\"hb-ob4-reply\"\n          href={replyHref}\n          target=\"_blank\"\n          rel=\"noopener noreferrer\"\n          data-show={step.done ? \"true\" : \"false\"}\n          tabIndex={step.done ? undefined : -1}\n          aria-hidden={step.done ? undefined : true}\n        >\n          <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n            <path d=\"M9 14 4 9l5-5\" />\n            <path d=\"M4 9h10.5a5.5 5.5 0 0 1 0 11H13\" />\n          </svg>\n          {l.reply}\n        </a>\n      ) : null}\n    </div>\n  );\n}\n"
    }
  ]
}