{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "list-todo-animated",
  "type": "registry:component",
  "title": "Animated Todo List",
  "description": "A task list with an add field, a check mark that draws itself, a strike-through that sweeps across the text, collapsing delete and up and down reordering that glides into place.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "components",
    "todo",
    "list",
    "checkbox",
    "reorder",
    "tasks",
    "animation"
  ],
  "docs": "https://hyperblur.dev/effects/list-todo-animated",
  "files": [
    {
      "path": "registry/hyperblur/list-todo-animated.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/list-todo-animated.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface TodoItem {\n  id: string;\n  text: string;\n  done?: boolean;\n}\n\nexport interface ListTodoAnimatedProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\"> {\n  items?: TodoItem[];\n  defaultItems?: TodoItem[];\n  onChange?: (items: TodoItem[]) => void;\n  placeholder?: string;\n  maxHeight?: number;\n  autoDemo?: number;\n  accent?: string;\n}\n\nconst seed: TodoItem[] = [\n  { id: \"d1\", text: \"Review the pricing page copy\" },\n  { id: \"d2\", text: \"Send invoice to Northwind\", done: true },\n  { id: \"d3\", text: \"Book flights for the offsite\" },\n];\n\nconst css = `\n.hb-za6 {\n  --hb-za6-c: #2f7bff;\n  box-sizing: border-box;\n  width: 100%;\n  font-family: inherit;\n  color: #ededed;\n}\n.hb-za6 *, .hb-za6 *::before, .hb-za6 *::after { box-sizing: border-box; }\n.hb-za6-add {\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  height: 36px;\n  padding: 0 4px 0 12px;\n  background: #111111;\n  border: 1px solid #2a2a2a;\n  border-radius: 10px;\n  transition: border-color 0.2s ease, box-shadow 0.2s ease;\n}\n.hb-za6-add:focus-within { border-color: var(--hb-za6-c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--hb-za6-c) 22%, transparent); }\n.hb-za6-input {\n  flex: 1 1 auto;\n  min-width: 0;\n  height: 100%;\n  padding: 0;\n  font: inherit;\n  font-size: 13px;\n  color: #ededed;\n  background: transparent;\n  border: 0;\n  outline: none;\n}\n.hb-za6-input::placeholder { color: #6f6f6f; }\n.hb-za6-go {\n  display: grid;\n  flex: 0 0 auto;\n  place-items: center;\n  width: 28px;\n  height: 28px;\n  margin: 0;\n  padding: 0;\n  color: #0a0a0a;\n  background: #ededed;\n  border: 0;\n  border-radius: 8px;\n  cursor: pointer;\n  transition: transform 0.2s ease, opacity 0.2s ease, background 0.2s ease;\n}\n.hb-za6-go:hover { background: #ffffff; }\n.hb-za6-go:active { transform: scale(0.92); }\n.hb-za6-go:disabled { opacity: 0.35; cursor: default; }\n.hb-za6-go:focus-visible { outline: 2px solid var(--hb-za6-c); outline-offset: 2px; }\n.hb-za6-go svg { width: 14px; height: 14px; }\n.hb-za6-list {\n  position: relative;\n  margin: 8px 0 0;\n  padding: 0;\n  list-style: none;\n  overflow-y: auto;\n  overscroll-behavior: contain;\n  scrollbar-width: thin;\n  scrollbar-color: #333333 transparent;\n}\n.hb-za6-item {\n  position: relative;\n  z-index: 1;\n  display: grid;\n  grid-template-rows: 1fr;\n  border-radius: 8px;\n  transition: grid-template-rows 0.34s cubic-bezier(0.22, 0.9, 0.24, 1), opacity 0.28s ease;\n  animation: hb-za6-in 0.38s cubic-bezier(0.22, 0.9, 0.24, 1) backwards;\n}\n.hb-za6-item[data-leaving=\"true\"] { grid-template-rows: 0fr; opacity: 0; pointer-events: none; }\n.hb-za6-inner { min-height: 0; overflow: hidden; }\n.hb-za6-row {\n  display: flex;\n  align-items: center;\n  gap: 10px;\n  height: 36px;\n  padding: 0 4px 0 6px;\n  border-radius: 8px;\n  transition: background 0.2s ease;\n}\n.hb-za6-row:hover, .hb-za6-row:focus-within { background: rgba(255, 255, 255, 0.04); }\n.hb-za6-check {\n  position: relative;\n  display: grid;\n  flex: 0 0 auto;\n  place-items: center;\n  width: 20px;\n  height: 20px;\n  margin: 0;\n  padding: 0;\n  color: #0a0a0a;\n  background: transparent;\n  border: 1.5px solid #4a4a4a;\n  border-radius: 6px;\n  cursor: pointer;\n  transition: background 0.25s ease, border-color 0.25s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);\n}\n.hb-za6-check:hover { border-color: #7a7a7a; }\n.hb-za6-check:active { transform: scale(0.88); }\n.hb-za6-check:focus-visible { outline: 2px solid var(--hb-za6-c); outline-offset: 2px; }\n.hb-za6-check[aria-checked=\"true\"] { background: var(--hb-za6-c); border-color: var(--hb-za6-c); }\n.hb-za6-check svg { width: 12px; height: 12px; overflow: visible; }\n.hb-za6-check path {\n  fill: none;\n  stroke: #ffffff;\n  stroke-width: 2.2;\n  stroke-linecap: round;\n  stroke-linejoin: round;\n  stroke-dasharray: 16;\n  stroke-dashoffset: 16;\n  transition: stroke-dashoffset 0.3s cubic-bezier(0.5, 0, 0.2, 1);\n}\n.hb-za6-check[aria-checked=\"true\"] path { stroke-dashoffset: 0; transition-delay: 0.08s; }\n.hb-za6-label { flex: 1 1 auto; min-width: 0; font-size: 13px; line-height: 1.2; }\n.hb-za6-text {\n  position: relative;\n  display: inline-block;\n  max-width: 100%;\n  overflow: hidden;\n  vertical-align: middle;\n  white-space: nowrap;\n  text-overflow: ellipsis;\n  color: #ededed;\n  transition: color 0.3s ease;\n}\n.hb-za6-text::after {\n  content: \"\";\n  position: absolute;\n  left: 0;\n  top: 52%;\n  width: 100%;\n  height: 1.5px;\n  background: #8f8f8f;\n  transform: scaleX(0);\n  transform-origin: left center;\n  transition: transform 0.34s cubic-bezier(0.5, 0, 0.2, 1);\n}\n.hb-za6-row[data-done=\"true\"] .hb-za6-text { color: #6f6f6f; }\n.hb-za6-row[data-done=\"true\"] .hb-za6-text::after { transform: scaleX(1); }\n.hb-za6-tools { display: flex; flex: 0 0 auto; align-items: center; gap: 1px; opacity: 0.45; transition: opacity 0.2s ease; }\n.hb-za6-row:hover .hb-za6-tools, .hb-za6-row:focus-within .hb-za6-tools { opacity: 1; }\n.hb-za6-tool {\n  display: grid;\n  place-items: center;\n  width: 24px;\n  height: 24px;\n  margin: 0;\n  padding: 0;\n  color: #9a9a9a;\n  background: transparent;\n  border: 0;\n  border-radius: 7px;\n  cursor: pointer;\n  transition: background 0.2s ease, color 0.2s ease, opacity 0.2s ease;\n}\n.hb-za6-tool:hover:not(:disabled) { background: #262626; color: #ededed; }\n.hb-za6-tool[data-kind=\"delete\"]:hover:not(:disabled) { color: #ff6b6b; }\n.hb-za6-tool:focus-visible { outline: 2px solid var(--hb-za6-c); outline-offset: 1px; }\n.hb-za6-tool:disabled { opacity: 0.25; cursor: default; }\n.hb-za6-tool svg { width: 13px; height: 13px; }\n.hb-za6-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; padding: 0 2px; font-size: 12px; color: #8f8f8f; }\n.hb-za6-left { display: inline-flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }\n.hb-za6-left b { display: inline-block; font-weight: 600; color: #ededed; animation: hb-za6-tick 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }\n.hb-za6-meter { width: 44px; height: 3px; overflow: hidden; background: #262626; border-radius: 999px; }\n.hb-za6-meter span { display: block; height: 100%; background: var(--hb-za6-c); border-radius: inherit; transform-origin: left center; transform: scaleX(var(--hb-za6-p, 0)); transition: transform 0.4s cubic-bezier(0.22, 0.9, 0.24, 1); }\n.hb-za6-clear {\n  margin: 0;\n  padding: 2px 6px;\n  font: inherit;\n  font-size: 12px;\n  color: #a1a1a1;\n  background: transparent;\n  border: 0;\n  border-radius: 6px;\n  cursor: pointer;\n  transition: color 0.2s ease, background 0.2s ease;\n}\n.hb-za6-clear:hover { color: #ededed; background: #1c1c1c; }\n.hb-za6-clear:focus-visible { outline: 2px solid var(--hb-za6-c); outline-offset: 1px; }\n.hb-za6-empty { padding: 14px 0; font-size: 12px; text-align: center; color: #6f6f6f; }\n@keyframes hb-za6-in {\n  from { grid-template-rows: 0fr; opacity: 0; }\n  to { grid-template-rows: 1fr; opacity: 1; }\n}\n@keyframes hb-za6-tick {\n  from { opacity: 0; transform: translateY(-6px) scale(0.8); }\n  to { opacity: 1; transform: none; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-za6-item, .hb-za6-check, .hb-za6-check path, .hb-za6-text::after, .hb-za6-meter span { transition: none; animation: none; }\n  .hb-za6-left b { animation: none; }\n}\n`;\n\nexport function ListTodoAnimated({\n  items,\n  defaultItems,\n  onChange,\n  placeholder = \"Add a task and press Enter\",\n  maxHeight,\n  autoDemo = 0,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  onPointerEnter,\n  onPointerLeave,\n  onFocus,\n  onBlur,\n  ...rest\n}: ListTodoAnimatedProps) {\n  const controlled = items !== undefined;\n  const [inner, setInner] = React.useState<TodoItem[]>(defaultItems ?? seed);\n  const list = controlled ? items : inner;\n  const [draft, setDraft] = React.useState(\"\");\n  const [leaving, setLeaving] = React.useState<Record<string, true>>({});\n  const [busy, setBusy] = React.useState(false);\n  const els = React.useRef(new Map<string, HTMLLIElement>());\n  const before = React.useRef<{ tops: Map<string, number>; id: string; kind: \"up\" | \"down\" } | null>(null);\n  const counter = React.useRef(0);\n  const timers = React.useRef<number[]>([]);\n  const latest = React.useRef({ list, onChange, controlled });\n  const inputId = React.useId();\n\n  React.useEffect(() => {\n    latest.current = { list, onChange, controlled };\n  }, [list, onChange, controlled]);\n\n  React.useEffect(() => {\n    const ids = timers.current;\n    return () => ids.forEach((t) => window.clearTimeout(t));\n  }, []);\n\n  const commit = React.useCallback((next: TodoItem[]) => {\n    latest.current.list = next;\n    if (!latest.current.controlled) setInner(next);\n    latest.current.onChange?.(next);\n  }, []);\n\n  React.useLayoutEffect(() => {\n    const snap = before.current;\n    if (!snap) return;\n    before.current = null;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    els.current.forEach((el, id) => {\n      const from = snap.tops.get(id);\n      if (from === undefined || reduce) return;\n      const delta = from - el.getBoundingClientRect().top;\n      if (Math.abs(delta) < 1) return;\n      const moved = id === snap.id;\n      el.animate(\n        [\n          {\n            transform: `translateY(${delta.toFixed(2)}px) scale(${moved ? 1.02 : 1})`,\n            zIndex: moved ? 3 : 1,\n            background: moved ? \"#1d1d1d\" : \"transparent\",\n          },\n          { transform: \"translateY(0) scale(1)\", zIndex: moved ? 3 : 1, background: \"transparent\" },\n        ],\n        { duration: 420, easing: \"cubic-bezier(0.22, 0.9, 0.24, 1)\" },\n      );\n    });\n    const el = els.current.get(snap.id);\n    if (el) {\n      const first = el.querySelector<HTMLButtonElement>(`[data-move=\"${snap.kind}\"]`);\n      const other = el.querySelector<HTMLButtonElement>(`[data-move=\"${snap.kind === \"up\" ? \"down\" : \"up\"}\"]`);\n      (first && !first.disabled ? first : other)?.focus({ preventScroll: true });\n    }\n  }, [list]);\n\n  const live = list.filter((t) => !leaving[t.id]);\n  const left = live.filter((t) => !t.done).length;\n  const doneCount = live.length - left;\n\n  function add() {\n    const text = draft.trim();\n    if (!text) return;\n    counter.current += 1;\n    commit([{ id: `n${counter.current}-${list.length}`, text, done: false }, ...latest.current.list]);\n    setDraft(\"\");\n  }\n\n  function toggle(id: string) {\n    commit(latest.current.list.map((t) => (t.id === id ? { ...t, done: !t.done } : t)));\n  }\n\n  function removeMany(ids: string[]) {\n    if (!ids.length) return;\n    setLeaving((prev) => {\n      const copy = { ...prev };\n      ids.forEach((id) => {\n        copy[id] = true;\n      });\n      return copy;\n    });\n    const t = window.setTimeout(() => {\n      commit(latest.current.list.filter((x) => !ids.includes(x.id)));\n      setLeaving((prev) => {\n        const copy = { ...prev };\n        ids.forEach((id) => {\n          delete copy[id];\n        });\n        return copy;\n      });\n    }, 360);\n    timers.current.push(t);\n  }\n\n  function move(id: string, dir: -1 | 1) {\n    const cur = latest.current.list;\n    const i = cur.findIndex((t) => t.id === id);\n    const j = i + dir;\n    if (i < 0 || j < 0 || j >= cur.length) return;\n    const tops = new Map<string, number>();\n    els.current.forEach((el, key) => tops.set(key, el.getBoundingClientRect().top));\n    before.current = { tops, id, kind: dir < 0 ? \"up\" : \"down\" };\n    const next = cur.slice();\n    [next[i], next[j]] = [next[j], next[i]];\n    commit(next);\n  }\n\n  function clearDone() {\n    removeMany(latest.current.list.filter((t) => t.done && !leaving[t.id]).map((t) => t.id));\n  }\n\n  React.useEffect(() => {\n    if (!autoDemo || busy) return;\n    const id = window.setInterval(() => {\n      const cur = latest.current.list;\n      if (!cur.length) return;\n      const open = cur.filter((t) => !t.done);\n      const target = open.length ? open[0] : cur[cur.length - 1];\n      commit(cur.map((t) => (t.id === target.id ? { ...t, done: !t.done } : t)));\n    }, autoDemo);\n    return () => window.clearInterval(id);\n  }, [autoDemo, busy, commit]);\n\n  const vars = {\n    \"--hb-za6-c\": accent,\n    \"--hb-za6-p\": live.length ? (doneCount / live.length).toFixed(4) : \"0\",\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <div\n      className={`hb-za6 ${className}`}\n      style={vars}\n      onPointerEnter={(e) => {\n        onPointerEnter?.(e);\n        setBusy(true);\n      }}\n      onPointerLeave={(e) => {\n        onPointerLeave?.(e);\n        setBusy(false);\n      }}\n      onFocus={(e) => {\n        onFocus?.(e);\n        setBusy(true);\n      }}\n      onBlur={(e) => {\n        onBlur?.(e);\n        setBusy(false);\n      }}\n      {...rest}\n    >\n      <style href=\"hb-list-todo-animated\" precedence=\"default\">{css}</style>\n      <div className=\"hb-za6-add\">\n        <input\n          id={inputId}\n          className=\"hb-za6-input\"\n          value={draft}\n          placeholder={placeholder}\n          aria-label=\"New task\"\n          autoComplete=\"off\"\n          onChange={(e) => setDraft(e.target.value)}\n          onKeyDown={(e) => {\n            if (e.key === \"Enter\" && !e.nativeEvent.isComposing) {\n              e.preventDefault();\n              add();\n            }\n          }}\n        />\n        <button type=\"button\" className=\"hb-za6-go\" aria-label=\"Add task\" disabled={!draft.trim()} onClick={add}>\n          <svg viewBox=\"0 0 14 14\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n            <path d=\"M7 2.5v9M2.5 7h9\" />\n          </svg>\n        </button>\n      </div>\n      <ul className=\"hb-za6-list\" style={maxHeight ? { maxHeight } : undefined} aria-label=\"Tasks\">\n        {list.map((t, i) => {\n          const gone = Boolean(leaving[t.id]);\n          return (\n            <li\n              key={t.id}\n              ref={(el) => {\n                if (el) els.current.set(t.id, el);\n                else els.current.delete(t.id);\n              }}\n              className=\"hb-za6-item\"\n              data-leaving={gone}\n            >\n              <div className=\"hb-za6-inner\">\n                <div className=\"hb-za6-row\" data-done={Boolean(t.done)}>\n                  <button\n                    type=\"button\"\n                    role=\"checkbox\"\n                    aria-checked={Boolean(t.done)}\n                    aria-label={t.text}\n                    className=\"hb-za6-check\"\n                    tabIndex={gone ? -1 : 0}\n                    onClick={() => toggle(t.id)}\n                  >\n                    <svg viewBox=\"0 0 12 12\" aria-hidden=\"true\">\n                      <path d=\"m2.2 6.4 2.5 2.5 5-5.6\" />\n                    </svg>\n                  </button>\n                  <span className=\"hb-za6-label\">\n                    <span className=\"hb-za6-text\">{t.text}</span>\n                  </span>\n                  <span className=\"hb-za6-tools\">\n                    <button\n                      type=\"button\"\n                      className=\"hb-za6-tool\"\n                      data-move=\"up\"\n                      aria-label={`Move ${t.text} up`}\n                      disabled={i === 0 || gone}\n                      tabIndex={gone ? -1 : 0}\n                      onClick={() => move(t.id, -1)}\n                    >\n                      <svg viewBox=\"0 0 14 14\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                        <path d=\"m3 8.5 4-4 4 4\" />\n                      </svg>\n                    </button>\n                    <button\n                      type=\"button\"\n                      className=\"hb-za6-tool\"\n                      data-move=\"down\"\n                      aria-label={`Move ${t.text} down`}\n                      disabled={i === list.length - 1 || gone}\n                      tabIndex={gone ? -1 : 0}\n                      onClick={() => move(t.id, 1)}\n                    >\n                      <svg viewBox=\"0 0 14 14\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                        <path d=\"m3 5.5 4 4 4-4\" />\n                      </svg>\n                    </button>\n                    <button\n                      type=\"button\"\n                      className=\"hb-za6-tool\"\n                      data-kind=\"delete\"\n                      aria-label={`Delete ${t.text}`}\n                      tabIndex={gone ? -1 : 0}\n                      onClick={() => removeMany([t.id])}\n                    >\n                      <svg viewBox=\"0 0 14 14\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                        <path d=\"m3.5 3.5 7 7M10.5 3.5l-7 7\" />\n                      </svg>\n                    </button>\n                  </span>\n                </div>\n              </div>\n            </li>\n          );\n        })}\n      </ul>\n      {live.length === 0 ? <div className=\"hb-za6-empty\">Nothing left to do</div> : null}\n      <div className=\"hb-za6-foot\">\n        <span className=\"hb-za6-left\" role=\"status\" aria-live=\"polite\">\n          <b key={left}>{left}</b>\n          <span>{left === 1 ? \"task left\" : \"tasks left\"}</span>\n          <span className=\"hb-za6-meter\" aria-hidden=\"true\">\n            <span />\n          </span>\n        </span>\n        {doneCount > 0 ? (\n          <button type=\"button\" className=\"hb-za6-clear\" onClick={clearDone}>\n            Clear done\n          </button>\n        ) : (\n          <span />\n        )}\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}