{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "run-13",
  "title": "Sandbox preview",
  "description": "The page a coding agent is building, beside the chat: Reload runs a thin progress line across the frame, the frame morphs between Desktop and Mobile width, and a console drawer opens to the last lines as hot updates arrive.",
  "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/chip.json",
    "https://ui.ndekocode.dev/r/company-mark.json",
    "https://ui.ndekocode.dev/r/demonstration.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/replay-button.json",
    "https://ui.ndekocode.dev/r/run-session.json",
    "https://ui.ndekocode.dev/r/segments.json",
    "https://ui.ndekocode.dev/r/theme.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/use-timeouts.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/run/run-13.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useId } from 'react';\n\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 { useTimeouts } from '@/registry/ndeko/hooks/use-timeouts';\nimport {\n  pressedQuietOf,\n  spokenUnless,\n} from '@/registry/ndeko/lib/demonstration';\nimport {\n  ChevronDownIcon,\n  RefreshCwIcon,\n  TerminalIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { rowPresenceOf } from '@/registry/ndeko/lib/motion-presets';\nimport { restingOf } from '@/registry/ndeko/lib/run-session';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Fold } from '@/registry/ndeko/ui/chat-motion';\nimport { ClockGate } from '@/registry/ndeko/ui/live-duration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\nimport { Segments, type Segment } from '@/registry/ndeko/ui/segments';\n\nimport { PricingPage } from './_parts/pricing-page';\n\nexport type PreviewView = 'desktop' | 'mobile';\n\nexport type ConsoleTone = 'info' | 'hot';\n\nexport type ConsoleLine = {\n  id: number;\n  tone: ConsoleTone;\n  text: string;\n};\n\nconst VIEWS: Segment<PreviewView>[] = [\n  { value: 'desktop', label: 'Desktop' },\n  { value: 'mobile', label: 'Mobile' },\n];\n\nconst FRAME_SIZE: Record<PreviewView, string> = {\n  desktop: 'w-full rounded-lg',\n  mobile: 'w-[17.5rem] rounded-[1.25rem]',\n};\n\nconst LINE_TONE: Record<ConsoleTone, string> = {\n  info: 'text-muted-foreground',\n  hot: 'text-primary-ink',\n};\n\nconst PROGRESS_START = { scaleX: 0.04, opacity: 1 };\n\nconst PROGRESS_RUNNING = { scaleX: 0.88, opacity: 1 };\n\nconst PROGRESS_DONE = { scaleX: 1, opacity: 0 };\n\nfunction chevronTurnOf(isOpen: boolean) {\n  if (isOpen) {\n    return 'rotate-180';\n  }\n  return 'rotate-0';\n}\n\nfunction spinOf(isReloading: boolean) {\n  if (isReloading) {\n    return 'animate-spin';\n  }\n  return undefined;\n}\n\nfunction frameLabelOf(view: PreviewView) {\n  if (view === 'mobile') {\n    return 'Preview of the page at phone width';\n  }\n  return 'Preview of the page at desktop width';\n}\n\nfunction ReloadLine({ isReloading }: { isReloading: boolean }) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const duration = reloadDurationOf(shouldReduceMotion);\n\n  return (\n    <AnimatePresence initial={false}>\n      {isReloading && (\n        <motion.span\n          key='reload'\n          aria-hidden='true'\n          initial={PROGRESS_START}\n          animate={PROGRESS_RUNNING}\n          exit={{ ...PROGRESS_DONE, transition: { duration: 0.25 } }}\n          transition={{ duration, ease: [0.23, 1, 0.32, 1] }}\n          className='bg-primary absolute inset-x-0 top-0 z-10 h-0.5 origin-left'\n        />\n      )}\n    </AnimatePresence>\n  );\n}\n\nfunction reloadDurationOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return 0;\n  }\n  return 0.9;\n}\n\nfunction ConsoleLines({ lines }: { lines: ConsoleLine[] }) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowPresence = rowPresenceOf(shouldReduceMotion);\n\n  return (\n    <ul\n      aria-label='Preview console'\n      className='bg-foreground/[0.04] dark:bg-foreground/[0.06] flex flex-col rounded-lg px-3 py-1.5 font-mono text-xs leading-5'\n    >\n      <AnimatePresence initial={false}>\n        {lines.map((line) => (\n          <motion.li key={line.id} className='overflow-hidden' {...rowPresence}>\n            <span className={cn('block truncate', LINE_TONE[line.tone])}>\n              [dev] {line.text}\n            </span>\n          </motion.li>\n        ))}\n      </AnimatePresence>\n    </ul>\n  );\n}\n\nexport type SandboxPreviewProps = {\n  /** The address the page runs at: \"localhost:3000/pricing\". */\n  address: string;\n  view: PreviewView;\n  onViewChange: (view: PreviewView) => void;\n  isReloading: boolean;\n  onReload: () => void;\n  isConsoleOpen: boolean;\n  onConsoleOpenChange: (isOpen: boolean) => void;\n  lines: ConsoleLine[];\n  /** The running page: an iframe, or anything drawn in the frame. */\n  children: React.ReactNode;\n  /** Shows Reload held down, for a demonstration that presses it. */\n  isReloadPressed?: boolean;\n  /** Shows the console toggle held down, for a demonstration that presses it. */\n  isConsolePressed?: boolean;\n  className?: string;\n};\n\nexport function SandboxPreview({\n  address,\n  view,\n  onViewChange,\n  isReloading,\n  onReload,\n  isConsoleOpen,\n  onConsoleOpenChange,\n  lines,\n  children,\n  isReloadPressed = false,\n  isConsolePressed = false,\n  className,\n}: SandboxPreviewProps) {\n  const consoleId = useId();\n  const lineCount = lines.length;\n\n  function toggleConsole() {\n    onConsoleOpenChange(!isConsoleOpen);\n  }\n\n  return (\n    <section\n      aria-label='Sandbox preview'\n      className={cn(\n        'bg-card hairline-ring ring-border @container flex flex-col gap-3 rounded-xl p-3 shadow-[0_1px_2px_rgb(0_0_0/0.04)]',\n        className\n      )}\n    >\n      <div className='flex flex-wrap items-center gap-2'>\n        <Button\n          type='button'\n          variant='ghost'\n          size='icon-sm'\n          aria-label='Reload the preview'\n          onClick={onReload}\n          className={cn(\n            'text-muted-foreground',\n            pressedQuietOf(isReloadPressed)\n          )}\n        >\n          <RefreshCwIcon className={spinOf(isReloading)} />\n        </Button>\n        <div className='bg-foreground/[0.05] dark:bg-foreground/[0.07] flex h-7 min-w-0 flex-1 basis-40 items-center gap-2 rounded-md px-2.5'>\n          <span\n            aria-hidden='true'\n            className='bg-success size-1.5 shrink-0 rounded-full'\n          />\n          <span className='min-w-0 truncate font-mono text-xs'>{address}</span>\n        </div>\n        <Segments\n          value={view}\n          segments={VIEWS}\n          onValueChange={onViewChange}\n          label='Preview width'\n        />\n      </div>\n      <div className='bg-foreground/[0.04] dark:bg-foreground/[0.06] relative flex h-[19rem] justify-center overflow-hidden rounded-lg p-3'>\n        <ReloadLine isReloading={isReloading} />\n        <div\n          role='img'\n          aria-label={frameLabelOf(view)}\n          className={cn(\n            'hairline-ring ring-border bg-background @container h-full max-w-full overflow-hidden shadow-[0_1px_2px_rgb(0_0_0/0.06)] transition-[width,border-radius] duration-300 ease-(--ease-out-strong) motion-reduce:transition-none',\n            FRAME_SIZE[view]\n          )}\n        >\n          {children}\n        </div>\n      </div>\n      <div className='flex flex-col'>\n        <button\n          type='button'\n          aria-expanded={isConsoleOpen}\n          aria-controls={consoleId}\n          onClick={toggleConsole}\n          className={cn(\n            'text-muted-foreground hover:text-foreground focus-visible:ring-ring/25 flex h-8 w-full cursor-pointer items-center gap-2 rounded-md px-1 text-xs transition-[color,scale] outline-none focus-visible:ring-[3px]',\n            pressedQuietOf(isConsolePressed)\n          )}\n        >\n          <TerminalIcon className='size-3.5' />\n          Console\n          <Badge variant='secondary' className='tabular-nums'>\n            {lineCount}\n          </Badge>\n          <ChevronDownIcon\n            className={cn(\n              'ms-auto size-3.5 transition-transform duration-200 ease-(--ease-out-strong)',\n              chevronTurnOf(isConsoleOpen)\n            )}\n          />\n        </button>\n        <Fold open={isConsoleOpen} id={consoleId}>\n          <ConsoleLines lines={lines} />\n        </Fold>\n      </div>\n    </section>\n  );\n}\n\nconst ADDRESS = 'localhost:3000/pricing';\n\nconst RELOAD_MS = 900;\n\nconst MAX_LINES = 4;\n\nconst EDIT_FILES = ['src/pricing/plan-card.tsx', 'src/pricing/cta.tsx'];\n\ntype SandboxState = {\n  view: PreviewView;\n  isConsoleOpen: boolean;\n  isReloading: boolean;\n  editCount: number;\n  lines: ConsoleLine[];\n  nextLineId: number;\n};\n\ntype SandboxAction =\n  | { type: 'edit' }\n  | { type: 'reload' }\n  | { type: 'reloaded' }\n  | { type: 'view'; view: PreviewView }\n  | { type: 'console'; isOpen: boolean }\n  | { type: 'hold' };\n\ntype SandboxStep = SessionStep<SandboxState, SandboxAction>;\n\nconst INITIAL: SandboxState = {\n  view: 'desktop',\n  isConsoleOpen: false,\n  isReloading: false,\n  editCount: 0,\n  lines: [\n    { id: 1, tone: 'info', text: 'ready on http://localhost:3000' },\n    { id: 2, tone: 'info', text: 'compiled /pricing in 412 ms' },\n  ],\n  nextLineId: 3,\n};\n\nfunction withLine(\n  state: SandboxState,\n  tone: ConsoleTone,\n  text: string\n): SandboxState {\n  const line: ConsoleLine = { id: state.nextLineId, tone, text };\n  const lines = [...state.lines, line].slice(-MAX_LINES);\n  return { ...state, lines, nextLineId: state.nextLineId + 1 };\n}\n\nfunction edited(state: SandboxState): SandboxState {\n  const file = EDIT_FILES[state.editCount];\n  if (!file) {\n    return state;\n  }\n  const next = withLine(state, 'hot', `hot update: ${file}`);\n  return { ...next, editCount: state.editCount + 1 };\n}\n\nfunction reloaded(state: SandboxState): SandboxState {\n  if (!state.isReloading) {\n    return state;\n  }\n  const next = withLine(state, 'info', 'page reloaded in 380 ms');\n  return { ...next, isReloading: false };\n}\n\nfunction reducer(state: SandboxState, action: SandboxAction): SandboxState {\n  switch (action.type) {\n    case 'edit':\n      return edited(state);\n    case 'reload':\n      return { ...state, isReloading: true };\n    case 'reloaded':\n      return reloaded(state);\n    case 'view':\n      return { ...state, view: action.view };\n    case 'console':\n      return { ...state, isConsoleOpen: action.isOpen };\n    case 'hold':\n      return state;\n  }\n}\n\nconst SCRIPT: SandboxStep[] = [\n  { after: 1800, action: { type: 'edit' } },\n  {\n    after: 1700,\n    by: 'demo',\n    press: 'reload',\n    action: { type: 'reload' },\n  },\n  { after: RELOAD_MS, action: { type: 'reloaded' } },\n  {\n    after: 1400,\n    by: 'demo',\n    action: { type: 'view', view: 'mobile' },\n  },\n  {\n    after: 1500,\n    by: 'demo',\n    press: 'console',\n    action: { type: 'console', isOpen: true },\n  },\n  { after: 1500, action: { type: 'edit' } },\n  { after: 4500, action: { type: 'hold' } },\n];\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: restingOf(INITIAL, SCRIPT, reducer),\n  script: SCRIPT,\n  loopAfter: 3000,\n};\n\nfunction announcementOf(state: SandboxState) {\n  const last = state.lines[state.lines.length - 1];\n  if (!last) {\n    return '';\n  }\n  return last.text;\n}\n\nexport default function Run13() {\n  const { schedule, clearAll } = useTimeouts();\n  const {\n    ref,\n    isInView,\n    isAutoplaying,\n    state,\n    act,\n    pressed,\n    isFinished,\n    restart,\n  } = useSession(SESSION);\n  const canReplay = isFinished && !isAutoplaying;\n  const announcement = announcementOf(state);\n\n  function reload() {\n    act({ type: 'reload' });\n    schedule(() => act({ type: 'reloaded' }), RELOAD_MS);\n  }\n\n  function changeView(view: PreviewView) {\n    act({ type: 'view', view });\n  }\n\n  function changeConsole(isOpen: boolean) {\n    act({ type: 'console', isOpen });\n  }\n\n  function replay() {\n    clearAll();\n    restart();\n  }\n\n  useKeptHeight(ref);\n\n  return (\n    <div\n      ref={ref}\n      className='flex min-h-[30rem] w-full max-w-[40rem] flex-col gap-2'\n    >\n      <ClockGate isActive={isInView}>\n        <SandboxPreview\n          address={ADDRESS}\n          view={state.view}\n          onViewChange={changeView}\n          isReloading={state.isReloading}\n          onReload={reload}\n          isConsoleOpen={state.isConsoleOpen}\n          onConsoleOpenChange={changeConsole}\n          lines={state.lines}\n          isReloadPressed={pressed === 'reload'}\n          isConsolePressed={pressed === 'console'}\n        >\n          <div inert className='h-full'>\n            <PricingPage editCount={state.editCount} />\n          </div>\n        </SandboxPreview>\n      </ClockGate>\n      <div className='flex h-7 items-center justify-end'>\n        <ReplayButton isShown={canReplay} onReplay={replay} />\n      </div>\n      <LiveRegion message={spokenUnless(isAutoplaying, announcement)} />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/run/run-13.tsx"
    },
    {
      "path": "registry/ndeko/components/run/_parts/pricing-page.tsx",
      "content": "import { CheckIcon } from '@/registry/ndeko/lib/icons';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { Chip } from '@/registry/ndeko/ui/chip';\nimport { CompanyMark } from '@/registry/ndeko/ui/company-mark';\n\ntype Plan = {\n  id: string;\n  name: string;\n  price: string;\n  features: string[];\n};\n\nconst PLANS: Plan[] = [\n  {\n    id: 'team',\n    name: 'Team',\n    price: '$12',\n    features: ['Up to 25 seats', 'Shared dashboards', 'Email support'],\n  },\n  {\n    id: 'business',\n    name: 'Business',\n    price: '$29',\n    features: ['Unlimited seats', 'Single sign-on', 'Priority support'],\n  },\n];\n\nconst NAV_LINKS = ['Product', 'Pricing', 'Docs'];\n\nfunction teamButtonOf(editCount: number) {\n  if (editCount >= 2) {\n    return 'Start free trial';\n  }\n  return 'Start trial';\n}\n\nfunction buttonLabelOf(plan: Plan, editCount: number) {\n  if (plan.id === 'team') {\n    return teamButtonOf(editCount);\n  }\n  return 'Talk to us';\n}\n\nfunction isMostChosen(plan: Plan, editCount: number) {\n  const isTeam = plan.id === 'team';\n  const hasEdit = editCount >= 1;\n  return isTeam && hasEdit;\n}\n\nfunction buttonVariantOf(isFeatured: boolean) {\n  if (isFeatured) {\n    return 'default';\n  }\n  return 'outline';\n}\n\nfunction PlanCard({ plan, editCount }: { plan: Plan; editCount: number }) {\n  const label = buttonLabelOf(plan, editCount);\n  const showsBadge = isMostChosen(plan, editCount);\n  const variant = buttonVariantOf(showsBadge);\n\n  return (\n    <li className='bg-card hairline-ring ring-border flex flex-col gap-2 rounded-lg p-3'>\n      <div className='flex items-center justify-between gap-2'>\n        <span className='text-[13px] font-medium'>{plan.name}</span>\n        {showsBadge && (\n          <Chip className='transition-[opacity,scale] duration-200 ease-(--ease-out-strong) starting:scale-95 starting:opacity-0'>\n            Most chosen\n          </Chip>\n        )}\n      </div>\n      <p className='flex items-baseline gap-1'>\n        <span className='text-xl font-semibold tabular-nums'>{plan.price}</span>\n        <span className='text-muted-foreground text-xs'>\n          per seat, per month\n        </span>\n      </p>\n      <ul className='text-muted-foreground flex flex-col gap-1 text-xs'>\n        {plan.features.map((feature) => (\n          <li key={feature} className='flex items-center gap-1.5'>\n            <CheckIcon className='text-success-foreground size-3 shrink-0' />\n            {feature}\n          </li>\n        ))}\n      </ul>\n      <Button\n        type='button'\n        size='sm'\n        variant={variant}\n        className='mt-1 self-start'\n      >\n        <Swap swapKey={label}>{label}</Swap>\n      </Button>\n    </li>\n  );\n}\n\ntype PricingPageProps = {\n  /** How many edits the agent has made to the page so far. */\n  editCount: number;\n};\n\n/** A small pricing page drawn in HTML, so the preview is something an agent could be building. */\nexport function PricingPage({ editCount }: PricingPageProps) {\n  return (\n    <div className='bg-background text-foreground flex h-full flex-col gap-4 p-3'>\n      <nav className='flex items-center gap-3'>\n        <CompanyMark seed='Larkfield' size='sm' />\n        <span className='text-[13px] font-medium'>Larkfield</span>\n        <span className='text-muted-foreground ms-2 hidden items-center gap-3 text-xs @md:flex'>\n          {NAV_LINKS.map((link) => (\n            <span key={link}>{link}</span>\n          ))}\n        </span>\n        <span className='text-muted-foreground ms-auto text-xs'>Sign in</span>\n      </nav>\n      <header className='flex flex-col gap-1'>\n        <h4 className='text-[15px] font-semibold text-balance @lg:text-lg'>\n          Simple pricing for small teams\n        </h4>\n        <p className='text-muted-foreground text-xs'>\n          Change plans any time. Illustrative prices.\n        </p>\n      </header>\n      <ul className='grid grid-cols-1 gap-2 @lg:grid-cols-2'>\n        {PLANS.map((plan) => (\n          <PlanCard key={plan.id} plan={plan} editCount={editCount} />\n        ))}\n      </ul>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/run/_parts/pricing-page.tsx"
    }
  ],
  "categories": [
    "components",
    "run"
  ],
  "type": "registry:component"
}