{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "motion-karaoke-paragraph",
  "type": "registry:component",
  "title": "Motion Karaoke Paragraph",
  "description": "A pinned quote that fills with light letter by letter as you scroll, like karaoke lyrics. Phrases wrapped in asterisks take the accent and get a marker stroke once read, and a counter tracks the words.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "motion",
    "scroll",
    "text",
    "highlight",
    "quote",
    "reading",
    "pinned"
  ],
  "docs": "https://hyperblur.dev/effects/motion-karaoke-paragraph",
  "files": [
    {
      "path": "registry/hyperblur/motion-karaoke-paragraph.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/motion-karaoke-paragraph.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface MotionKaraokeParagraphProps extends Omit<React.HTMLAttributes<HTMLElement>, \"title\"> {\n  text?: string;\n  eyebrow?: string;\n  author?: string;\n  accent?: string;\n  progress?: number;\n  autoPlay?: boolean;\n  duration?: number;\n  length?: number;\n  height?: string;\n}\n\nconst defaultText =\n  \"We stopped measuring how much we shipped and started measuring *how it felt to use*. The roadmap got shorter, the releases got quieter, and for the first time our customers wrote to say *thank you* instead of asking where things had gone.\";\n\nconst css = `\n.hb-wh4 {\n  --hb-wh4-a: #2f7bff;\n  --hb-wh4-p: 0;\n  position: relative;\n  width: 100%;\n  height: var(--hb-wh4-h);\n  color: #ededed;\n  font-family: inherit;\n  background: #0a0a0a;\n}\n.hb-wh4[data-pinned=\"true\"] { height: calc(var(--hb-wh4-h) * var(--hb-wh4-len)); }\n.hb-wh4 *, .hb-wh4 *::before, .hb-wh4 *::after { box-sizing: border-box; }\n.hb-wh4-stage {\n  position: sticky;\n  top: 0;\n  height: var(--hb-wh4-h);\n  overflow: hidden;\n  container-type: size;\n  display: flex;\n  flex-direction: column;\n  justify-content: center;\n  gap: clamp(8px, 4cqh, 36px);\n  padding: 6cqh max(16px, 8cqw);\n  background: radial-gradient(80% 60% at 50% 110%, color-mix(in srgb, var(--hb-wh4-a) 9%, transparent), transparent 70%), #0a0a0a;\n}\n.hb-wh4-head {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  gap: 1em;\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: clamp(8px, 1.6cqw, 12px);\n  letter-spacing: 0.14em;\n  text-transform: uppercase;\n  color: #7c7c7c;\n}\n.hb-wh4-count { font-variant-numeric: tabular-nums; color: #a1a1a1; }\n.hb-wh4-count b { font-weight: 500; color: #ededed; }\n.hb-wh4-text {\n  margin: 0;\n  max-width: 34ch;\n  font-family: var(--font-grotesk, var(--font-sans, system-ui));\n  font-size: clamp(13px, min(4.6cqw, 7cqh), 54px);\n  font-weight: 500;\n  line-height: 1.32;\n  letter-spacing: -0.02em;\n}\n.hb-wh4-w {\n  --hb-wh4-f: clamp(0, calc(var(--hb-wh4-p) * var(--hb-wh4-n) * 1.08 - var(--i)), 1);\n  position: relative;\n  display: inline;\n  color: transparent;\n  background:\n    linear-gradient(90deg, #f5f5f5, #f5f5f5) no-repeat 0 0 / calc(var(--hb-wh4-f) * 100%) 100%,\n    #3a3a3a;\n  -webkit-background-clip: text;\n  background-clip: text;\n}\n.hb-wh4-w[data-em=\"true\"] {\n  background:\n    linear-gradient(90deg, color-mix(in srgb, var(--hb-wh4-a) 40%, #fff), color-mix(in srgb, var(--hb-wh4-a) 40%, #fff)) no-repeat 0 0 / calc(var(--hb-wh4-f) * 100%) 100%,\n    #3a3a3a;\n  -webkit-background-clip: text;\n  background-clip: text;\n}\n.hb-wh4-mk {\n  position: relative;\n  display: inline;\n  background: linear-gradient(90deg, color-mix(in srgb, var(--hb-wh4-a) 30%, transparent), color-mix(in srgb, var(--hb-wh4-a) 18%, transparent)) no-repeat 0 88% / calc(var(--hb-wh4-mk) * 100%) 0.42em;\n  -webkit-box-decoration-break: clone;\n  box-decoration-break: clone;\n}\n.hb-wh4-caret {\n  display: inline-block;\n  width: 0.08em;\n  height: 0.95em;\n  margin-left: 0.04em;\n  vertical-align: -0.12em;\n  border-radius: 1px;\n  background: var(--hb-wh4-a);\n  box-shadow: 0 0 10px var(--hb-wh4-a);\n  opacity: calc(1 - clamp(0, (var(--hb-wh4-p) - 0.9) * 10, 1));\n  animation: hb-wh4-blink 1s steps(1) infinite;\n}\n@keyframes hb-wh4-blink { 50% { visibility: hidden; } }\n.hb-wh4-foot {\n  display: flex;\n  align-items: center;\n  gap: 0.75em;\n  font-size: clamp(9px, 1.7cqw, 14px);\n  color: #8f8f8f;\n}\n.hb-wh4-bar {\n  position: relative;\n  flex: 0 0 clamp(40px, 16cqw, 160px);\n  height: 2px;\n  border-radius: 2px;\n  background: #232323;\n  overflow: hidden;\n}\n.hb-wh4-bar::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  background: var(--hb-wh4-a);\n  transform-origin: left;\n  transform: scaleX(var(--hb-wh4-p));\n}\n.hb-wh4-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-wh4-caret { animation: none; display: none; }\n}\n`;\n\nfunction clamp01(x: number) {\n  return Math.min(1, Math.max(0, x));\n}\n\nfunction inOut(x: number) {\n  return x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;\n}\n\nfunction findScroller(el: HTMLElement): HTMLElement | null {\n  let node = el.parentElement;\n  while (node && node !== document.body && node !== document.documentElement) {\n    const oy = getComputedStyle(node).overflowY;\n    if ((oy === \"auto\" || oy === \"scroll\" || oy === \"overlay\") && node.scrollHeight > node.clientHeight + 1) return node;\n    node = node.parentElement;\n  }\n  return null;\n}\n\nfunction loopAt(ms: number, duration: number) {\n  const d = Math.max(1, duration) * 1000;\n  const back = d * 0.3;\n  const hold = 1800;\n  const t = ms % (d + hold + back + 500);\n  if (t < d) return t / d;\n  if (t < d + hold) return 1;\n  if (t < d + hold + back) return 1 - inOut((t - d - hold) / back);\n  return 0;\n}\n\nfunction useProgress(\n  ref: React.RefObject<HTMLElement | null>,\n  apply: (p: number) => void,\n  progress: number | undefined,\n  autoPlay: boolean,\n  duration: number,\n) {\n  const applyRef = React.useRef(apply);\n  React.useLayoutEffect(() => {\n    applyRef.current = apply;\n  });\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const run = (p: number) => applyRef.current(clamp01(p));\n    if (typeof progress === \"number\") {\n      run(progress);\n      return;\n    }\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) {\n      run(1);\n      return;\n    }\n    let raf = 0;\n    if (autoPlay) {\n      let visible = true;\n      let last = 0;\n      let t = 0;\n      const io = new IntersectionObserver((entries) => {\n        visible = entries[0]?.isIntersecting ?? true;\n      });\n      io.observe(el);\n      const loop = (now: number) => {\n        const dt = last ? Math.min(64, now - last) : 0;\n        last = now;\n        if (visible) {\n          t += dt;\n          run(loopAt(t, duration));\n        }\n        raf = requestAnimationFrame(loop);\n      };\n      raf = requestAnimationFrame(loop);\n      return () => {\n        cancelAnimationFrame(raf);\n        io.disconnect();\n      };\n    }\n    const sc = findScroller(el);\n    const measure = () => {\n      raf = 0;\n      const r = el.getBoundingClientRect();\n      const top = sc ? r.top - sc.getBoundingClientRect().top : r.top;\n      const vh = sc ? sc.clientHeight : window.innerHeight;\n      const span = r.height - vh;\n      run(span > 1 ? -top / span : (vh - top) / (vh + r.height));\n    };\n    const onScroll = () => {\n      if (!raf) raf = requestAnimationFrame(measure);\n    };\n    measure();\n    const target: HTMLElement | Window = sc ?? window;\n    target.addEventListener(\"scroll\", onScroll, { passive: true });\n    window.addEventListener(\"resize\", onScroll);\n    return () => {\n      cancelAnimationFrame(raf);\n      target.removeEventListener(\"scroll\", onScroll);\n      window.removeEventListener(\"resize\", onScroll);\n    };\n  }, [ref, progress, autoPlay, duration]);\n}\n\ninterface Word {\n  w: string;\n  em: boolean;\n  i: number;\n}\n\nfunction parse(text: string) {\n  const groups: { em: boolean; words: Word[] }[] = [];\n  let n = 0;\n  text.split(\"*\").forEach((part, k) => {\n    const em = k % 2 === 1;\n    const words = part.split(/\\s+/).filter(Boolean).map((w) => ({ w, em, i: n++ }));\n    if (words.length) groups.push({ em, words });\n  });\n  return groups;\n}\n\nexport function MotionKaraokeParagraph({\n  text = defaultText,\n  eyebrow = \"Field notes · Chapter 04\",\n  author = \"Mara Ellison, Head of Product at Tessel\",\n  accent = \"#2f7bff\",\n  progress,\n  autoPlay = false,\n  duration = 7,\n  length = 3,\n  height = \"100vh\",\n  className,\n  style,\n  ...rest\n}: MotionKaraokeParagraphProps) {\n  const ref = React.useRef<HTMLElement>(null);\n  const countRef = React.useRef<HTMLElement>(null);\n  const groups = React.useMemo(() => parse(text), [text]);\n  const total = groups.reduce((n, g) => n + g.words.length, 0);\n  const pinned = progress === undefined && !autoPlay;\n  const plain = text.split(\"*\").join(\"\");\n\n  useProgress(\n    ref,\n    (p) => {\n      const el = ref.current;\n      if (!el) return;\n      el.style.setProperty(\"--hb-wh4-p\", p.toFixed(4));\n      if (countRef.current) {\n        const read = Math.min(total, Math.floor(p * total * 1.08));\n        countRef.current.textContent = String(read).padStart(String(total).length, \"0\");\n      }\n    },\n    progress,\n    autoPlay,\n    duration,\n  );\n\n  return (\n    <section\n      ref={ref}\n      className={[\"hb-wh4\", className].filter(Boolean).join(\" \")}\n      data-pinned={pinned ? \"true\" : \"false\"}\n      style={\n        {\n          \"--hb-wh4-a\": accent,\n          \"--hb-wh4-h\": height,\n          \"--hb-wh4-len\": length,\n          \"--hb-wh4-n\": total,\n          ...style,\n        } as React.CSSProperties\n      }\n      {...rest}\n    >\n      <style href=\"hb-motion-karaoke-paragraph\" precedence=\"default\">{css}</style>\n      <div className=\"hb-wh4-stage\">\n        <div className=\"hb-wh4-head\" aria-hidden=\"true\">\n          <span>{eyebrow}</span>\n          <span className=\"hb-wh4-count\">\n            <b ref={countRef}>{\"0\".padStart(String(total).length, \"0\")}</b> / {total} words\n          </span>\n        </div>\n        <p className=\"hb-wh4-text\">\n          <span className=\"hb-wh4-sr\">{plain}</span>\n          <span aria-hidden=\"true\">\n            {groups.map((g, gi) => {\n              const words = g.words.map((word, wi) => {\n                const i = word.i;\n                return (\n                  <React.Fragment key={i}>\n                    <span className=\"hb-wh4-w\" data-em={word.em ? \"true\" : \"false\"} style={{ \"--i\": i } as React.CSSProperties}>\n                      {word.w}\n                    </span>\n                    {wi < g.words.length - 1 ? \" \" : null}\n                  </React.Fragment>\n                );\n              });\n              const gap = gi < groups.length - 1 ? \" \" : null;\n              if (!g.em) {\n                return (\n                  <React.Fragment key={`g${gi}`}>\n                    {words}\n                    {gap}\n                  </React.Fragment>\n                );\n              }\n              const end = g.words[g.words.length - 1].i + 1;\n              return (\n                <React.Fragment key={`g${gi}`}>\n                  <span\n                    className=\"hb-wh4-mk\"\n                    style={\n                      {\n                        \"--hb-wh4-mk\": `clamp(0, calc((var(--hb-wh4-p) * var(--hb-wh4-n) * 1.08 - ${end}) / 2.5), 1)`,\n                      } as React.CSSProperties\n                    }\n                  >\n                    {words}\n                  </span>\n                  {gap}\n                </React.Fragment>\n              );\n            })}\n            <span className=\"hb-wh4-caret\" />\n          </span>\n        </p>\n        {author ? (\n          <div className=\"hb-wh4-foot\">\n            <span className=\"hb-wh4-bar\" aria-hidden=\"true\" />\n            <span>{author}</span>\n          </div>\n        ) : null}\n      </div>\n    </section>\n  );\n}\n"
    }
  ]
}