{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"livelist","title":"Live list","description":"A checklist your whole team writes in at once. New items arrive in their group with the name of whoever added them, ticked ones settle into Done, and the card never changes height while it happens.","type":"registry:component","author":"Detent","dependencies":["motion"],"registryDependencies":["https://detentui.com/r/theme.json"],"files":[{"path":"components/detent/components/livelist/LiveList.tsx","target":"components/detent/components/livelist/LiveList.tsx","type":"registry:component","content":"'use client'\n\nimport { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'\nimport type { FormEvent, KeyboardEvent, ReactNode } from 'react'\nimport { AnimatePresence, MotionConfig, motion, useReducedMotion } from 'motion/react'\nimport { RollingText } from '@/components/detent/ui/RollingText'\n\nexport type LivePerson = { id: string; name: string; hue: number }\nexport type LiveGroup = { id: string; label: string; hue: number }\nexport type LiveItem = { id: string; title: string; group: string; by: string; done?: boolean; at?: number }\ntype Snap = { order: string[]; done: Record<string, boolean>; keep: Record<string, LiveItem> }\n\nconst take = (list: LiveItem[]): Snap => ({ order: list.map((i) => i.id), done: Object.fromEntries(list.map((i) => [i.id, !!i.done])), keep: Object.fromEntries(list.map((i) => [i.id, i])) })\n\nconst ROW = 36\nconst FRESH = 2200\nconst SETTLE = 700\nconst EASE = [0.3, 0, 0.2, 1] as const\nconst GROW = { duration: 0.26, ease: EASE }\nconst IDLE = 4000\nconst HAIR = 'border-[light-dark(rgb(0_0_0/.06),rgb(255_255_255/.07))]'\n\nconst initials = (name: string) =>\n  name\n    .split(/\\s+/)\n    .map((w) => w[0])\n    .join('')\n    .slice(0, 2)\n    .toUpperCase()\n\nfunction Face({ person, size = 20, ring = false }: { person?: LivePerson; size?: number; ring?: boolean }) {\n  if (!person) return <span className=\"shrink-0\" style={{ width: size }} />\n  return (\n    <span\n      title={person.name}\n      className={`grid shrink-0 place-items-center rounded-full font-semibold tracking-[-0.02em] text-[light-dark(oklch(0.34_0.07_var(--h)),oklch(0.9_0.06_var(--h)))] ${ring ? 'shadow-[0_0_0_2px_var(--tray)]' : ''}`}\n      style={{ width: size, height: size, fontSize: Math.round(size * 0.4), background: `light-dark(oklch(0.91 0.06 ${person.hue}), oklch(0.36 0.07 ${person.hue}))`, ['--h' as string]: person.hue }}\n    >\n      {initials(person.name)}\n    </span>\n  )\n}\n\nfunction Pie({ part, still }: { part: number; still: boolean }) {\n  const c = 2 * Math.PI * 2.25\n  return (\n    <svg viewBox=\"0 0 12 12\" className=\"size-3 shrink-0 -rotate-90\" aria-hidden>\n      <circle cx=\"6\" cy=\"6\" r=\"5.25\" fill=\"none\" stroke=\"currentColor\" strokeOpacity=\".35\" strokeWidth=\"1.5\" />\n      <motion.circle cx=\"6\" cy=\"6\" r=\"2.25\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"4.5\" strokeDasharray={`${c} ${c}`} initial={false} animate={{ strokeDashoffset: c * (1 - part) }} transition={still ? { duration: 0 } : { type: 'spring', stiffness: 200, damping: 30 }} />\n    </svg>\n  )\n}\n\nfunction Box({ done, still }: { done: boolean; still: boolean }) {\n  return (\n    <span className={`relative grid size-[17px] shrink-0 place-items-center rounded-[5px] transition-[background-color,box-shadow] ease-detent duration-150 ${done ? 'bg-ink' : 'bg-surface shadow-[inset_0_0_0_1.5px_light-dark(rgb(0_0_0/.22),rgb(255_255_255/.28))] group-hover/box:shadow-[inset_0_0_0_1.5px_light-dark(rgb(0_0_0/.42),rgb(255_255_255/.5))]'}`}>\n      <svg viewBox=\"0 0 12 12\" className=\"size-[11px]\" fill=\"none\" stroke=\"var(--surface)\" strokeWidth=\"1.9\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden>\n        <motion.path d=\"M2.6 6.3 5 8.6 9.6 3.6\" initial={false} animate={{ pathLength: done ? 1 : 0, opacity: done ? 1 : 0 }} transition={still ? { duration: 0 } : { duration: 0.22, ease: EASE }} />\n      </svg>\n    </span>\n  )\n}\n\nexport function LiveList({\n  title,\n  people,\n  groups,\n  items: controlled,\n  defaultItems = [],\n  onItemsChange,\n  me,\n  height = 340,\n}: {\n  title: string\n  people: LivePerson[]\n  groups: LiveGroup[]\n  items?: LiveItem[]\n  defaultItems?: LiveItem[]\n  onItemsChange?: (items: LiveItem[]) => void\n  me: string\n  height?: number\n}) {\n  const [own, setOwn] = useState(defaultItems)\n  const items = controlled ?? own\n  const still = !!useReducedMotion()\n  const [now, setNow] = useState(0)\n  const [shut, setShut] = useState<Record<string, boolean>>({ __done: true })\n  const [settling, setSettling] = useState<Record<string, boolean>>({})\n  const [draft, setDraft] = useState('')\n  const timers = useRef<Record<string, ReturnType<typeof setTimeout>>>({})\n  const [snap, setSnap] = useState<Snap | null>(null)\n  const [landed, setLanded] = useState<Record<string, boolean>>({})\n  const inside = useRef({ hover: false, focus: false })\n\n  const live = useRef({ items, controlled: controlled !== undefined, onItemsChange, still })\n  useLayoutEffect(() => {\n    live.current = { items, controlled: controlled !== undefined, onItemsChange, still }\n  })\n\n  const commit = useCallback((next: LiveItem[]) => {\n    live.current.items = next\n    if (!live.current.controlled) setOwn(next)\n    live.current.onItemsChange?.(next)\n  }, [])\n\n  const toggle = useCallback(\n    (id: string) => {\n      const item = live.current.items.find((i) => i.id === id)\n      if (!item) return\n      const next = !item.done\n      commit(live.current.items.map((i) => (i.id === id ? { ...i, done: next } : i)))\n      setSnap((s) => (s ? { ...s, done: { ...s.done, [id]: next } } : s))\n      clearTimeout(timers.current[id])\n      if (next && !live.current.still) {\n        setSettling((s) => ({ ...s, [id]: true }))\n        timers.current[id] = setTimeout(() => setSettling((s) => ({ ...s, [id]: false })), SETTLE)\n      } else setSettling((s) => ({ ...s, [id]: false }))\n    },\n    [commit],\n  )\n\n  const freshest = Math.max(0, ...items.map((i) => i.at ?? 0))\n  useEffect(() => {\n    if (!freshest) return\n    const t = setTimeout(() => setNow(Date.now()), Math.max(0, freshest + FRESH - Date.now()) + 20)\n    return () => clearTimeout(t)\n  }, [freshest])\n  useEffect(() => {\n    const t = timers.current\n    return () => Object.values(t).forEach(clearTimeout)\n  }, [])\n\n  const hold = () => setSnap((s) => s ?? take(live.current.items))\n  const flush = (keep: boolean) => {\n    if (!snap) return\n    const ids = live.current.items.filter((i) => !snap.done.hasOwnProperty(i.id)).map((i) => i.id)\n    if (ids.length) {\n      setLanded(Object.fromEntries(ids.map((id) => [id, true])))\n      clearTimeout(timers.current.__landed)\n      timers.current.__landed = setTimeout(() => setLanded({}), FRESH)\n    }\n    setSnap(keep ? take(live.current.items) : null)\n  }\n  const release = () => {\n    if (!inside.current.hover && !inside.current.focus) flush(false)\n  }\n\n  const who = useMemo(() => Object.fromEntries(people.map((p) => [p.id, p])), [people])\n  const total = items.length\n  const finished = items.filter((i) => i.done).length\n  const byId = new Map(items.map((i) => [i.id, i]))\n  const seen = snap ? snap.order.map((id) => byId.get(id) ?? snap.keep[id]) : items\n  const waiting = snap ? items.filter((i) => !snap.done.hasOwnProperty(i.id)) : []\n  const placed = (i: LiveItem) => (snap ? snap.done[i.id] : !!i.done)\n  const done = seen.filter((i) => placed(i) && !settling[i.id])\n  const isFresh = (i: LiveItem) => !!landed[i.id] || (!snap && i.at !== undefined && now - i.at < FRESH)\n  const waitingBy = [...new Set(waiting.map((i) => i.by))].map((id) => who[id]).filter(Boolean)\n\n  const add = (e: FormEvent) => {\n    e.preventDefault()\n    const tag = draft.match(/#(\\w+)/)?.[1]?.toLowerCase()\n    const group = groups.find((g) => tag && (g.id === tag || g.label.toLowerCase().startsWith(tag)))?.id ?? groups[0]?.id\n    const text = draft.replace(/#\\w+/, '').replace(/\\s+/g, ' ').trim()\n    if (!text || !group) return\n    const item = { id: `${Date.now()}`, title: text, group, by: me, at: Date.now() }\n    setSnap((s) => (s ? { order: [...s.order, item.id], done: { ...s.done, [item.id]: false }, keep: { ...s.keep, [item.id]: item } } : s))\n    commit([...items, item])\n    setDraft('')\n    setShut((s) => ({ ...s, [group]: false }))\n  }\n\n  const hint = draft.match(/(?:^|\\s)#(\\w*)$/)?.[1]?.toLowerCase()\n  const match = hint !== undefined ? groups.filter((g) => g.label.toLowerCase().startsWith(hint) || g.id.startsWith(hint)) : []\n  const pick = (g: LiveGroup) => setDraft((d) => d.replace(/#\\w*$/, `#${g.id} `))\n  const tab = (e: KeyboardEvent<HTMLInputElement>) => {\n    if ((e.key === 'Tab' || e.key === 'Enter') && match.length && hint !== match[0].id) {\n      e.preventDefault()\n      pick(match[0])\n    }\n  }\n\n  const avatars = people.slice(0, 4)\n  const typed = draft.trim().length > 0\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <div className=\"flex w-full max-w-[400px] flex-col rounded-[22px] bg-[var(--tray)] p-1.5 shadow-[0_0_0_1px_light-dark(rgb(0_0_0/.06),rgb(255_255_255/.06))] [--tray:light-dark(#f4f4f5,#1c1c1f)]\">\n        <div className=\"flex h-[46px] items-center justify-between gap-3 pl-3 pr-2\">\n          <div className=\"min-w-0\">\n            <h3 className=\"truncate text-[13px] font-medium leading-tight text-ink\">{title}</h3>\n            <p className=\"mt-1 flex items-center gap-1.5 text-[12px] leading-none text-ink-3\">\n              <Pie part={total ? finished / total : 0} still={still} />\n              <span className=\"flex items-center whitespace-nowrap\">\n                <RollingText text={`${finished}`} proportional still={still} />\n                <span className=\"ml-[0.28em]\">of {total} done</span>\n              </span>\n            </p>\n          </div>\n          <div className=\"flex shrink-0 items-center -space-x-[3px]\" role=\"img\" aria-label={`${people.length} people on this list`}>\n            {avatars.map((p) => (\n              <Face key={p.id} person={p} size={22} ring />\n            ))}\n            {people.length > avatars.length && <span className=\"grid size-[22px] place-items-center rounded-full bg-[light-dark(#e4e4e7,#2e2e33)] text-[9.5px] font-medium text-ink-2 shadow-[0_0_0_2px_var(--tray)]\">+{people.length - avatars.length}</span>}\n          </div>\n        </div>\n\n        <div\n          onPointerEnter={(e) => {\n            if (e.pointerType !== 'mouse') return\n            inside.current.hover = true\n            hold()\n          }}\n          onPointerLeave={(e) => {\n            if (e.pointerType !== 'mouse') return\n            inside.current.hover = false\n            release()\n          }}\n          onPointerDown={(e) => {\n            if (e.pointerType === 'mouse') return\n            hold()\n            clearTimeout(timers.current.__idle)\n            timers.current.__idle = setTimeout(() => {\n              if (!inside.current.focus) setSnap(null)\n            }, IDLE)\n          }}\n          onFocus={(e) => {\n            if (e.target.tagName !== 'INPUT' && !e.target.matches(':focus-visible')) return\n            inside.current.focus = true\n            hold()\n          }}\n          onBlur={(e) => {\n            if (e.currentTarget.contains(e.relatedTarget as Node)) return\n            inside.current.focus = false\n            release()\n          }}\n          className=\"relative flex flex-col overflow-hidden rounded-[16px] bg-surface shadow-[0_0_0_0.5px_light-dark(rgb(0_0_0/.09),rgb(255_255_255/.08)),0_1px_2px_rgb(0_0_0/.04),0_8px_24px_-12px_rgb(0_0_0/.12)]\">\n          <div className=\"overflow-y-auto overscroll-contain px-1.5 py-1 [mask-image:linear-gradient(to_bottom,transparent,#000_8px,#000_calc(100%-14px),transparent)] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\" style={{ height }}>\n            {groups.map((g) => {\n              const rows = seen.filter((i) => i.group === g.id && (!placed(i) || settling[i.id]))\n              const closed = !!shut[g.id]\n              return (\n                <section key={g.id} className=\"pt-1\">\n                  <Header label={g.label} hue={g.hue} count={rows.filter((i) => !i.done).length} closed={closed} still={still} onToggle={() => setShut((s) => ({ ...s, [g.id]: !closed }))} />\n                  <Fold open={!closed} still={still}>\n                    <AnimatePresence initial={false}>\n                      {rows.map((item) => (\n                        <Grow key={item.id} still={still}>\n                          <Row item={item} by={who[item.by]} still={still} onToggle={toggle} fresh={isFresh(item)} />\n                        </Grow>\n                      ))}\n                      {!rows.length && (\n                        <Grow key=\"__empty\" still={still}>\n                          <p className=\"flex h-full items-center px-2.5 text-[12.5px] text-ink-3\">All clear</p>\n                        </Grow>\n                      )}\n                    </AnimatePresence>\n                  </Fold>\n                </section>\n              )\n            })}\n\n            <section className={`mt-1 border-t pt-1 ${HAIR}`}>\n              <Header label=\"Done\" count={done.length} closed={!!shut.__done} still={still} onToggle={() => setShut((s) => ({ ...s, __done: !s.__done }))} quiet />\n              <Fold open={!shut.__done} still={still}>\n                <AnimatePresence initial={false}>\n                  {done.map((item) => (\n                    <Grow key={item.id} still={still}>\n                      <Row item={item} by={who[item.by]} still={still} onToggle={toggle} fresh={false} />\n                    </Grow>\n                  ))}\n                </AnimatePresence>\n              </Fold>\n            </section>\n          </div>\n\n          <AnimatePresence>\n            {waiting.length > 0 && (\n              <motion.button\n                type=\"button\"\n                aria-label={`Show ${waiting.length} new`}\n                onClick={() => flush(true)}\n                initial={{ opacity: 0, y: -6, scale: 0.96 }}\n                animate={{ opacity: 1, y: 0, scale: 1 }}\n                exit={{ opacity: 0, y: -6, scale: 0.96, transition: { duration: still ? 0 : 0.14 } }}\n                transition={{ duration: still ? 0 : 0.2, ease: EASE }}\n                whileTap={{ scale: 0.96 }}\n                className=\"ring-focus absolute left-1/2 top-2 z-10 flex h-7 -translate-x-1/2 items-center gap-1.5 rounded-full bg-ink pl-1 pr-2.5 text-[12px] font-medium text-surface shadow-[0_6px_16px_-6px_rgb(0_0_0/.35)]\"\n              >\n                <span className=\"flex -space-x-[4px]\">\n                  {waitingBy.slice(0, 3).map((p) => (\n                    <span key={p.id} className=\"rounded-full shadow-[0_0_0_1.5px_var(--ink)]\">\n                      <Face person={p} size={20} />\n                    </span>\n                  ))}\n                </span>\n                <span className=\"flex items-center whitespace-nowrap\">\n                  <RollingText text={`${waiting.length}`} proportional still={still} />\n                  <span className=\"ml-[0.28em]\">new</span>\n                </span>\n              </motion.button>\n            )}\n          </AnimatePresence>\n\n          <form onSubmit={add} className={`relative border-t ${HAIR}`}>\n            <div className=\"flex h-[46px] items-center gap-2.5 px-4\">\n              <span aria-hidden className=\"grid size-[17px] shrink-0 place-items-center text-ink-3\">\n                <svg viewBox=\"0 0 12 12\" className=\"size-3\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\">\n                  <path d=\"M6 2v8M2 6h8\" />\n                </svg>\n              </span>\n              <input\n                value={draft}\n                onChange={(e) => setDraft(e.target.value)}\n                onKeyDown={tab}\n                aria-label=\"Add an item\"\n                enterKeyHint=\"done\"\n                placeholder=\"Add an item, # for a group\"\n                className=\"min-w-0 flex-1 bg-transparent text-[13px] text-ink outline-none placeholder:text-ink-3 max-sm:text-[16px]\"\n              />\n              <motion.button\n                type=\"submit\"\n                tabIndex={typed ? 0 : -1}\n                aria-hidden={!typed}\n                initial={false}\n                animate={{ opacity: typed ? 1 : 0, scale: typed ? 1 : 0.9 }}\n                transition={{ duration: still ? 0 : 0.15 }}\n                whileTap={{ scale: 0.95 }}\n                className={`ring-focus shrink-0 rounded-[7px] bg-ink px-2 py-1 text-[11.5px] font-medium text-surface ${typed ? '' : 'pointer-events-none'}`}\n              >\n                Add\n              </motion.button>\n            </div>\n            <AnimatePresence>\n              {match.length > 0 && (\n                <motion.div role=\"listbox\" aria-label=\"Groups\" initial={{ opacity: 0, y: 4 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, y: 4, transition: { duration: 0.1 } }} className=\"absolute bottom-[calc(100%-6px)] left-10 z-10 flex max-w-[calc(100%-3rem)] gap-1 overflow-x-auto rounded-[10px] bg-surface p-1 shadow-[0_0_0_0.5px_light-dark(rgb(0_0_0/.12),rgb(255_255_255/.12)),0_8px_24px_-8px_rgb(0_0_0/.25)] [scrollbar-width:none]\">\n                  {match.map((g, k) => (\n                    <button key={g.id} type=\"button\" role=\"option\" aria-selected={k === 0} onMouseDown={(e) => e.preventDefault()} onClick={() => pick(g)} className={`flex shrink-0 items-center gap-1.5 whitespace-nowrap rounded-[7px] px-2 py-1 text-[12px] ${k === 0 ? 'bg-[light-dark(rgb(0_0_0/.05),rgb(255_255_255/.08))] text-ink' : 'text-ink-2'}`}>\n                      <span className=\"size-2 rounded-[2.5px]\" style={{ background: `oklch(0.72 0.13 ${g.hue})` }} />\n                      {g.label}\n                      {k === 0 && <kbd className=\"ml-1 font-sans text-[10.5px] text-ink-3 max-sm:hidden\">Tab</kbd>}\n                    </button>\n                  ))}\n                </motion.div>\n              )}\n            </AnimatePresence>\n          </form>\n        </div>\n      </div>\n    </MotionConfig>\n  )\n}\n\nfunction Grow({ still, children }: { still: boolean; children: ReactNode }) {\n  return (\n    <motion.div initial={{ height: 0, opacity: 0 }} animate={{ height: ROW, opacity: 1 }} exit={{ height: 0, opacity: 0 }} transition={still ? { duration: 0 } : GROW} className=\"overflow-hidden\">\n      {children}\n    </motion.div>\n  )\n}\n\nfunction Fold({ open, still, children }: { open: boolean; still: boolean; children: ReactNode }) {\n  return (\n    <motion.div initial={false} animate={{ height: open ? 'auto' : 0, opacity: open ? 1 : 0 }} transition={still ? { duration: 0 } : GROW} className=\"overflow-hidden\" inert={!open}>\n      {children}\n    </motion.div>\n  )\n}\n\nfunction Header({ label, hue, count, closed, still, onToggle, quiet = false }: { label: string; hue?: number; count: number; closed: boolean; still: boolean; onToggle: () => void; quiet?: boolean }) {\n  return (\n    <button type=\"button\" aria-expanded={!closed} aria-label={`${label}, ${count}`} onClick={onToggle} className=\"ring-focus group flex h-8 w-full items-center gap-2 rounded-[8px] px-2.5 text-left\">\n      {hue !== undefined && <span aria-hidden className=\"size-2 shrink-0 rounded-[2.5px]\" style={{ background: `oklch(0.72 0.13 ${hue})` }} />}\n      <span className={`text-[12px] font-medium leading-none ${quiet ? 'text-ink-3' : 'text-ink-2'}`}>{label}</span>\n      <span className=\"flex items-center text-[12px] leading-none tabular-nums text-ink-3\">\n        <RollingText text={`${count}`} still={still} />\n      </span>\n      <span className=\"flex-1\" />\n      <motion.svg aria-hidden viewBox=\"0 0 12 12\" className=\"size-3 text-ink-3 opacity-0 transition-opacity ease-detent duration-150 group-hover:opacity-100 group-focus-visible:opacity-100 [@media(hover:none)]:opacity-100\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" initial={false} animate={{ rotate: closed ? -90 : 0 }} transition={still ? { duration: 0 } : GROW}>\n        <path d=\"m3 4.5 3 3 3-3\" />\n      </motion.svg>\n    </button>\n  )\n}\n\nconst Row = memo(function Row({ item, by, still, onToggle, fresh }: { item: LiveItem; by?: LivePerson; still: boolean; onToggle: (id: string) => void; fresh: boolean }) {\n  const done = !!item.done\n  const tint = by ? `light-dark(oklch(0.965 0.035 ${by.hue}), oklch(0.3 0.045 ${by.hue}))` : 'transparent'\n  const edge = by ? `inset 0 0 0 1px light-dark(oklch(0.9 0.06 ${by.hue}), oklch(0.42 0.06 ${by.hue}))` : 'none'\n  return (\n    <div className=\"group relative flex items-center gap-2.5 rounded-[9px] px-2.5 transition-colors ease-detent duration-150 hover:bg-[light-dark(rgb(0_0_0/.03),rgb(255_255_255/.04))]\" style={{ height: ROW }}>\n      <motion.span aria-hidden className=\"pointer-events-none absolute inset-0 rounded-[9px]\" initial={false} animate={{ opacity: fresh ? 1 : 0 }} transition={{ duration: still ? 0 : fresh ? 0.2 : 0.6 }} style={{ background: tint, boxShadow: edge }} />\n      <button type=\"button\" role=\"checkbox\" aria-checked={done} aria-label={item.title} onClick={() => onToggle(item.id)} className=\"ring-focus group/box relative -m-1.5 grid shrink-0 place-items-center rounded-[7px] p-1.5\">\n        <Box done={done} still={still} />\n      </button>\n      <span className=\"relative min-w-0 flex-1 truncate text-[13px]\">\n        <span className={`transition-colors ease-detent duration-200 ${done ? 'text-ink-3' : 'text-ink'}`}>{item.title}</span>\n        <motion.span aria-hidden className=\"absolute left-0 top-1/2 h-px w-full origin-left bg-ink-3\" initial={false} animate={{ scaleX: done ? 1 : 0 }} transition={still ? { duration: 0 } : { duration: 0.28, ease: EASE }} />\n      </span>\n      {by && (\n        <motion.span aria-hidden={!fresh} initial={false} animate={{ opacity: fresh ? 1 : 0, x: fresh ? 0 : 4 }} transition={{ duration: still ? 0 : 0.2 }} className=\"pointer-events-none absolute right-[38px] top-[8px] whitespace-nowrap leading-[16px] rounded-[6px] py-0.5 pl-3 text-[11.5px] text-ink-2 max-[360px]:hidden\" style={{ background: `linear-gradient(to right, transparent, ${tint} 12px)` }}>\n          {by.name.split(' ')[0]} · just now\n        </motion.span>\n      )}\n      <span className=\"relative\">\n        <Face person={by} />\n      </span>\n    </div>\n  )\n})\n"},{"path":"components/detent/ui/RollingText.tsx","target":"components/detent/ui/RollingText.tsx","type":"registry:component","content":"'use client'\n\nimport { useLayoutEffect, useRef, useState } from 'react'\nimport { animate, motion, useMotionValue } from 'motion/react'\n\nconst roll = { type: 'spring', stiffness: 380, damping: 34, mass: 0.8 } as const\n\nexport function RollingText({ text, className = '', proportional = false, still = false }: { text: string; className?: string; proportional?: boolean; still?: boolean }) {\n  const chars = [...text]\n  const probe = useRef<HTMLSpanElement>(null)\n  const [widths, setWidths] = useState<number[] | null>(null)\n\n  useLayoutEffect(() => {\n    if (!proportional || !probe.current) return\n    const read = () => {\n      const box = probe.current!\n      const z = box.offsetWidth ? box.getBoundingClientRect().width / box.offsetWidth : 1\n      const em = parseFloat(getComputedStyle(box).fontSize) || 16\n      setWidths([...box.children].map((c) => (c as HTMLElement).getBoundingClientRect().width / z / em))\n    }\n    read()\n    document.fonts?.ready.then(read)\n  }, [proportional])\n\n  return (\n    <span className={`relative inline-flex ${proportional ? '' : 'tnum'} ${className}`} style={{ lineHeight: '1.25em', height: '1.25em' }}>\n      <span className=\"sr-only\">{text}</span>\n      {proportional && (\n        <span aria-hidden className=\"pointer-events-none absolute left-0 top-0 size-0 overflow-hidden\">\n          <span ref={probe} className=\"invisible flex w-max whitespace-pre\">\n            {Array.from({ length: 10 }, (_, n) => (\n              <span key={n}>{n}</span>\n            ))}\n          </span>\n        </span>\n      )}\n      {chars.map((c, i) => {\n        const key = chars.length - i\n        return /\\d/.test(c) ? (\n          <Digit key={key} d={+c} width={proportional && widths ? widths[+c] : undefined} still={still} />\n        ) : (\n          <span key={`${key}${c}`} aria-hidden className=\"whitespace-pre\">\n            {c}\n          </span>\n        )\n      })}\n    </span>\n  )\n}\n\nfunction Digit({ d, width, still }: { d: number; width?: number; still: boolean }) {\n  const w = useMotionValue<string>(width === undefined ? '1ch' : `${width}em`)\n  const had = useRef(width !== undefined)\n  useLayoutEffect(() => {\n    if (width === undefined) return\n    if (!had.current) {\n      had.current = true\n      w.set(`${width}em`)\n      return\n    }\n    const ctl = animate(w, `${width}em`, roll)\n    return () => ctl.stop()\n  }, [width, w])\n\n  return (\n    <motion.span aria-hidden className=\"relative inline-block overflow-hidden\" style={{ height: '1.25em', width: w }}>\n      <motion.span className=\"absolute inset-x-0 top-0 flex flex-col items-center\" initial={false} animate={{ y: `${-d * 10}%` }} transition={still ? { duration: 0 } : roll}>\n        {Array.from({ length: 10 }, (_, n) => (\n          <span key={n} className=\"block\" style={{ height: '1.25em' }}>\n            {n}\n          </span>\n        ))}\n      </motion.span>\n    </motion.span>\n  )\n}\n"}]}