{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "typewriter-human",
  "type": "registry:component",
  "title": "Typewriter Human",
  "description": "A typewriter with uneven rhythm: longer beats after punctuation, the occasional wrong key noticed late and backspaced. The sequence is seeded, so it is identical on every render.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "text",
    "text",
    "typewriter",
    "typing",
    "typo",
    "human",
    "caret"
  ],
  "docs": "https://hyperblur.dev/effects/typewriter-human",
  "files": [
    {
      "path": "registry/hyperblur/typewriter-human.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/typewriter-human.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface TypewriterHumanProps extends React.HTMLAttributes<HTMLSpanElement> {\n  text: string;\n  speed?: number;\n  typos?: number;\n  seed?: number;\n  loop?: boolean;\n  pause?: number;\n  accent?: string;\n}\n\nconst css = `\n@keyframes hb-zz3-blink {\n  0%, 49.9% { opacity: 1; }\n  50%, 100% { opacity: 0; }\n}\n.hb-zz3 {\n  display: inline;\n  font-family: inherit;\n  white-space: pre-wrap;\n  overflow-wrap: anywhere;\n}\n.hb-zz3-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  padding: 0;\n  overflow: hidden;\n  clip: rect(0, 0, 0, 0);\n  white-space: nowrap;\n  border: 0;\n}\n.hb-zz3-w { color: #ff7a7a; text-decoration: underline wavy rgba(255, 122, 122, 0.7) 1px; text-underline-offset: 0.18em; }\n.hb-zz3-h { visibility: hidden; }\n.hb-zz3-k { position: relative; }\n.hb-zz3-k::after {\n  content: \"\";\n  position: absolute;\n  left: 0.04em;\n  top: 0.12em;\n  bottom: 0.08em;\n  width: 0.095em;\n  border-radius: 1px;\n  background: var(--hb-zz3-accent);\n  animation: hb-zz3-blink 1.05s linear infinite;\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-zz3-k::after { animation: none; }\n}\n`;\n\nfunction mix(n: number) {\n  let h = Math.imul(n ^ 0x9e3779b9, 0x85ebca6b);\n  h ^= h >>> 13;\n  h = Math.imul(h, 0xc2b2ae35);\n  h ^= h >>> 16;\n  return h >>> 0;\n}\n\nconst rows = [\"qwertyuiop\", \"asdfghjkl\", \"zxcvbnm\"];\n\nfunction neighbors(ch: string) {\n  const lower = ch.toLowerCase();\n  const out: string[] = [];\n  rows.forEach((row, r) => {\n    const c = row.indexOf(lower);\n    if (c < 0) return;\n    if (row[c - 1]) out.push(row[c - 1]);\n    if (row[c + 1]) out.push(row[c + 1]);\n    const above = rows[r - 1];\n    if (above?.[c]) out.push(above[c]);\n    const below = rows[r + 1];\n    if (below?.[c]) out.push(below[c]);\n  });\n  return out;\n}\n\ntype Step = { op: \"add\" | \"del\"; ch: string; wait: number };\n\nfunction build(text: string, speed: number, typos: number, seed: number): Step[] {\n  const chars = Array.from(text);\n  const n = chars.length;\n  const steps: Step[] = [];\n  const skip = new Set<number>();\n  let i = 0;\n  while (i < n) {\n    const ch = chars[i];\n    const prev = i > 0 ? chars[i - 1] : \"\";\n    const h = mix(i * 977 + seed * 131 + 11);\n    let wait = speed * (0.55 + ((h % 1000) / 1000) * 0.95);\n    if (prev === \".\" || prev === \"!\" || prev === \"?\") wait += speed * 5.5;\n    else if (prev === \",\" || prev === \";\" || prev === \":\") wait += speed * 2.8;\n    else if (prev === \" \") wait += speed * 0.3;\n    const roll = (mix(i * 613 + seed * 17 + 5) % 1000) / 1000;\n    const near = /[a-z]/i.test(ch) ? neighbors(ch) : [];\n    const typo = !skip.has(i) && i >= 2 && n - i > 2 && roll < typos && near.length > 0;\n    if (typo) {\n      const pick = near[h % near.length];\n      const wrong = ch === ch.toUpperCase() && ch !== ch.toLowerCase() ? pick.toUpperCase() : pick;\n      steps.push({ op: \"add\", ch: wrong, wait });\n      const extra = Math.min(mix(i * 37 + seed * 3 + 1) % 3, n - i - 1);\n      for (let k = 1; k <= extra; k++) {\n        steps.push({ op: \"add\", ch: chars[i + k], wait: speed * (0.5 + ((mix(i * 53 + k) % 100) / 100) * 0.5) });\n      }\n      for (let k = 0; k <= extra; k++) {\n        steps.push({ op: \"del\", ch: \"\", wait: k === 0 ? speed * (2.4 + ((h % 7) / 7) * 1.4) : speed * 0.42 });\n      }\n      skip.add(i);\n      continue;\n    }\n    steps.push({ op: \"add\", ch, wait });\n    i++;\n  }\n  return steps;\n}\n\nexport function TypewriterHuman({\n  text,\n  speed = 75,\n  typos = 0.05,\n  seed = 3,\n  loop = true,\n  pause = 2600,\n  accent = \"#7fb3ff\",\n  className = \"\",\n  style,\n  ...rest\n}: TypewriterHumanProps) {\n  const ref = React.useRef<HTMLSpanElement>(null);\n  const [shown, setShown] = React.useState(\"\");\n  const [active, setActive] = React.useState(false);\n  const script = React.useMemo(\n    () => build(text, Math.max(10, speed), Math.min(1, Math.max(0, typos)), seed),\n    [text, speed, typos, seed],\n  );\n\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const io = new IntersectionObserver((entries) => {\n      for (const e of entries) setActive(e.isIntersecting);\n    });\n    io.observe(el);\n    return () => io.disconnect();\n  }, []);\n\n  React.useEffect(() => {\n    if (!active) return;\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    let timer = 0;\n    if (reduced) {\n      timer = window.setTimeout(() => setShown(text), 0);\n      return () => window.clearTimeout(timer);\n    }\n    let pos = 0;\n    let buf: string[] = [];\n    const run = () => {\n      if (pos >= script.length) {\n        if (!loop) return;\n        timer = window.setTimeout(() => {\n          pos = 0;\n          buf = [];\n          setShown(\"\");\n          timer = window.setTimeout(run, 600);\n        }, pause);\n        return;\n      }\n      const step = script[pos++];\n      timer = window.setTimeout(() => {\n        if (step.op === \"add\") buf.push(step.ch);\n        else buf.pop();\n        setShown(buf.join(\"\"));\n        run();\n      }, step.wait);\n    };\n    timer = window.setTimeout(() => {\n      setShown(\"\");\n      run();\n    }, 450);\n    return () => window.clearTimeout(timer);\n  }, [active, script, loop, pause, text]);\n\n  const target = Array.from(text);\n  const typed = Array.from(shown);\n  let good = 0;\n  while (good < typed.length && good < target.length && typed[good] === target[good]) good++;\n\n  return (\n    <span\n      {...rest}\n      ref={ref}\n      className={`hb-zz3${className ? ` ${className}` : \"\"}`}\n      style={{ [\"--hb-zz3-accent\" as string]: accent, ...style }}\n    >\n      <style href=\"hb-typewriter-human\" precedence=\"default\">{css}</style>\n      <span className=\"hb-zz3-sr\">{text}</span>\n      <span aria-hidden=\"true\">\n        {target.slice(0, good).join(\"\")}\n        {good < typed.length ? <span className=\"hb-zz3-w\">{typed.slice(good).join(\"\")}</span> : null}\n        <span className=\"hb-zz3-k\" />\n        <span className=\"hb-zz3-h\">{target.slice(good).join(\"\")}</span>\n      </span>\n    </span>\n  );\n}\n"
    }
  ]
}