{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "run-11",
  "title": "Error and retry",
  "description": "A failed step in plain words, with a ring that empties toward the next automatic retry, Retry now and Stop retrying, the raw error behind a fold with Copy, and a card that folds into one line once a try goes through.",
  "dependencies": [],
  "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/copy-button.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-number.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-11.tsx",
      "content": "'use client';\n\nimport { useId } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { WordRoll } from '@/components/core/word-roll';\nimport { useKeptHeight } from '@/registry/ndeko/hooks/use-kept-height';\nimport {\n  useSession,\n  type SessionStep,\n} from '@/registry/ndeko/hooks/use-session';\nimport {\n  pressedQuietOf,\n  pressedSolidOf,\n  spokenUnless,\n} from '@/registry/ndeko/lib/demonstration';\nimport {\n  ChevronDownIcon,\n  RefreshCwIcon,\n  StopIcon,\n  XIcon,\n} from '@/registry/ndeko/lib/icons';\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 { Fold, Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { CopyButton } from '@/registry/ndeko/ui/copy-button';\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 { useOpenState } from './_parts/use-open-state';\nimport {\n  useInterval,\n  useIsOwnClockOn,\n  useTimeout,\n} from './_parts/use-own-clock';\n\nexport type RetryPhase = 'waiting' | 'retrying' | 'recovered' | 'stopped';\n\nconst RING_SIZE = 36;\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 SPINNING_SHARE = 0.28;\n\nconst WAITING_RING = 'stroke-warning duration-1000 ease-linear';\n\nconst RETRYING_RING = 'stroke-primary duration-500 ease-(--ease-out-strong)';\n\nconst QUIET_RING = 'stroke-transparent duration-300 ease-(--ease-out-strong)';\n\nfunction ringFillOf(phase: RetryPhase) {\n  if (phase === 'waiting') {\n    return WAITING_RING;\n  }\n  if (phase === 'retrying') {\n    return RETRYING_RING;\n  }\n  return QUIET_RING;\n}\n\n/** The ring runs one second ahead of the figure, so it is empty the moment the next try starts. */\nfunction ringShareOf(\n  phase: RetryPhase,\n  secondsLeft: number,\n  waitSeconds: number\n) {\n  if (phase === 'retrying') {\n    return SPINNING_SHARE;\n  }\n  if (phase !== 'waiting') {\n    return 0;\n  }\n  const secondsAfterThisOne = Math.max(0, secondsLeft - 1);\n  return secondsAfterThisOne / waitSeconds;\n}\n\nfunction spinOf(phase: RetryPhase) {\n  if (phase === 'retrying') {\n    return 'animate-spin';\n  }\n  return undefined;\n}\n\ntype CountdownRingProps = {\n  phase: RetryPhase;\n  secondsLeft: number;\n  waitSeconds: number;\n};\n\nfunction CountdownRing({\n  phase,\n  secondsLeft,\n  waitSeconds,\n}: CountdownRingProps) {\n  const share = ringShareOf(phase, secondsLeft, waitSeconds);\n  const dashOffset = CIRCUMFERENCE * (1 - share);\n\n  return (\n    <span aria-hidden='true' className={cn('inline-flex', spinOf(phase))}>\n      <svg\n        width={RING_SIZE}\n        height={RING_SIZE}\n        viewBox={`0 0 ${RING_SIZE} ${RING_SIZE}`}\n        className='-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] motion-reduce:transition-none',\n            ringFillOf(phase)\n          )}\n        />\n      </svg>\n    </span>\n  );\n}\n\nfunction RingCenter({\n  phase,\n  secondsLeft,\n}: {\n  phase: RetryPhase;\n  secondsLeft: number;\n}) {\n  if (phase === 'waiting') {\n    return (\n      <span className='text-warning-foreground text-xs font-medium tabular-nums'>\n        {secondsLeft}\n      </span>\n    );\n  }\n  if (phase === 'retrying') {\n    return <RefreshCwIcon className='text-primary-ink size-3.5' />;\n  }\n  if (phase === 'recovered') {\n    return <DrawnCheck tone='success' entrance='draw' label='Recovered' />;\n  }\n  return <StopIcon className='text-muted-foreground size-3.5' />;\n}\n\nfunction PhaseWords({\n  phase,\n  secondsLeft,\n}: {\n  phase: RetryPhase;\n  secondsLeft: number;\n}) {\n  if (phase === 'waiting') {\n    return <span className='tabular-nums'>Next try in {secondsLeft}s</span>;\n  }\n  if (phase === 'retrying') {\n    return <span>Trying now</span>;\n  }\n  if (phase === 'recovered') {\n    return <span>Back on track</span>;\n  }\n  return <span>No more automatic tries</span>;\n}\n\nfunction headlineOf(phase: RetryPhase, title: string, recoveredTitle: string) {\n  if (phase === 'waiting') {\n    return title;\n  }\n  if (phase === 'retrying') {\n    return 'Trying again';\n  }\n  if (phase === 'recovered') {\n    return recoveredTitle;\n  }\n  return 'Stopped retrying';\n}\n\nfunction attemptBadgeOf(phase: RetryPhase) {\n  if (phase === 'recovered') {\n    return 'success';\n  }\n  return 'secondary';\n}\n\nfunction primaryLabelOf(phase: RetryPhase) {\n  if (phase === 'stopped') {\n    return 'Try again';\n  }\n  return 'Retry now';\n}\n\nfunction chevronTurnOf(isOpen: boolean) {\n  if (isOpen) {\n    return 'rotate-180';\n  }\n  return 'rotate-0';\n}\n\nexport type RetryCardProps = {\n  phase: RetryPhase;\n  /** The attempt that failed last while waiting, the one in progress while retrying, the one that worked once recovered. */\n  attempt: number;\n  maxAttempts: number;\n  secondsLeft: number;\n  /** The wait the countdown started from, so the ring knows how full to be. */\n  waitSeconds: number;\n  title: string;\n  cause: string;\n  details: string;\n  recoveredTitle: string;\n  onRetryNow?: () => void;\n  onStop?: () => void;\n  isDetailsOpen?: boolean;\n  onDetailsOpenChange?: (isOpen: boolean) => void;\n  /** Shows Retry now held down, for a demonstration that presses it. */\n  isRetryPressed?: boolean;\n  /** Shows Details held down, for a demonstration that presses it. */\n  isDetailsPressed?: boolean;\n  className?: string;\n};\n\nexport function RetryCard({\n  phase,\n  attempt,\n  maxAttempts,\n  secondsLeft,\n  waitSeconds,\n  title,\n  cause,\n  details,\n  recoveredTitle,\n  onRetryNow,\n  onStop,\n  isDetailsOpen,\n  onDetailsOpenChange,\n  isRetryPressed = false,\n  isDetailsPressed = false,\n  className,\n}: RetryCardProps) {\n  const detailsId = useId();\n  const detailsState = useOpenState({\n    isOpen: isDetailsOpen,\n    defaultOpen: false,\n    onOpenChange: onDetailsOpenChange,\n  });\n  const isRecovered = phase === 'recovered';\n  const isRetrying = phase === 'retrying';\n  const isStopped = phase === 'stopped';\n  const canStop = !isStopped && !isRecovered;\n  const headline = headlineOf(phase, title, recoveredTitle);\n  const primaryLabel = primaryLabelOf(phase);\n\n  return (\n    <section\n      aria-label='Agent error'\n      className={cn(\n        'bg-card hairline-ring ring-border rounded-xl p-3 shadow-[0_1px_2px_rgb(0_0_0/0.04)]',\n        className\n      )}\n    >\n      <div className='flex items-center gap-3'>\n        <span className='relative inline-flex size-9 shrink-0 items-center justify-center'>\n          <span className='absolute inset-0'>\n            <CountdownRing\n              phase={phase}\n              secondsLeft={secondsLeft}\n              waitSeconds={waitSeconds}\n            />\n          </span>\n          <Swap swapKey={phase} className='relative'>\n            <RingCenter phase={phase} secondsLeft={secondsLeft} />\n          </Swap>\n        </span>\n        <div className='flex min-w-0 flex-1 flex-col gap-0.5'>\n          <p className='min-w-0 truncate text-[13px] font-medium'>\n            <WordRoll text={headline} />\n          </p>\n          <p className='text-muted-foreground flex flex-wrap items-center gap-x-2 text-xs'>\n            <Badge variant={attemptBadgeOf(phase)}>\n              Attempt <MotionNumber value={attempt} /> of {maxAttempts}\n            </Badge>\n            <Swap swapKey={phase}>\n              <PhaseWords phase={phase} secondsLeft={secondsLeft} />\n            </Swap>\n          </p>\n        </div>\n      </div>\n      <Fold open={!isRecovered}>\n        <div className='flex flex-col gap-3 pt-3'>\n          <p className='text-muted-foreground text-xs leading-5'>{cause}</p>\n          <div className='flex flex-wrap items-center gap-2'>\n            <Button\n              type='button'\n              size='sm'\n              disabled={isRetrying}\n              focusableWhenDisabled\n              onClick={onRetryNow}\n              className={pressedSolidOf(isRetryPressed)}\n            >\n              <RefreshCwIcon />\n              <Swap swapKey={primaryLabel}>{primaryLabel}</Swap>\n            </Button>\n            {canStop && (\n              <Button\n                type='button'\n                variant='outline'\n                size='sm'\n                onClick={onStop}\n              >\n                <XIcon />\n                Stop retrying\n              </Button>\n            )}\n          </div>\n          <div className='flex flex-col'>\n            <button\n              type='button'\n              aria-expanded={detailsState.isOpen}\n              aria-controls={detailsId}\n              onClick={detailsState.toggle}\n              className={cn(\n                'text-muted-foreground hover:text-foreground focus-visible:ring-ring/25 flex h-6 w-fit cursor-pointer items-center gap-1 rounded-md text-xs transition-[color,scale] outline-none focus-visible:ring-[3px]',\n                pressedQuietOf(isDetailsPressed)\n              )}\n            >\n              Details\n              <ChevronDownIcon\n                className={cn(\n                  'size-3.5 transition-transform duration-200 ease-(--ease-out-strong)',\n                  chevronTurnOf(detailsState.isOpen)\n                )}\n              />\n            </button>\n            <Fold open={detailsState.isOpen} id={detailsId}>\n              <div className='bg-foreground/[0.04] dark:bg-foreground/[0.06] mt-1 flex items-start gap-2 rounded-lg p-2.5'>\n                <pre className='relative min-w-0 flex-1 overflow-x-auto font-mono text-xs leading-5'>\n                  {details}\n                </pre>\n                <CopyButton text={details} label='Copy the error details' />\n              </div>\n            </Fold>\n          </div>\n        </div>\n      </Fold>\n    </section>\n  );\n}\n\nconst MAX_ATTEMPTS = 4;\n\n/** Each failed attempt lengthens the wait before the next one. */\nconst WAITS_SECONDS = [4, 8, 16];\n\nconst RECOVERS_ON_ATTEMPT = 3;\n\nconst TICK_MS = 1000;\n\nconst RETRY_MS = 1300;\n\nconst TITLE = 'Could not read the pricing page';\n\nconst RECOVERED_TITLE = 'Read the pricing page';\n\nconst CAUSE =\n  'The supplier site answered \"too many requests\". The agent waits a little longer after each failed try, then asks again on its own.';\n\nconst DETAILS = [\n  'HTTP 429 Too Many Requests',\n  'GET https://pricing.brightmoor.example/wholesale',\n  'retry-after: 8',\n  'x-request-id: 7f3c0d1a',\n].join('\\n');\n\ntype RetryState = {\n  phase: RetryPhase;\n  attempt: number;\n  secondsLeft: number;\n  waitSeconds: number;\n  isDetailsOpen: boolean;\n  isHandled: boolean;\n};\n\ntype RetryAction =\n  | { type: 'tick' }\n  | { type: 'settle' }\n  | { type: 'retry-now' }\n  | { type: 'stop' }\n  | { type: 'details'; isOpen: boolean }\n  | { type: 'hold' };\n\ntype RetryStep = SessionStep<RetryState, RetryAction>;\n\nconst INITIAL: RetryState = {\n  phase: 'waiting',\n  attempt: 1,\n  secondsLeft: 4,\n  waitSeconds: 4,\n  isDetailsOpen: false,\n  isHandled: false,\n};\n\nconst RESTING: RetryState = {\n  phase: 'waiting',\n  attempt: 2,\n  secondsLeft: 5,\n  waitSeconds: 8,\n  isDetailsOpen: false,\n  isHandled: false,\n};\n\nfunction waitSecondsOf(failedAttempts: number) {\n  const lastIndex = WAITS_SECONDS.length - 1;\n  const index = Math.min(failedAttempts - 1, lastIndex);\n  return WAITS_SECONDS[index];\n}\n\nfunction tried(state: RetryState): RetryState {\n  return { ...state, phase: 'retrying', attempt: state.attempt + 1 };\n}\n\nfunction ticked(state: RetryState): RetryState {\n  if (state.phase !== 'waiting') {\n    return state;\n  }\n  const secondsLeft = state.secondsLeft - 1;\n  const isOver = secondsLeft <= 0;\n  if (isOver) {\n    return tried(state);\n  }\n  return { ...state, secondsLeft };\n}\n\nfunction settled(state: RetryState): RetryState {\n  if (state.phase !== 'retrying') {\n    return state;\n  }\n  const hasRecovered = state.attempt >= RECOVERS_ON_ATTEMPT;\n  if (hasRecovered) {\n    return { ...state, phase: 'recovered' };\n  }\n  const waitSeconds = waitSecondsOf(state.attempt);\n  return { ...state, phase: 'waiting', secondsLeft: waitSeconds, waitSeconds };\n}\n\nfunction retriedNow(state: RetryState): RetryState {\n  const isWaiting = state.phase === 'waiting';\n  const isStopped = state.phase === 'stopped';\n  const canRetry = isWaiting || isStopped;\n  if (!canRetry) {\n    return state;\n  }\n  return { ...tried(state), isHandled: true };\n}\n\nfunction stopped(state: RetryState): RetryState {\n  const isWaiting = state.phase === 'waiting';\n  const isRetrying = state.phase === 'retrying';\n  const canStop = isWaiting || isRetrying;\n  if (!canStop) {\n    return state;\n  }\n  return { ...state, phase: 'stopped', isHandled: true };\n}\n\nfunction reducer(state: RetryState, action: RetryAction): RetryState {\n  switch (action.type) {\n    case 'tick':\n      return ticked(state);\n    case 'settle':\n      return settled(state);\n    case 'retry-now':\n      return retriedNow(state);\n    case 'stop':\n      return stopped(state);\n    case 'details':\n      return { ...state, isDetailsOpen: action.isOpen };\n    case 'hold':\n      return state;\n  }\n}\n\nfunction tickStep(after: number): RetryStep {\n  return { after, by: 'demo', action: { type: 'tick' } };\n}\n\nfunction detailsStep(after: number, isOpen: boolean): RetryStep {\n  const action: RetryAction = { type: 'details', isOpen };\n  return { after, by: 'demo', press: 'details', action };\n}\n\nfunction hasSecondTryStarted(state: RetryState) {\n  const isStopped = state.phase === 'stopped';\n  const isPastSecondTry = state.attempt >= RECOVERS_ON_ATTEMPT;\n  return isStopped || isPastSecondTry;\n}\n\nconst SCRIPT: RetryStep[] = [\n  tickStep(1200),\n  detailsStep(100, true),\n  tickStep(900),\n  tickStep(1000),\n  detailsStep(100, false),\n  tickStep(900),\n  { after: RETRY_MS, by: 'demo', action: { type: 'settle' } },\n  tickStep(1000),\n  tickStep(1000),\n  tickStep(1000),\n  {\n    after: 500,\n    by: 'person',\n    press: 'retry',\n    action: { type: 'retry-now' },\n    isAnswered: hasSecondTryStarted,\n  },\n  { after: RETRY_MS, by: 'demo', action: { type: 'settle' } },\n  { after: 4200, by: 'demo', action: { type: 'hold' } },\n];\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: 3000,\n};\n\nfunction announcementOf(state: RetryState) {\n  if (state.phase === 'waiting') {\n    const failed = `Attempt ${state.attempt} failed`;\n    const wait = countOf(state.waitSeconds, 'second');\n    return `${failed}. The next try is in ${wait}`;\n  }\n  if (state.phase === 'retrying') {\n    return `Trying again, attempt ${state.attempt} of ${MAX_ATTEMPTS}`;\n  }\n  if (state.phase === 'recovered') {\n    return `It worked on attempt ${state.attempt}`;\n  }\n  return 'Stopped retrying';\n}\n\nfunction isSettledPhase(phase: RetryPhase) {\n  const isRecovered = phase === 'recovered';\n  const isStopped = phase === 'stopped';\n  return isRecovered || isStopped;\n}\n\nexport default function Run11() {\n  const { ref, isInView, isAutoplaying, state, act, pressed, restart } =\n    useSession(SESSION);\n  const isClockOn = useIsOwnClockOn({\n    isInView,\n    isAutoplaying,\n    isHandled: state.isHandled,\n  });\n  const isWaiting = state.phase === 'waiting';\n  const isRetrying = state.phase === 'retrying';\n  const canReplay = isSettledPhase(state.phase) && !isAutoplaying;\n  const announcement = announcementOf(state);\n\n  function tick() {\n    act({ type: 'tick' });\n  }\n\n  function settle() {\n    act({ type: 'settle' });\n  }\n\n  function retryNow() {\n    act({ type: 'retry-now' });\n  }\n\n  function stop() {\n    act({ type: 'stop' });\n  }\n\n  function changeDetails(isOpen: boolean) {\n    act({ type: 'details', isOpen });\n  }\n\n  useInterval(tick, TICK_MS, isClockOn && isWaiting);\n  useTimeout(settle, RETRY_MS, isClockOn && isRetrying);\n  useKeptHeight(ref);\n\n  return (\n    <div\n      ref={ref}\n      className='flex min-h-[21rem] w-full max-w-[28rem] flex-col gap-2'\n    >\n      <ClockGate isActive={isInView}>\n        <RetryCard\n          phase={state.phase}\n          attempt={state.attempt}\n          maxAttempts={MAX_ATTEMPTS}\n          secondsLeft={state.secondsLeft}\n          waitSeconds={state.waitSeconds}\n          title={TITLE}\n          cause={CAUSE}\n          details={DETAILS}\n          recoveredTitle={RECOVERED_TITLE}\n          onRetryNow={retryNow}\n          onStop={stop}\n          isDetailsOpen={state.isDetailsOpen}\n          onDetailsOpenChange={changeDetails}\n          isRetryPressed={pressed === 'retry'}\n          isDetailsPressed={pressed === 'details'}\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-11.tsx"
    },
    {
      "path": "registry/ndeko/components/run/_parts/use-open-state.ts",
      "content": "'use client';\n\nimport { useState } from 'react';\n\ntype OpenStateOptions = {\n  /** When given, the parent owns the state. */\n  isOpen?: boolean;\n  defaultOpen: boolean;\n  onOpenChange?: (isOpen: boolean) => void;\n};\n\nfunction currentOpenOf(isOpen: boolean | undefined, ownOpen: boolean) {\n  if (isOpen === undefined) {\n    return ownOpen;\n  }\n  return isOpen;\n}\n\nexport function useOpenState({\n  isOpen,\n  defaultOpen,\n  onOpenChange,\n}: OpenStateOptions) {\n  const [ownOpen, setOwnOpen] = useState(defaultOpen);\n  const current = currentOpenOf(isOpen, ownOpen);\n\n  function toggle() {\n    const next = !current;\n    setOwnOpen(next);\n    onOpenChange?.(next);\n  }\n\n  return { isOpen: current, toggle };\n}\n",
      "type": "registry:component",
      "target": "components/run/_parts/use-open-state.ts"
    },
    {
      "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"
}