{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "run-14",
  "title": "Background tasks",
  "description": "A queue of long jobs with a bar and the time left on each, Cancel and Retry on a failed one, finished jobs that check themselves and leave, and a ring in the header that closes as the queue empties.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/badge.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/drawn-check.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/live-duration.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/motion-presets.json",
    "https://ui.ndekocode.dev/r/motion-word-roll.json",
    "https://ui.ndekocode.dev/r/replay-button.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-agent-run.json",
    "https://ui.ndekocode.dev/r/use-kept-height.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/use-session.json",
    "https://ui.ndekocode.dev/r/utils.json",
    "https://ui.ndekocode.dev/r/words.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/run/run-14.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\n\nimport { WordRoll } from '@/components/core/word-roll';\nimport { useKeptHeight } from '@/registry/ndeko/hooks/use-kept-height';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  useSession,\n  type SessionStep,\n} from '@/registry/ndeko/hooks/use-session';\nimport {\n  pressedQuietOf,\n  spokenUnless,\n} from '@/registry/ndeko/lib/demonstration';\nimport {\n  DatabaseIcon,\n  ImageIcon,\n  RotateCcwIcon,\n  TableIcon,\n  XIcon,\n  type Icon,\n} from '@/registry/ndeko/lib/icons';\nimport { rowPresenceOf } from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { countOf } from '@/registry/ndeko/lib/words';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { DrawnCheck } from '@/registry/ndeko/ui/drawn-check';\nimport { ClockGate } from '@/registry/ndeko/ui/live-duration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\n\nimport { useInterval, useIsOwnClockOn } from './_parts/use-own-clock';\n\nexport type JobKind = 'index' | 'export' | 'resize';\n\nexport type JobStatus = 'running' | 'failed' | 'done';\n\nexport type BackgroundJob = {\n  id: string;\n  kind: JobKind;\n  title: string;\n  detail: string;\n  status: JobStatus;\n  /** From 0 to 100. */\n  progress: number;\n  secondsLeft?: number;\n  error?: string;\n};\n\nconst JOB_ICONS: Record<JobKind, Icon> = {\n  index: DatabaseIcon,\n  export: TableIcon,\n  resize: ImageIcon,\n};\n\nconst RING_SIZE = 32;\n\nconst RING_STROKE = 3;\n\nconst RING_RADIUS = (RING_SIZE - RING_STROKE) / 2;\n\nconst RING_CENTER = RING_SIZE / 2;\n\nconst CIRCUMFERENCE = 2 * Math.PI * RING_RADIUS;\n\nconst FILL_TONE: Record<JobStatus, string> = {\n  running: 'bg-primary',\n  failed: 'bg-destructive',\n  done: 'bg-success',\n};\n\nfunction queueShareOf(jobs: BackgroundJob[], finishedCount: number) {\n  const batchSize = jobs.length + finishedCount;\n  if (batchSize === 0) {\n    return 0;\n  }\n  let progressed = finishedCount * 100;\n  for (const job of jobs) {\n    progressed += job.progress;\n  }\n  return progressed / (batchSize * 100);\n}\n\nfunction barStyleOf(progress: number): React.CSSProperties {\n  const share = Math.min(1, Math.max(0, progress / 100));\n  return { transform: `scaleX(${share})` };\n}\n\nfunction timeLeftOf(seconds: number | undefined) {\n  if (seconds === undefined) {\n    return '';\n  }\n  if (seconds < 60) {\n    return `${seconds}s left`;\n  }\n  const minutes = Math.floor(seconds / 60);\n  const rest = seconds % 60;\n  return `${minutes}m ${rest}s left`;\n}\n\nfunction ringToneOf(isClosed: boolean) {\n  if (isClosed) {\n    return 'stroke-success';\n  }\n  return 'stroke-info';\n}\n\ntype QueueRingProps = {\n  share: number;\n  isClosed: boolean;\n};\n\nfunction QueueRing({ share, isClosed }: QueueRingProps) {\n  const dashOffset = CIRCUMFERENCE * (1 - share);\n  const percent = Math.round(share * 100);\n  const centerKey = String(isClosed);\n\n  return (\n    <span className='relative inline-flex size-8 shrink-0 items-center justify-center'>\n      <svg\n        aria-hidden='true'\n        width={RING_SIZE}\n        height={RING_SIZE}\n        viewBox={`0 0 ${RING_SIZE} ${RING_SIZE}`}\n        className='absolute inset-0 -rotate-90'\n      >\n        <circle\n          cx={RING_CENTER}\n          cy={RING_CENTER}\n          r={RING_RADIUS}\n          fill='none'\n          strokeWidth={RING_STROKE}\n          className='stroke-foreground/10'\n        />\n        <circle\n          cx={RING_CENTER}\n          cy={RING_CENTER}\n          r={RING_RADIUS}\n          fill='none'\n          strokeWidth={RING_STROKE}\n          strokeLinecap='round'\n          strokeDasharray={CIRCUMFERENCE}\n          strokeDashoffset={dashOffset}\n          className={cn(\n            'transition-[stroke-dashoffset,stroke] duration-500 ease-(--ease-out-strong) motion-reduce:transition-none',\n            ringToneOf(isClosed)\n          )}\n        />\n      </svg>\n      <Swap swapKey={centerKey} className='relative'>\n        {isClosed && (\n          <DrawnCheck tone='success' entrance='draw' label='All jobs done' />\n        )}\n        {!isClosed && (\n          <span className='text-muted-foreground text-[10px] tabular-nums'>\n            {percent}\n          </span>\n        )}\n      </Swap>\n    </span>\n  );\n}\n\nfunction headerLineOf(jobs: BackgroundJob[], finishedCount: number) {\n  const hasNothing = jobs.length === 0 && finishedCount === 0;\n  if (hasNothing) {\n    return 'No background jobs';\n  }\n  if (jobs.length === 0) {\n    return 'All jobs are done';\n  }\n  const running = jobs.filter((job) => job.status === 'running');\n  const failed = jobs.filter((job) => job.status === 'failed');\n  const failedCount = failed.length;\n  if (running.length === 0) {\n    return `${countOf(failedCount, 'job')} failed`;\n  }\n  const runningWords = `${countOf(running.length, 'job')} running`;\n  if (failedCount === 0) {\n    return runningWords;\n  }\n  return `${runningWords}, ${failedCount} failed`;\n}\n\nfunction JobStatusLine({ job }: { job: BackgroundJob }) {\n  if (job.status === 'running') {\n    return (\n      <span className='text-muted-foreground text-xs tabular-nums'>\n        {timeLeftOf(job.secondsLeft)}\n      </span>\n    );\n  }\n  if (job.status === 'failed') {\n    return <Badge variant='destructive'>Failed</Badge>;\n  }\n  return (\n    <span className='text-success-foreground flex items-center gap-1.5 text-xs'>\n      <DrawnCheck tone='success' entrance='draw' />\n      Done\n    </span>\n  );\n}\n\ntype JobRowProps = {\n  job: BackgroundJob;\n  isRetryPressed: boolean;\n  onCancel?: (jobId: string) => void;\n  onRetry?: (jobId: string) => void;\n};\n\nfunction JobRow({ job, isRetryPressed, onCancel, onRetry }: JobRowProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowPresence = rowPresenceOf(shouldReduceMotion);\n  const Glyph = JOB_ICONS[job.kind];\n  const isFailed = job.status === 'failed';\n  const isDone = job.status === 'done';\n  const canRetry = isFailed && onRetry !== undefined;\n  const canCancel = !isDone && onCancel !== undefined;\n\n  function cancel() {\n    onCancel?.(job.id);\n  }\n\n  function retry() {\n    onRetry?.(job.id);\n  }\n\n  return (\n    <motion.li\n      data-status={job.status}\n      className='overflow-hidden'\n      {...rowPresence}\n    >\n      <div className='grid grid-cols-[1.75rem_minmax(0,1fr)_auto] items-center gap-x-3 gap-y-2 py-2'>\n        <span className='keycap-3d text-muted-foreground inline-flex size-7 items-center justify-center rounded-md'>\n          <Glyph className='size-4' />\n        </span>\n        <span className='flex min-w-0 flex-col'>\n          <span className='truncate text-[13px] font-medium'>{job.title}</span>\n          <span className='text-muted-foreground truncate text-xs'>\n            {job.detail}\n          </span>\n        </span>\n        <span className='flex items-center gap-1.5'>\n          <Swap swapKey={job.status}>\n            <JobStatusLine job={job} />\n          </Swap>\n          {canRetry && (\n            <Button\n              type='button'\n              variant='outline'\n              size='sm'\n              aria-label={`Retry ${job.title}`}\n              onClick={retry}\n              className={pressedQuietOf(isRetryPressed)}\n            >\n              <RotateCcwIcon />\n              Retry\n            </Button>\n          )}\n          {canCancel && (\n            <Button\n              type='button'\n              variant='ghost'\n              size='icon-sm'\n              aria-label={`Cancel ${job.title}`}\n              onClick={cancel}\n              className='text-muted-foreground'\n            >\n              <XIcon />\n            </Button>\n          )}\n        </span>\n        <span\n          role='progressbar'\n          aria-label={`${job.title} progress`}\n          aria-valuemin={0}\n          aria-valuemax={100}\n          aria-valuenow={Math.round(job.progress)}\n          className='bg-foreground/10 col-span-full h-1 overflow-hidden rounded-full'\n        >\n          <span\n            style={barStyleOf(job.progress)}\n            className={cn(\n              'block h-full w-full origin-left rounded-full transition-[transform,background-color] duration-[400ms] ease-linear motion-reduce:transition-none',\n              FILL_TONE[job.status]\n            )}\n          />\n        </span>\n        <AnimatePresence initial={false}>\n          {isFailed && job.error && (\n            <motion.span\n              key='error'\n              className='text-destructive-ink col-span-full block overflow-hidden text-xs leading-5'\n              {...rowPresence}\n            >\n              {job.error}\n            </motion.span>\n          )}\n        </AnimatePresence>\n      </div>\n    </motion.li>\n  );\n}\n\nexport type BackgroundTasksProps = {\n  jobs: BackgroundJob[];\n  /** How many jobs of this batch finished and already left the list. */\n  finishedCount: number;\n  onCancel?: (jobId: string) => void;\n  onRetry?: (jobId: string) => void;\n  /** The job whose Retry a demonstration holds down. */\n  pressedRetryId?: string | null;\n  className?: string;\n};\n\nexport function BackgroundTasks({\n  jobs,\n  finishedCount,\n  onCancel,\n  onRetry,\n  pressedRetryId = null,\n  className,\n}: BackgroundTasksProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowPresence = rowPresenceOf(shouldReduceMotion);\n  const share = queueShareOf(jobs, finishedCount);\n  const isEmpty = jobs.length === 0;\n  const isClosed = isEmpty && finishedCount > 0;\n  const headerLine = headerLineOf(jobs, finishedCount);\n\n  return (\n    <section\n      aria-label='Background jobs'\n      className={cn(\n        'bg-card hairline-ring ring-border flex flex-col gap-2 rounded-xl p-4 shadow-[0_1px_2px_rgb(0_0_0/0.04)]',\n        className\n      )}\n    >\n      <header className='flex items-center gap-3'>\n        <QueueRing share={share} isClosed={isClosed} />\n        <div className='flex min-w-0 flex-col'>\n          <h3 className='text-sm font-medium'>Background jobs</h3>\n          <p className='text-muted-foreground min-w-0 truncate text-xs'>\n            <WordRoll text={headerLine} />\n          </p>\n        </div>\n      </header>\n      <ul aria-label='Jobs' className='flex flex-col'>\n        <AnimatePresence initial={false}>\n          {jobs.map((job) => (\n            <JobRow\n              key={job.id}\n              job={job}\n              isRetryPressed={pressedRetryId === job.id}\n              onCancel={onCancel}\n              onRetry={onRetry}\n            />\n          ))}\n        </AnimatePresence>\n      </ul>\n      <AnimatePresence initial={false}>\n        {isClosed && (\n          <motion.p\n            key='empty'\n            className='text-muted-foreground overflow-hidden text-xs leading-5'\n            {...rowPresence}\n          >\n            Every job finished. Nothing runs in the background.\n          </motion.p>\n        )}\n      </AnimatePresence>\n    </section>\n  );\n}\n\nconst TICK_MS = 400;\n\nconst SECONDS_PER_TICK = TICK_MS / 1000;\n\n/** A finished job shows its check for this many ticks, then leaves. */\nconst LEAVE_TICKS = 4;\n\ntype JobSpec = {\n  id: string;\n  kind: JobKind;\n  title: string;\n  detail: string;\n  /** Percent of the job done each second. */\n  rate: number;\n  /** The first attempt stops here, with this error. */\n  failsAt?: number;\n  error?: string;\n};\n\nconst SPECS: JobSpec[] = [\n  {\n    id: 'index',\n    kind: 'index',\n    title: 'Index the support docs',\n    detail: '1,820 pages',\n    rate: 14,\n  },\n  {\n    id: 'export',\n    kind: 'export',\n    title: 'Export Q3 invoices',\n    detail: '12,400 rows to CSV',\n    rate: 20,\n    failsAt: 60,\n    error: 'The export host closed the connection',\n  },\n  {\n    id: 'resize',\n    kind: 'resize',\n    title: 'Resize product photos',\n    detail: '240 photos to 1600 px',\n    rate: 11,\n  },\n];\n\ntype JobState = BackgroundJob & {\n  rate: number;\n  failsAt?: number;\n  attempts: number;\n  /** Ticks left before a finished job leaves the list. */\n  leaveIn?: number;\n};\n\ntype QueueState = {\n  jobs: JobState[];\n  finishedCount: number;\n  isHandled: boolean;\n};\n\ntype QueueAction =\n  | { type: 'tick' }\n  | { type: 'retry'; id: string }\n  | { type: 'cancel'; id: string }\n  | { type: 'hold' };\n\ntype QueueStep = SessionStep<QueueState, QueueAction>;\n\nfunction secondsLeftOf(progress: number, rate: number) {\n  const remaining = 100 - progress;\n  return Math.ceil(remaining / rate);\n}\n\nfunction startedJob(spec: JobSpec): JobState {\n  return {\n    id: spec.id,\n    kind: spec.kind,\n    title: spec.title,\n    detail: spec.detail,\n    status: 'running',\n    progress: 0,\n    secondsLeft: secondsLeftOf(0, spec.rate),\n    rate: spec.rate,\n    failsAt: spec.failsAt,\n    attempts: 0,\n    error: undefined,\n  };\n}\n\nconst INITIAL: QueueState = {\n  jobs: SPECS.map(startedJob),\n  finishedCount: 0,\n  isHandled: false,\n};\n\nfunction hasFailureAhead(job: JobState) {\n  const isFirstAttempt = job.attempts === 0;\n  const canFail = job.failsAt !== undefined;\n  return isFirstAttempt && canFail;\n}\n\nfunction failedJob(job: JobState, failsAt: number, error: string): JobState {\n  return {\n    ...job,\n    status: 'failed',\n    progress: failsAt,\n    secondsLeft: undefined,\n    error,\n  };\n}\n\nfunction ranJob(job: JobState): JobState {\n  const progress = Math.min(100, job.progress + job.rate * SECONDS_PER_TICK);\n  const failsAt = job.failsAt ?? 100;\n  const stopsToFail = hasFailureAhead(job) && progress >= failsAt;\n  if (stopsToFail) {\n    const spec = SPECS.find((candidate) => candidate.id === job.id);\n    const error = spec?.error ?? '';\n    return failedJob(job, failsAt, error);\n  }\n  if (progress >= 100) {\n    return {\n      ...job,\n      status: 'done',\n      progress: 100,\n      secondsLeft: undefined,\n      leaveIn: LEAVE_TICKS,\n    };\n  }\n  const secondsLeft = secondsLeftOf(progress, job.rate);\n  return { ...job, progress, secondsLeft };\n}\n\nfunction agedJob(job: JobState): JobState {\n  const leaveIn = (job.leaveIn ?? 0) - 1;\n  return { ...job, leaveIn };\n}\n\nfunction hasLeft(job: JobState) {\n  const isDone = job.status === 'done';\n  const hasTimeRunOut = (job.leaveIn ?? 1) <= 0;\n  return isDone && hasTimeRunOut;\n}\n\nfunction ticked(state: QueueState): QueueState {\n  const advanced = state.jobs.map((job) => {\n    if (job.status === 'running') {\n      return ranJob(job);\n    }\n    if (job.status === 'done') {\n      return agedJob(job);\n    }\n    return job;\n  });\n  const leavers = advanced.filter(hasLeft);\n  const jobs = advanced.filter((job) => !hasLeft(job));\n  const finishedCount = state.finishedCount + leavers.length;\n  return { ...state, jobs, finishedCount };\n}\n\nfunction retried(state: QueueState, id: string): QueueState {\n  const jobs = state.jobs.map((job) => {\n    const isTarget = job.id === id;\n    const isFailed = job.status === 'failed';\n    if (!isTarget || !isFailed) {\n      return job;\n    }\n    const status: JobStatus = 'running';\n    return {\n      ...job,\n      status,\n      progress: 0,\n      secondsLeft: secondsLeftOf(0, job.rate),\n      error: undefined,\n      attempts: job.attempts + 1,\n    };\n  });\n  return { ...state, jobs, isHandled: true };\n}\n\nfunction cancelled(state: QueueState, id: string): QueueState {\n  const jobs = state.jobs.filter((job) => job.id !== id);\n  return { ...state, jobs, isHandled: true };\n}\n\nfunction reducer(state: QueueState, action: QueueAction): QueueState {\n  switch (action.type) {\n    case 'tick':\n      return ticked(state);\n    case 'retry':\n      return retried(state, action.id);\n    case 'cancel':\n      return cancelled(state, action.id);\n    case 'hold':\n      return state;\n  }\n}\n\nconst TICKS_BEFORE_RETRY = 12;\n\nconst TICKS_AFTER_RETRY = 19;\n\nfunction tickSteps(count: number): QueueStep[] {\n  const steps: QueueStep[] = [];\n  for (let index = 0; index < count; index += 1) {\n    steps.push({ after: TICK_MS, by: 'demo', action: { type: 'tick' } });\n  }\n  return steps;\n}\n\nconst SCRIPT: QueueStep[] = [\n  { after: 900, by: 'demo', action: { type: 'tick' } },\n  ...tickSteps(TICKS_BEFORE_RETRY),\n  {\n    after: 700,\n    by: 'demo',\n    press: 'retry',\n    action: { type: 'retry', id: 'export' },\n  },\n  ...tickSteps(TICKS_AFTER_RETRY),\n  { after: 4000, by: 'demo', action: { type: 'hold' } },\n];\n\nfunction restingStateOf() {\n  let state = INITIAL;\n  for (let index = 0; index < 9; index += 1) {\n    state = ticked(state);\n  }\n  return state;\n}\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: restingStateOf(),\n  script: SCRIPT,\n  loopAfter: 3000,\n};\n\nfunction announcementOf(state: QueueState) {\n  const failed = state.jobs.find((job) => job.status === 'failed');\n  if (failed) {\n    return `${failed.title} failed. ${failed.error ?? ''}`;\n  }\n  const hasFinishedAll = state.jobs.length === 0 && state.finishedCount > 0;\n  if (hasFinishedAll) {\n    return 'Every job finished';\n  }\n  const running = state.jobs.filter((job) => job.status === 'running');\n  return `${countOf(running.length, 'job')} running`;\n}\n\nfunction pressedIdOf(pressed: string | null) {\n  if (pressed === 'retry') {\n    return 'export';\n  }\n  return null;\n}\n\nexport default function Run14() {\n  const {\n    ref,\n    isInView,\n    isAutoplaying,\n    state,\n    act,\n    pressed,\n    isFinished,\n    restart,\n  } = useSession(SESSION);\n  const isClockOn = useIsOwnClockOn({\n    isInView,\n    isAutoplaying,\n    isHandled: state.isHandled,\n  });\n  const isBusy = state.jobs.some((job) => job.status !== 'failed');\n  const isOver = state.jobs.length === 0 && state.finishedCount > 0;\n  const canReplay = isOver && isFinished && !isAutoplaying;\n  const announcement = announcementOf(state);\n\n  function tick() {\n    act({ type: 'tick' });\n  }\n\n  function retry(id: string) {\n    act({ type: 'retry', id });\n  }\n\n  function cancel(id: string) {\n    act({ type: 'cancel', id });\n  }\n\n  useInterval(tick, TICK_MS, isClockOn && isBusy);\n  useKeptHeight(ref);\n\n  return (\n    <div\n      ref={ref}\n      className='flex min-h-[23rem] w-full max-w-[32rem] flex-col gap-2'\n    >\n      <ClockGate isActive={isInView}>\n        <BackgroundTasks\n          jobs={state.jobs}\n          finishedCount={state.finishedCount}\n          onCancel={cancel}\n          onRetry={retry}\n          pressedRetryId={pressedIdOf(pressed)}\n        />\n      </ClockGate>\n      <div className='flex h-7 items-center justify-end'>\n        <ReplayButton isShown={canReplay} onReplay={restart} />\n      </div>\n      <LiveRegion message={spokenUnless(isAutoplaying, announcement)} />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/run/run-14.tsx"
    },
    {
      "path": "registry/ndeko/components/run/_parts/use-own-clock.ts",
      "content": "'use client';\n\nimport { useEffect, useRef } from 'react';\n\nimport { useDocumentVisible } from '@/registry/ndeko/hooks/use-agent-run';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\n\ntype ClockGate = {\n  isInView: boolean;\n  isAutoplaying: boolean;\n  /** True once a person pressed one of the controls: under reduced motion the piece then runs for real. */\n  isHandled: boolean;\n};\n\n/**\n * The demonstration plays the first round through its script. From the moment a person takes over,\n * or presses a control under reduced motion, the piece runs on its own clock instead, so a\n * countdown or a job they started always reaches its end.\n */\nexport function useIsOwnClockOn({\n  isInView,\n  isAutoplaying,\n  isHandled,\n}: ClockGate) {\n  const isVisible = useDocumentVisible();\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const isSeen = isInView && isVisible;\n  const hasTakenOver = !isAutoplaying;\n  const mayRun = !shouldReduceMotion || isHandled;\n  return isSeen && hasTakenOver && mayRun;\n}\n\n/** Calls the latest `onTick` every `intervalMs` while `isOn`, and holds still otherwise. */\nexport function useInterval(\n  onTick: () => void,\n  intervalMs: number,\n  isOn: boolean\n) {\n  const latest = useRef(onTick);\n\n  useEffect(() => {\n    latest.current = onTick;\n  });\n\n  useEffect(() => {\n    if (!isOn) {\n      return;\n    }\n    const timer = setInterval(() => latest.current(), intervalMs);\n    return () => clearInterval(timer);\n  }, [intervalMs, isOn]);\n}\n\n/** Calls the latest `onElapse` once, `delayMs` after `isOn` turns true. */\nexport function useTimeout(\n  onElapse: () => void,\n  delayMs: number,\n  isOn: boolean\n) {\n  const latest = useRef(onElapse);\n\n  useEffect(() => {\n    latest.current = onElapse;\n  });\n\n  useEffect(() => {\n    if (!isOn) {\n      return;\n    }\n    const timer = setTimeout(() => latest.current(), delayMs);\n    return () => clearTimeout(timer);\n  }, [delayMs, isOn]);\n}\n",
      "type": "registry:component",
      "target": "components/run/_parts/use-own-clock.ts"
    }
  ],
  "categories": [
    "components",
    "run"
  ],
  "type": "registry:component"
}