{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "illustration-06",
  "title": "Task flow",
  "description": "A task whose connectors draw down to subtasks that settle a little askew, then a named cursor picks the last one up and drops it into the dashed slot.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/agent-run.json",
    "https://ui.ndekocode.dev/r/avatar.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-agent-run.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/illustration/illustration-06.tsx",
      "content": "'use client';\n\nimport { seriesColorOf, type SeriesSlot } from '@/registry/ndeko/lib/agent-run';\nimport {\n  MessageSquareTextIcon,\n  MousePointerIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Avatar } from '@/registry/ndeko/ui/avatar';\n\nimport { delayWhile } from './_parts/delay';\nimport { useSceneFrames, type SceneFrame } from './_parts/use-scene-frames';\nimport { useScenePlay } from './_parts/use-scene-play';\n\nexport type FlowTask = {\n  title: string;\n  /** The person who owns the task. Their picture is drawn from this name. */\n  owner: string;\n};\n\nexport type FlowSubtask = {\n  id: string;\n  title: string;\n  role: string;\n  assignee: string;\n  noteCount: number;\n};\n\nexport type FlowCursor = {\n  name: string;\n  series: SeriesSlot;\n};\n\ntype CardState = 'home' | 'held' | 'carried' | 'landed';\n\ntype CursorState = 'waiting' | 'near' | 'moved' | 'gone';\n\ntype Beat = {\n  isBranched: boolean;\n  hasCards: boolean;\n  card: CardState;\n  cursor: CursorState;\n};\n\ntype Pose = {\n  translate: string;\n  rotate: string;\n  scale: string;\n  transitionDuration: string;\n};\n\ntype GemStyle = React.CSSProperties & { '--gem': string };\n\nconst TASK_PX = 56;\n\nconst ROWS_TOP_PX = 68;\n\nconst ROW_PX = 48;\n\nconst ROW_PITCH_PX = 56;\n\nconst CARD_STAGGER_MS = 110;\n\n/** The branches to the subtasks start once the trunk is down, one after the other. */\nconst BRANCH_AFTER_MS = 200;\n\nconst BRANCH_STAGGER_MS = 100;\n\n/** A card never lies quite straight once it is put down. */\nconst TILTS_DEG = [-1.2, 0.9, -0.7, 1.1];\n\nconst HIDDEN_HOME: Pose = {\n  translate: '0px -6px',\n  rotate: '0deg',\n  scale: '1',\n  transitionDuration: '200ms',\n};\n\nconst REST: Beat = {\n  isBranched: true,\n  hasCards: true,\n  card: 'landed',\n  cursor: 'moved',\n};\n\nconst GONE: Beat = {\n  isBranched: false,\n  hasCards: false,\n  card: 'landed',\n  cursor: 'gone',\n};\n\nconst EMPTY: Beat = { ...GONE, card: 'home', cursor: 'waiting' };\n\nconst BRANCHED: Beat = { ...EMPTY, isBranched: true };\n\nconst SETTLED: Beat = { ...BRANCHED, hasCards: true };\n\n/** The round ends on the card in the air above its slot: the first frame, back at rest, is the drop. */\nconst BEATS: SceneFrame<Beat>[] = [\n  { state: REST, holdMs: 2800 },\n  { state: GONE, holdMs: 420 },\n  { state: EMPTY, holdMs: 260 },\n  { state: BRANCHED, holdMs: 520 },\n  { state: SETTLED, holdMs: 900 },\n  { state: { ...SETTLED, cursor: 'near' }, holdMs: 820 },\n  { state: { ...SETTLED, cursor: 'near', card: 'held' }, holdMs: 300 },\n  { state: { ...SETTLED, cursor: 'moved', card: 'carried' }, holdMs: 980 },\n];\n\nfunction rowTopOf(index: number) {\n  return ROWS_TOP_PX + index * ROW_PITCH_PX;\n}\n\nfunction rowMiddleOf(index: number) {\n  return rowTopOf(index) + ROW_PX / 2;\n}\n\nfunction branchDelayOf(index: number) {\n  return BRANCH_AFTER_MS + index * BRANCH_STAGGER_MS;\n}\n\nfunction tiltOf(index: number) {\n  return TILTS_DEG[index % TILTS_DEG.length];\n}\n\nfunction settledPoseOf(isShown: boolean, tilt: number): Pose {\n  if (isShown) {\n    return {\n      translate: '0px 0px',\n      rotate: `${tilt}deg`,\n      scale: '1',\n      transitionDuration: '320ms',\n    };\n  }\n  return HIDDEN_HOME;\n}\n\n/**\n * The pose of the card the cursor moves. Hidden at home it goes back without a transition: it returns\n * from the slot while nobody can see it.\n */\nfunction movedPoseOf(\n  card: CardState,\n  isShown: boolean,\n  tilt: number,\n  carry: string\n): Pose {\n  if (card === 'held') {\n    return {\n      translate: '0px -2px',\n      rotate: '1.5deg',\n      scale: '1.03',\n      transitionDuration: '240ms',\n    };\n  }\n  if (card === 'carried') {\n    return {\n      translate: carry,\n      rotate: '1.5deg',\n      scale: '1.03',\n      transitionDuration: '900ms',\n    };\n  }\n  if (card === 'landed') {\n    return {\n      translate: carry,\n      rotate: '-0.6deg',\n      scale: '1',\n      transitionDuration: '280ms',\n    };\n  }\n  if (isShown) {\n    return settledPoseOf(true, tilt);\n  }\n  return { ...HIDDEN_HOME, transitionDuration: '0ms' };\n}\n\nfunction cursorPoseOf(cursor: CursorState, carry: string) {\n  if (cursor === 'near') {\n    return { translate: '0px 0px', transitionDuration: '700ms' };\n  }\n  if (cursor === 'moved') {\n    return { translate: carry, transitionDuration: '900ms' };\n  }\n  if (cursor === 'gone') {\n    return { translate: carry, transitionDuration: '260ms' };\n  }\n  return { translate: '34px 40px', transitionDuration: '0ms' };\n}\n\nfunction isCursorSeen(cursor: CursorState) {\n  const isNear = cursor === 'near';\n  const hasMoved = cursor === 'moved';\n  return isNear || hasMoved;\n}\n\nfunction isLifted(card: CardState) {\n  const isHeld = card === 'held';\n  const isCarried = card === 'carried';\n  return isHeld || isCarried;\n}\n\nfunction isStillInList(card: CardState) {\n  const isHome = card === 'home';\n  const isHeld = card === 'held';\n  return isHome || isHeld;\n}\n\n/** How far the last card travels to its slot: half the stage across, and up to the row its slot is on. */\nfunction carryOf(lastIndex: number, slotIndex: number) {\n  const rowsUp = lastIndex - slotIndex;\n  const up = rowsUp * ROW_PITCH_PX;\n  return `calc(50cqw + 2px) -${up}px`;\n}\n\nfunction subtaskCountOf(count: number) {\n  if (count === 1) {\n    return '1 subtask';\n  }\n  return `${count} subtasks`;\n}\n\nfunction labelOf(task: FlowTask, subtasks: FlowSubtask[], cursor: FlowCursor) {\n  const titles = subtasks.map((subtask) => subtask.title);\n  const moved = titles.at(-1);\n  if (moved === undefined) {\n    return task.title;\n  }\n  const list = titles.join(', ');\n  return `${task.title} branches into ${list}. ${cursor.name} moves ${moved} to the next slot`;\n}\n\nconst CARD =\n  'bg-card hairline-ring ring-border absolute left-5 h-12 w-[calc(50%-26px)] rounded-lg opacity-0 shadow-[0_1px_2px_rgb(0_0_0/0.04)] transition-[translate,rotate,scale,opacity] ease-(--ease-in-out-strong) data-[shown=true]:opacity-100';\n\nconst LINE = 'bg-foreground/15 absolute left-2';\n\nconst DRAWN_DOWN =\n  'w-px origin-top scale-y-0 transition-[scale,opacity] duration-200 ease-(--ease-out-strong) data-[drawn=true]:scale-y-100';\n\nconst DRAWN_ACROSS =\n  'h-px w-3 origin-left scale-x-0 transition-[scale,opacity] duration-200 ease-(--ease-out-strong) data-[drawn=true]:scale-x-100';\n\nfunction SubtaskFace({ subtask }: { subtask: FlowSubtask }) {\n  return (\n    <span className='flex h-full flex-col justify-center gap-1 px-2.5'>\n      <span className='truncate text-xs leading-4 font-medium'>\n        {subtask.title}\n      </span>\n      <span className='text-muted-foreground flex items-center gap-1.5 text-[11px] leading-4'>\n        <Avatar seed={subtask.assignee} className='size-4' />\n        <span className='min-w-0 flex-1 truncate'>{subtask.role}</span>\n        <MessageSquareTextIcon className='size-3 shrink-0' />\n        <span className='tabular-nums'>{subtask.noteCount}</span>\n      </span>\n    </span>\n  );\n}\n\ntype NamedCursorProps = {\n  cursor: FlowCursor;\n  state: CursorState;\n  carry: string;\n  top: number;\n};\n\nfunction NamedCursor({ cursor, state, carry, top }: NamedCursorProps) {\n  const color = seriesColorOf(cursor.series);\n  const plate: GemStyle = { '--gem': color };\n\n  return (\n    <span\n      data-seen={isCursorSeen(state)}\n      style={{ top, ...cursorPoseOf(state, carry) }}\n      className='pointer-events-none absolute left-5 z-10 h-12 w-[calc(50%-26px)] opacity-0 transition-[translate,opacity] ease-(--ease-in-out-strong) data-[seen=true]:opacity-100'\n    >\n      <span className='absolute top-[55%] left-[38%] flex items-start'>\n        <MousePointerIcon style={{ color }} className='size-4 fill-current' />\n        <span\n          style={plate}\n          className='gem-plate mt-3 rounded-full px-2 py-0.5 text-[11px] leading-4 font-medium whitespace-nowrap'\n        >\n          {cursor.name}\n        </span>\n      </span>\n    </span>\n  );\n}\n\nexport type TaskFlowProps = {\n  task: FlowTask;\n  /** The cursor moves the last one into the empty slot. */\n  subtasks: FlowSubtask[];\n  cursor: FlowCursor;\n  className?: string;\n};\n\nexport function TaskFlow({ task, subtasks, cursor, className }: TaskFlowProps) {\n  const { ref, isPlaying, isStill } = useScenePlay();\n  const beat = useSceneFrames(BEATS, { isPlaying, isStill });\n  const count = subtasks.length;\n  const lastIndex = Math.max(count - 1, 0);\n  const slotIndex = Math.max(count - 2, 0);\n  const carry = carryOf(lastIndex, slotIndex);\n  const stageHeight = rowTopOf(lastIndex) + ROW_PX;\n  const trunkHeight = rowMiddleOf(slotIndex) - TASK_PX;\n  const lastTrunkHeight = rowMiddleOf(lastIndex) - rowMiddleOf(slotIndex);\n  const isLastInList = isStillInList(beat.card);\n  const isLastDrawn = beat.isBranched && isLastInList;\n  const isLastHome = beat.card === 'home';\n  const isLastEntering = beat.hasCards && isLastHome;\n  const hasLanded = beat.card === 'landed';\n  const isSlotFilled = beat.hasCards && hasLanded;\n  const isSlotAimed = beat.card === 'carried';\n\n  return (\n    <div\n      ref={ref}\n      role='img'\n      aria-label={labelOf(task, subtasks, cursor)}\n      style={{ height: stageHeight }}\n      className={cn('@container relative w-full max-w-[26rem]', className)}\n    >\n      <div className='bg-card hairline-ring ring-border absolute top-0 left-0 flex h-14 w-[66%] items-center gap-2 rounded-xl px-3 shadow-[0_1px_2px_rgb(0_0_0/0.04)]'>\n        <span className='flex min-w-0 flex-1 flex-col'>\n          <span className='truncate text-[13px] leading-5 font-medium'>\n            {task.title}\n          </span>\n          <span className='text-muted-foreground text-[11px] leading-4'>\n            {subtaskCountOf(count)}\n          </span>\n        </span>\n        <Avatar seed={task.owner} className='size-6' />\n      </div>\n      <span\n        data-drawn={beat.isBranched}\n        style={{ top: TASK_PX, height: trunkHeight }}\n        className={cn(LINE, DRAWN_DOWN)}\n      />\n      <span\n        data-drawn={isLastDrawn}\n        style={{ top: rowMiddleOf(slotIndex), height: lastTrunkHeight }}\n        className={cn(LINE, DRAWN_DOWN, 'data-[drawn=true]:delay-150')}\n      />\n      {subtasks.map((subtask, index) => {\n        const isLast = index === lastIndex;\n        const leadsToCard = !isLast || isLastInList;\n        const isDrawn = beat.isBranched && leadsToCard;\n\n        return (\n          <span\n            key={subtask.id}\n            data-drawn={isDrawn}\n            style={{\n              top: rowMiddleOf(index),\n              ...delayWhile(isDrawn, branchDelayOf(index)),\n            }}\n            className={cn(LINE, DRAWN_ACROSS)}\n          />\n        );\n      })}\n      <span\n        data-aimed={isSlotAimed}\n        data-filled={isSlotFilled}\n        style={{ top: rowTopOf(slotIndex) }}\n        className='hairline-border border-foreground/25 text-muted-foreground data-[aimed=true]:border-primary/60 data-[aimed=true]:bg-primary/[0.06] absolute right-1 flex h-12 w-[calc(50%-26px)] items-center justify-center rounded-lg border-dashed text-[11px] transition-[border-color,background-color,opacity] duration-200 data-[filled=true]:opacity-0'\n      >\n        Next up\n      </span>\n      {subtasks.map((subtask, index) => {\n        const isLast = index === lastIndex;\n        const tilt = tiltOf(index);\n        const delayMs = index * CARD_STAGGER_MS;\n\n        if (isLast) {\n          return (\n            <span\n              key={subtask.id}\n              data-shown={beat.hasCards}\n              style={{\n                top: rowTopOf(index),\n                ...movedPoseOf(beat.card, beat.hasCards, tilt, carry),\n                ...delayWhile(isLastEntering, delayMs),\n              }}\n              className={cn(CARD, 'z-5')}\n            >\n              <span\n                data-lifted={isLifted(beat.card)}\n                className='absolute inset-0 rounded-[inherit] opacity-0 shadow-[0_4px_8px_-2px_rgb(0_0_0/0.06),0_12px_32px_-4px_rgb(0_0_0/0.12)] transition-opacity duration-200 data-[lifted=true]:opacity-100'\n              />\n              <SubtaskFace subtask={subtask} />\n            </span>\n          );\n        }\n        return (\n          <span\n            key={subtask.id}\n            data-shown={beat.hasCards}\n            style={{\n              top: rowTopOf(index),\n              ...settledPoseOf(beat.hasCards, tilt),\n              ...delayWhile(beat.hasCards, delayMs),\n            }}\n            className={CARD}\n          >\n            <SubtaskFace subtask={subtask} />\n          </span>\n        );\n      })}\n      <NamedCursor\n        cursor={cursor}\n        state={beat.cursor}\n        carry={carry}\n        top={rowTopOf(lastIndex)}\n      />\n    </div>\n  );\n}\n\nconst TASK: FlowTask = {\n  title: 'Launch pricing page',\n  owner: 'Ines Moreau',\n};\n\nconst SUBTASKS: FlowSubtask[] = [\n  {\n    id: 'plans',\n    title: 'Plan table',\n    role: 'Design',\n    assignee: 'Maya Okafor',\n    noteCount: 2,\n  },\n  {\n    id: 'faq',\n    title: 'Write the FAQ',\n    role: 'Copy',\n    assignee: 'Jonas Weber',\n    noteCount: 1,\n  },\n  {\n    id: 'checkout',\n    title: 'Wire checkout',\n    role: 'Build',\n    assignee: 'Priya Nair',\n    noteCount: 3,\n  },\n];\n\nconst CURSOR: FlowCursor = { name: 'Ines', series: 5 };\n\nexport default function Illustration06() {\n  return <TaskFlow task={TASK} subtasks={SUBTASKS} cursor={CURSOR} />;\n}\n",
      "type": "registry:component",
      "target": "components/illustration/illustration-06.tsx"
    },
    {
      "path": "registry/ndeko/components/illustration/_parts/delay.ts",
      "content": "/**\n * A stagger belongs to an entrance. On the way out everything leaves together, so the delay only\n * applies while its element is shown.\n */\nexport function delayWhile(isShown: boolean, delayMs: number) {\n  if (isShown) {\n    return { transitionDelay: `${delayMs}ms` };\n  }\n  return { transitionDelay: '0ms' };\n}\n",
      "type": "registry:component",
      "target": "components/illustration/_parts/delay.ts"
    },
    {
      "path": "registry/ndeko/components/illustration/_parts/use-scene-frames.ts",
      "content": "'use client';\n\nimport { useEffect, useState } from 'react';\n\nimport type { ScenePlay } from './use-scene-play';\n\nexport type SceneFrame<State> = {\n  state: State;\n  /** Milliseconds the scene stays in this state before the next one. */\n  holdMs: number;\n};\n\nfunction nextIndexOf(index: number, count: number) {\n  const next = index + 1;\n  return next % count;\n}\n\n/**\n * A scene told as a flipbook: whole states, each held for a while, played in a loop. The first frame\n * is the resting picture: it shows before the scene plays and under reduced motion. While the scene\n * does not play the book stays on its page and no timer is left. `frames` holds at least one frame.\n */\nexport function useSceneFrames<State>(\n  frames: readonly SceneFrame<State>[],\n  { isPlaying, isStill }: ScenePlay\n) {\n  const [index, setIndex] = useState(0);\n  const frameCount = frames.length;\n  const shownIndex = index % frameCount;\n  const frame = frames[shownIndex];\n  const holdMs = frame.holdMs;\n\n  useEffect(() => {\n    if (!isPlaying) {\n      return;\n    }\n    const timer = window.setTimeout(() => {\n      setIndex(nextIndexOf(shownIndex, frameCount));\n    }, holdMs);\n    return () => window.clearTimeout(timer);\n  }, [isPlaying, shownIndex, frameCount, holdMs]);\n\n  if (isStill) {\n    return frames[0].state;\n  }\n  return frame.state;\n}\n",
      "type": "registry:component",
      "target": "components/illustration/_parts/use-scene-frames.ts"
    },
    {
      "path": "registry/ndeko/components/illustration/_parts/use-scene-play.ts",
      "content": "'use client';\n\nimport { useInView } from 'motion/react';\nimport { useRef } from 'react';\n\nimport { useDocumentVisible } from '@/registry/ndeko/hooks/use-agent-run';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\n\nconst IN_VIEW_SHARE = 0.3;\n\nexport type ScenePlay = {\n  /** True while a visitor can see the scene move: on screen, in a visible tab, without reduced motion. */\n  isPlaying: boolean;\n  /** True under reduced motion: the scene rests on its still frame. */\n  isStill: boolean;\n};\n\n/**\n * An illustration moves only while someone can see it. Everything that loops in a scene hangs on\n * `isPlaying`, so nothing runs off screen, in a hidden tab or under reduced motion.\n */\nexport function useScenePlay<Element extends HTMLElement = HTMLDivElement>() {\n  const ref = useRef<Element>(null);\n  const isInView = useInView(ref, { amount: IN_VIEW_SHARE });\n  const isTabVisible = useDocumentVisible();\n  const isStill = usePrefersReducedMotion();\n  const isOnScreen = isInView && isTabVisible;\n  const isPlaying = isOnScreen && !isStill;\n\n  return { ref, isPlaying, isStill };\n}\n",
      "type": "registry:component",
      "target": "components/illustration/_parts/use-scene-play.ts"
    }
  ],
  "categories": [
    "components",
    "illustration"
  ],
  "type": "registry:component"
}