{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "illustration-01",
  "title": "Model orbit",
  "description": "Model marks turning around an agent, where the link glides to the next model at each hand-over and the label under the agent rolls to its name.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/brand-logos.json",
    "https://ui.ndekocode.dev/r/brand-tile.json",
    "https://ui.ndekocode.dev/r/mesh-tile.json",
    "https://ui.ndekocode.dev/r/motion-word-roll.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-01.tsx",
      "content": "'use client';\n\nimport { useMemo, useState } from 'react';\n\nimport { WordRoll } from '@/components/core/word-roll';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { BrandTile } from '@/registry/ndeko/ui/brand-tile';\nimport { MeshTile } from '@/registry/ndeko/ui/mesh-tile';\n\nimport { nearestAngleOf, percentOf, radiansOf } from './_parts/geometry';\nimport {\n  CHATGPT,\n  CLAUDE,\n  DEEPSEEK,\n  GEMINI,\n  MISTRAL,\n  type SceneModel,\n} from './_parts/models';\nimport { useSceneFrames, type SceneFrame } from './_parts/use-scene-frames';\nimport { useScenePlay } from './_parts/use-scene-play';\n\ntype Link = {\n  index: number;\n  angle: number;\n};\n\ntype TurnStyle = {\n  animationDuration: string;\n  animationPlayState: 'running' | 'paused';\n  animationDirection: 'normal' | 'reverse';\n};\n\nconst FULL_TURN_DEG = 360;\n\nconst TOP_OF_ORBIT_DEG = -90;\n\nconst DEFAULT_ORBIT_SECONDS = 48;\n\nconst DEFAULT_HAND_OVER_MS = 3200;\n\nfunction slotAngleOf(index: number, count: number) {\n  const step = FULL_TURN_DEG / count;\n  return TOP_OF_ORBIT_DEG + step * index;\n}\n\nfunction slotPlaceOf(index: number, count: number) {\n  const degrees = slotAngleOf(index, count);\n  const angle = radiansOf(degrees);\n  const across = 0.5 + Math.cos(angle) * 0.5;\n  const down = 0.5 + Math.sin(angle) * 0.5;\n  return { left: percentOf(across), top: percentOf(down) };\n}\n\nfunction playStateOf(isPlaying: boolean) {\n  if (isPlaying) {\n    return 'running';\n  }\n  return 'paused';\n}\n\n/** One frame per model, in orbit order. An orbit with no model still gets its resting frame. */\nfunction handOversOf(count: number, holdMs: number) {\n  const frameCount = Math.max(count, 1);\n  const frames: SceneFrame<number>[] = [];\n  for (let index = 0; index < frameCount; index += 1) {\n    frames.push({ state: index, holdMs });\n  }\n  return frames;\n}\n\nfunction labelOf(agentName: string, models: SceneModel[], active: SceneModel) {\n  const names = models.map((model) => model.name);\n  const list = names.join(', ');\n  return `${agentName} can hand a step to ${list}. It is using ${active.name}`;\n}\n\nexport type ModelOrbitProps = {\n  /** The agent at the centre. Its picture is drawn from this name. */\n  agentName: string;\n  models: SceneModel[];\n  /** Milliseconds the agent stays on one model before it hands over to the next. */\n  handOverMs?: number;\n  /** Seconds for one turn of the orbit. */\n  orbitSeconds?: number;\n  className?: string;\n};\n\nexport function ModelOrbit({\n  agentName,\n  models,\n  handOverMs = DEFAULT_HAND_OVER_MS,\n  orbitSeconds = DEFAULT_ORBIT_SECONDS,\n  className,\n}: ModelOrbitProps) {\n  const { ref, isPlaying, isStill } = useScenePlay();\n  const count = models.length;\n  const handOvers = useMemo(\n    () => handOversOf(count, handOverMs),\n    [count, handOverMs]\n  );\n  const activeIndex = useSceneFrames(handOvers, { isPlaying, isStill });\n  const [link, setLink] = useState<Link>({\n    index: 0,\n    angle: TOP_OF_ORBIT_DEG,\n  });\n  const active = models[activeIndex];\n\n  const hasHandedOver = link.index !== activeIndex;\n  if (hasHandedOver) {\n    const slotCount = Math.max(count, 1);\n    const target = slotAngleOf(activeIndex, slotCount);\n    const angle = nearestAngleOf(target, link.angle);\n    setLink({ index: activeIndex, angle });\n  }\n\n  if (!active) {\n    return null;\n  }\n\n  const names = models.map((model) => model.name);\n  const turn: TurnStyle = {\n    animationDuration: `${orbitSeconds}s`,\n    animationPlayState: playStateOf(isPlaying),\n    animationDirection: 'normal',\n  };\n  const counterTurn: TurnStyle = { ...turn, animationDirection: 'reverse' };\n\n  return (\n    <div\n      ref={ref}\n      role='img'\n      aria-label={labelOf(agentName, models, active)}\n      className={cn('relative aspect-square w-full max-w-[20rem]', className)}\n    >\n      <div\n        style={turn}\n        className='hairline-ring ring-border absolute inset-[12%] animate-spin rounded-full motion-reduce:animate-none'\n      >\n        <span\n          style={{ transform: `rotate(${link.angle}deg)` }}\n          className='from-primary/0 to-primary absolute top-1/2 left-1/2 -mt-px h-0.5 w-1/2 origin-left rounded-full bg-linear-to-r transition-transform duration-700 ease-(--ease-in-out-strong)'\n        />\n        {models.map((model, index) => (\n          <span\n            key={model.id}\n            style={slotPlaceOf(index, count)}\n            className='absolute -translate-x-1/2 -translate-y-1/2'\n          >\n            <span\n              style={counterTurn}\n              className='relative block animate-spin motion-reduce:animate-none'\n            >\n              <span\n                data-active={index === activeIndex}\n                className='ring-primary absolute -inset-1 rounded-[14px] opacity-0 ring-[1.5px] transition-opacity duration-300 ease-(--ease-out-strong) data-[active=true]:opacity-100'\n              />\n              <BrandTile brand={model.brand} size='2xl' />\n            </span>\n          </span>\n        ))}\n      </div>\n      <MeshTile\n        seed={agentName}\n        color='var(--primary)'\n        className='absolute top-1/2 left-1/2 size-12 -translate-x-1/2 -translate-y-1/2 rounded-[14px]'\n      />\n      <p className='bg-card hairline-ring ring-border absolute top-1/2 left-1/2 mt-9 flex h-6 -translate-x-1/2 items-center gap-1 rounded-full px-2.5 text-xs whitespace-nowrap shadow-[0_1px_2px_rgb(0_0_0/0.04)]'>\n        <span className='text-muted-foreground'>via</span>\n        <WordRoll text={active.name} labels={names} className='font-medium' />\n      </p>\n    </div>\n  );\n}\n\nconst MODELS: SceneModel[] = [CLAUDE, CHATGPT, GEMINI, MISTRAL, DEEPSEEK];\n\nexport default function Illustration01() {\n  return <ModelOrbit agentName='Planner' models={MODELS} />;\n}\n",
      "type": "registry:component",
      "target": "components/illustration/illustration-01.tsx"
    },
    {
      "path": "registry/ndeko/components/illustration/_parts/geometry.ts",
      "content": "export type ScenePoint = {\n  /** Share of the stage width, from 0 to 1. */\n  x: number;\n  /** Share of the stage height, from 0 to 1. */\n  y: number;\n};\n\nexport type SceneSpan = {\n  /** Length of the line as a percentage of the stage width. */\n  lengthPercent: number;\n  /** Angle of the line in degrees, clockwise from the right, as CSS turns it. */\n  angleDeg: number;\n};\n\nconst HALF_TURN_DEG = 180;\n\nconst FULL_TURN_DEG = 360;\n\n/**\n * Two engines can disagree on the last digit of a sine. A value written into a style is rounded, so\n * the server and the browser print the same text.\n */\nexport function rounded(value: number) {\n  const hundredths = Math.round(value * 100);\n  return hundredths / 100;\n}\n\nexport function percentOf(share: number) {\n  const percent = rounded(share * 100);\n  return `${percent}%`;\n}\n\nexport function degreesOf(radians: number) {\n  return (radians * HALF_TURN_DEG) / Math.PI;\n}\n\nexport function radiansOf(degrees: number) {\n  return (degrees * Math.PI) / HALF_TURN_DEG;\n}\n\n/** The angle equal to `target` that is closest to `current`, so a turn towards it goes the short way round. */\nexport function nearestAngleOf(target: number, current: number) {\n  const difference = target - current;\n  const turns = Math.round(difference / FULL_TURN_DEG);\n  const wrapped = difference - FULL_TURN_DEG * turns;\n  return current + wrapped;\n}\n\n/** The line between two points of a stage that is `aspect` times wider than it is tall. */\nexport function spanBetween(\n  from: ScenePoint,\n  to: ScenePoint,\n  aspect: number\n): SceneSpan {\n  const acrossShare = to.x - from.x;\n  const downShare = to.y - from.y;\n  const downInWidths = downShare / aspect;\n  const lengthInWidths = Math.hypot(acrossShare, downInWidths);\n  const angle = Math.atan2(downInWidths, acrossShare);\n  const degrees = degreesOf(angle);\n  return {\n    lengthPercent: rounded(lengthInWidths * 100),\n    angleDeg: rounded(degrees),\n  };\n}\n\n/** Where a tile centred on a point of the stage goes: its `left` and `top`. */\nexport function placeOf(point: ScenePoint) {\n  return { left: percentOf(point.x), top: percentOf(point.y) };\n}\n",
      "type": "registry:component",
      "target": "components/illustration/_parts/geometry.ts"
    },
    {
      "path": "registry/ndeko/components/illustration/_parts/models.ts",
      "content": "import type { BrandSlug } from '@/registry/ndeko/lib/brand-logos';\n\nexport type SceneModel = {\n  id: string;\n  /** The name people call the model by, without a version number. */\n  name: string;\n  brand: BrandSlug;\n};\n\nexport const CLAUDE: SceneModel = {\n  id: 'claude',\n  name: 'Claude',\n  brand: 'claude',\n};\n\nexport const CHATGPT: SceneModel = {\n  id: 'chatgpt',\n  name: 'ChatGPT',\n  brand: 'openai',\n};\n\nexport const GEMINI: SceneModel = {\n  id: 'gemini',\n  name: 'Gemini',\n  brand: 'gemini',\n};\n\nexport const MISTRAL: SceneModel = {\n  id: 'mistral',\n  name: 'Mistral',\n  brand: 'mistral',\n};\n\nexport const DEEPSEEK: SceneModel = {\n  id: 'deepseek',\n  name: 'DeepSeek',\n  brand: 'deepseek',\n};\n\nexport const LLAMA: SceneModel = {\n  id: 'llama',\n  name: 'Llama',\n  brand: 'meta',\n};\n\nexport const GROK: SceneModel = {\n  id: 'grok',\n  name: 'Grok',\n  brand: 'grok',\n};\n\nexport const QWEN: SceneModel = {\n  id: 'qwen',\n  name: 'Qwen',\n  brand: 'qwen',\n};\n\nexport const COMMAND: SceneModel = {\n  id: 'command',\n  name: 'Command',\n  brand: 'cohere',\n};\n\nexport const SONAR: SceneModel = {\n  id: 'sonar',\n  name: 'Sonar',\n  brand: 'perplexity',\n};\n",
      "type": "registry:component",
      "target": "components/illustration/_parts/models.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"
}