{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "illustration-08",
  "title": "Vector search",
  "description": "Retrieval told in five chapters on a step bar that fills as it plays, where chunks fly into topic clusters and a question walks the links to its nearest chunks before the ranked sources slide in.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/agent-run.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/icons.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/motion-presets.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-08.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport {\n  useEffect,\n  useEffectEvent,\n  useLayoutEffect,\n  useRef,\n  useState,\n} from 'react';\n\nimport { seriesColorOf, type SeriesSlot } from '@/registry/ndeko/lib/agent-run';\nimport { spokenUnless } from '@/registry/ndeko/lib/demonstration';\nimport { PauseIcon, PlayIcon } from '@/registry/ndeko/lib/icons';\nimport { risePresenceOf } from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\n\nimport { delayWhile } from './_parts/delay';\nimport { degreesOf, rounded } from './_parts/geometry';\nimport { useScenePlay } from './_parts/use-scene-play';\n\ntype Chapter = {\n  id: string;\n  label: string;\n  caption: string;\n  durationMs: number;\n};\n\n/** A place on the stage, in hundredths of its width on both axes. */\ntype Place = {\n  x: number;\n  y: number;\n};\n\ntype Chunk = {\n  id: string;\n  documentIndex: number;\n  row: number;\n  topic: number;\n  home: Place;\n  plane: Place;\n};\n\ntype Hop = {\n  from: Place;\n  to: Place;\n  leavesMs: number;\n  arrivesMs: number;\n};\n\ntype Result = {\n  chunkId: string;\n  documentIndex: number;\n  chunkNumber: number;\n  score: number;\n};\n\nconst CHAPTERS: Chapter[] = [\n  {\n    id: 'chunk',\n    label: 'Chunk',\n    caption: 'Each document is cut into chunks small enough to embed',\n    durationMs: 2800,\n  },\n  {\n    id: 'embed',\n    label: 'Embed',\n    caption:\n      'Every chunk becomes a point, and points about one topic land together',\n    durationMs: 3000,\n  },\n  {\n    id: 'index',\n    label: 'Index',\n    caption:\n      'Each point is linked to its nearest neighbours, so a search can walk',\n    durationMs: 2800,\n  },\n  {\n    id: 'query',\n    label: 'Query',\n    caption:\n      'The question becomes a point too, and the search walks the links towards it',\n    durationMs: 3800,\n  },\n  {\n    id: 'rank',\n    label: 'Rank',\n    caption: 'The closest chunks come back as sources, ranked by how near',\n    durationMs: 3400,\n  },\n];\n\nconst CHUNK_CHAPTER = 0;\n\nconst EMBED_CHAPTER = 1;\n\nconst INDEX_CHAPTER = 2;\n\nconst QUERY_CHAPTER = 3;\n\nconst RANK_CHAPTER = 4;\n\nconst TOPIC_SERIES: SeriesSlot[] = [1, 2, 4];\n\nconst TOPIC_CENTRES: Place[] = [\n  { x: 48, y: 19.5 },\n  { x: 80, y: 24 },\n  { x: 62, y: 45 },\n];\n\nconst HALO_RADIUS = 9.5;\n\n/** Where the four chunks of a topic sit around its centre. */\nconst TOPIC_SPREAD: Place[][] = [\n  [\n    { x: -4.5, y: -2.5 },\n    { x: 3.5, y: -4 },\n    { x: -1.5, y: 3.5 },\n    { x: 5, y: 2 },\n  ],\n  [\n    { x: -4, y: -3 },\n    { x: 4, y: -2.5 },\n    { x: -2.5, y: 4 },\n    { x: 4.5, y: 3.5 },\n  ],\n  [\n    { x: -5, y: -1.5 },\n    { x: 0.5, y: -4.5 },\n    { x: 4.5, y: 1 },\n    { x: -1, y: 4 },\n  ],\n];\n\n/** For each document, the topic of each of its four chunks and its seat in that topic. A document is mostly about one topic. */\nconst CHUNK_SEATS = [\n  [\n    [0, 0],\n    [0, 1],\n    [1, 0],\n    [2, 0],\n  ],\n  [\n    [1, 1],\n    [1, 2],\n    [0, 2],\n    [2, 1],\n  ],\n  [\n    [2, 2],\n    [2, 3],\n    [1, 3],\n    [0, 3],\n  ],\n];\n\n/** Links between seats, as topic and seat on both ends: four inside each topic, then three bridges. */\nconst LINK_SEATS = [\n  [0, 0, 0, 1],\n  [0, 0, 0, 2],\n  [0, 1, 0, 3],\n  [0, 2, 0, 3],\n  [1, 0, 1, 1],\n  [1, 0, 1, 2],\n  [1, 1, 1, 3],\n  [1, 2, 1, 3],\n  [2, 0, 2, 1],\n  [2, 0, 2, 2],\n  [2, 1, 2, 3],\n  [2, 2, 2, 3],\n  [0, 3, 2, 1],\n  [0, 1, 1, 0],\n  [2, 2, 1, 2],\n];\n\nconst DOCUMENT_LEFT = 3;\n\nconst DOCUMENT_TOPS = [3.5, 23, 42.5];\n\nconst DOCUMENT_WIDTH = 24;\n\nconst DOCUMENT_HEIGHT = 16.5;\n\nconst LINE_LEFT = 5.5;\n\nconst FIRST_LINE = 7.45;\n\nconst LINE_PITCH = 2;\n\n/** Cut apart, the four lines of a document sit this much further from each other. */\nconst SPLIT_SPREAD = 1.2;\n\nconst SPLIT_AFTER_MS = 900;\n\nconst FLIGHT_STAGGER_MS = 45;\n\nconst LINK_STAGGER_MS = 70;\n\nconst RESULTS_AFTER_MS = 120;\n\nconst RESULT_STAGGER_MS = 90;\n\nconst QUESTION: Place = { x: 58, y: 52.5 };\n\nconst WALK_MS = 2600;\n\nconst WALKER_SHOWS_MS = 500;\n\nconst WALK_EASE = 'cubic-bezier(0.65, 0, 0.35, 1)';\n\nfunction seatPlaceOf(topic: number, seat: number): Place {\n  const centre = TOPIC_CENTRES[topic];\n  const spread = TOPIC_SPREAD[topic][seat];\n  return { x: centre.x + spread.x, y: centre.y + spread.y };\n}\n\nfunction homeOf(documentIndex: number, row: number): Place {\n  const top = DOCUMENT_TOPS[documentIndex];\n  const firstLine = top + FIRST_LINE;\n  return { x: LINE_LEFT, y: firstLine + row * LINE_PITCH };\n}\n\nfunction chunksOf() {\n  const chunks: Chunk[] = [];\n  CHUNK_SEATS.forEach((seats, documentIndex) => {\n    seats.forEach(([topic, seat], row) => {\n      chunks.push({\n        id: `${documentIndex}-${row}`,\n        documentIndex,\n        row,\n        topic,\n        home: homeOf(documentIndex, row),\n        plane: seatPlaceOf(topic, seat),\n      });\n    });\n  });\n  return chunks;\n}\n\nconst CHUNKS = chunksOf();\n\n/** The search enters the graph far from the question and follows a link at each step to a point that is nearer. */\nconst WALK: Hop[] = [\n  {\n    from: seatPlaceOf(0, 1),\n    to: seatPlaceOf(0, 3),\n    leavesMs: 800,\n    arrivesMs: 1150,\n  },\n  {\n    from: seatPlaceOf(0, 3),\n    to: seatPlaceOf(2, 1),\n    leavesMs: 1400,\n    arrivesMs: 1850,\n  },\n  {\n    from: seatPlaceOf(2, 1),\n    to: seatPlaceOf(2, 3),\n    leavesMs: 2100,\n    arrivesMs: 2450,\n  },\n];\n\nconst WALK_START = WALK[0].from;\n\nconst WALK_END = WALK[WALK.length - 1].to;\n\n/** The three chunks nearest the question, nearest first. The scores are illustrative. */\nconst RESULTS: Result[] = [\n  { chunkId: '2-1', documentIndex: 2, chunkNumber: 2, score: 0.92 },\n  { chunkId: '0-3', documentIndex: 0, chunkNumber: 4, score: 0.87 },\n  { chunkId: '2-0', documentIndex: 2, chunkNumber: 1, score: 0.81 },\n];\n\nconst NEAREST_IDS = RESULTS.map((result) => result.chunkId);\n\nfunction lengthOf(value: number) {\n  return `${rounded(value)}cqw`;\n}\n\nfunction translateOf(place: Place) {\n  return `${lengthOf(place.x)} ${lengthOf(place.y)}`;\n}\n\nfunction cornerOf(place: Place) {\n  return { left: lengthOf(place.x), top: lengthOf(place.y) };\n}\n\nconst HALO_SIZE = lengthOf(HALO_RADIUS * 2);\n\nconst HALO_TOP = lengthOf(-HALO_RADIUS);\n\nconst DOCUMENT_SIZE = {\n  width: lengthOf(DOCUMENT_WIDTH),\n  height: lengthOf(DOCUMENT_HEIGHT),\n};\n\nfunction documentCornerOf(documentIndex: number) {\n  return cornerOf({ x: DOCUMENT_LEFT, y: DOCUMENT_TOPS[documentIndex] });\n}\n\nfunction formatScore(score: number) {\n  return score.toFixed(2);\n}\n\nfunction resultDelayOf(index: number) {\n  return RESULTS_AFTER_MS + index * RESULT_STAGGER_MS;\n}\n\nfunction drawnScaleOf(isDrawn: boolean) {\n  if (isDrawn) {\n    return 1;\n  }\n  return 0;\n}\n\n/**\n * A line from one place to another that draws itself from its first end. The turn and the growth\n * share one transform, in that order, so the line grows along its own direction.\n */\nfunction segmentStyleOf(from: Place, to: Place, isDrawn: boolean) {\n  const across = to.x - from.x;\n  const down = to.y - from.y;\n  const length = Math.hypot(across, down);\n  const radians = Math.atan2(down, across);\n  const degrees = degreesOf(radians);\n  const angle = rounded(degrees);\n  const scale = drawnScaleOf(isDrawn);\n  return {\n    ...cornerOf(from),\n    width: lengthOf(length),\n    transform: `rotate(${angle}deg) scaleX(${scale})`,\n  };\n}\n\nfunction shareOf(timeMs: number) {\n  return rounded(timeMs / WALK_MS);\n}\n\n/** The walker fades in on the point where the search enters, then steps from point to point and waits on each. */\nfunction walkKeyframesOf(): Keyframe[] {\n  const start = translateOf(WALK_START);\n  const frames: Keyframe[] = [\n    { offset: 0, translate: start, opacity: 0 },\n    { offset: shareOf(WALKER_SHOWS_MS), translate: start, opacity: 0 },\n  ];\n  for (const hop of WALK) {\n    frames.push({\n      offset: shareOf(hop.leavesMs),\n      translate: translateOf(hop.from),\n      opacity: 1,\n      easing: WALK_EASE,\n    });\n    frames.push({\n      offset: shareOf(hop.arrivesMs),\n      translate: translateOf(hop.to),\n      opacity: 1,\n    });\n  }\n  frames.push({ offset: 1, translate: translateOf(WALK_END), opacity: 1 });\n  return frames;\n}\n\nconst WALK_KEYFRAMES = walkKeyframesOf();\n\nfunction splitOf(isSplit: boolean, row: number) {\n  if (!isSplit) {\n    return '0cqw 0cqw';\n  }\n  const fromMiddle = row - 1.5;\n  return `0cqw ${lengthOf(fromMiddle * SPLIT_SPREAD)}`;\n}\n\nfunction placeOfChunk(chunk: Chunk, isEmbedded: boolean) {\n  if (isEmbedded) {\n    return chunk.plane;\n  }\n  return chunk.home;\n}\n\nfunction nextChapterOf(chapter: number) {\n  const next = chapter + 1;\n  return next % CHAPTERS.length;\n}\n\nfunction currentStepOf(isCurrent: boolean) {\n  if (isCurrent) {\n    return 'step';\n  }\n  return undefined;\n}\n\nfunction playLabelOf(isPaused: boolean) {\n  if (isPaused) {\n    return 'Play';\n  }\n  return 'Pause';\n}\n\nfunction stepLabelOf(chapter: Chapter, index: number) {\n  const position = index + 1;\n  return `${chapter.label}, chapter ${position} of ${CHAPTERS.length}`;\n}\n\n/**\n * The chapter clock is not all that moves: a walk or a flight can still be under way. Paused or off\n * screen, all of it holds where it is, and it goes on from there. Under reduced motion nothing is\n * held: the theme already keeps transitions to fades.\n */\nfunction holdStage(stage: HTMLElement, isHeld: boolean) {\n  const animations = stage.getAnimations({ subtree: true });\n  for (const animation of animations) {\n    if (isHeld) {\n      animation.pause();\n      continue;\n    }\n    const wasHeld = animation.playState === 'paused';\n    if (wasHeld) {\n      animation.play();\n    }\n  }\n}\n\n/** A jump lands on its chapter: whatever was held half way from the chapter before ends where it was going. */\nfunction finishHeld(stage: HTMLElement) {\n  const animations = stage.getAnimations({ subtree: true });\n  for (const animation of animations) {\n    const isHeld = animation.playState === 'paused';\n    if (isHeld) {\n      animation.finish();\n    }\n  }\n}\n\ntype ChapterFillProps = {\n  durationMs: number;\n  isRunning: boolean;\n  onDone: () => void;\n};\n\nconst EMPTY_BAR = 'scaleX(0)';\n\nconst FULL_BAR = 'scaleX(1)';\n\n/**\n * The bar of the chapter that plays is also its clock: it fills once over the length of the chapter\n * and its end starts the next one. Paused, it holds its place and nothing else keeps time. The empty\n * bar is an inline transform, the property the animation writes: a scale utility would multiply\n * with it and keep the bar empty.\n */\nfunction ChapterFill({ durationMs, isRunning, onDone }: ChapterFillProps) {\n  const barRef = useRef<HTMLSpanElement>(null);\n  const fillRef = useRef<Animation | null>(null);\n  const finish = useEffectEvent(onDone);\n\n  useEffect(() => {\n    const bar = barRef.current;\n    if (!bar) {\n      return;\n    }\n    const fill = bar.animate(\n      [{ transform: EMPTY_BAR }, { transform: FULL_BAR }],\n      { duration: durationMs, easing: 'linear', fill: 'forwards' }\n    );\n    fill.pause();\n    fill.onfinish = () => finish();\n    fillRef.current = fill;\n    return () => {\n      fill.onfinish = null;\n      fill.cancel();\n      fillRef.current = null;\n    };\n  }, [durationMs]);\n\n  useEffect(() => {\n    const fill = fillRef.current;\n    if (!fill) {\n      return;\n    }\n    if (isRunning) {\n      fill.play();\n      return;\n    }\n    fill.pause();\n  }, [isRunning]);\n\n  return (\n    <span\n      ref={barRef}\n      style={{ transform: EMPTY_BAR }}\n      className='bg-primary absolute inset-0 origin-left rounded-full'\n    />\n  );\n}\n\ntype ChunkMarkProps = {\n  chunk: Chunk;\n  order: number;\n  chapter: number;\n};\n\nfunction ChunkMark({ chunk, order, chapter }: ChunkMarkProps) {\n  const isSplit = chapter === CHUNK_CHAPTER;\n  const isEmbedded = chapter >= EMBED_CHAPTER;\n  const isQueried = chapter >= QUERY_CHAPTER;\n  const isAsked = chapter === QUERY_CHAPTER;\n  const isNearest = NEAREST_IDS.includes(chunk.id);\n  const isMarked = isQueried && isNearest;\n  const place = placeOfChunk(chunk, isEmbedded);\n  const color = seriesColorOf(TOPIC_SERIES[chunk.topic]);\n  const flightDelayMs = order * FLIGHT_STAGGER_MS;\n\n  return (\n    <span\n      style={{\n        translate: translateOf(place),\n        ...delayWhile(isEmbedded, flightDelayMs),\n      }}\n      className='absolute top-0 left-0 transition-[translate] duration-700 ease-(--ease-in-out-strong)'\n    >\n      <span\n        style={{\n          translate: splitOf(isSplit, chunk.row),\n          ...delayWhile(isSplit, SPLIT_AFTER_MS),\n        }}\n        className='absolute top-0 left-0 transition-[translate] duration-500 ease-(--ease-out-strong)'\n      >\n        <span\n          data-embedded={isEmbedded}\n          className='bg-foreground/20 absolute top-0 left-0 h-[1.7cqw] w-[16cqw] origin-left -translate-y-1/2 rounded-full transition-[opacity,scale] duration-500 ease-(--ease-out-strong) data-[embedded=true]:scale-x-[0.12] data-[embedded=true]:opacity-0'\n        />\n      </span>\n      <span\n        data-embedded={isEmbedded}\n        style={{ backgroundColor: color }}\n        className='absolute top-0 left-0 size-[2cqw] -translate-x-1/2 -translate-y-1/2 scale-50 rounded-full opacity-0 transition-[opacity,scale] duration-500 ease-(--ease-out-strong) data-[embedded=true]:scale-100 data-[embedded=true]:opacity-100'\n      />\n      <span\n        data-marked={isMarked}\n        style={delayWhile(isAsked, WALK_MS)}\n        className='ring-primary absolute top-0 left-0 size-[4.2cqw] -translate-x-1/2 -translate-y-1/2 scale-75 rounded-full opacity-0 ring-[1.5px] transition-[opacity,scale] duration-300 ease-(--ease-out-strong) data-[marked=true]:scale-100 data-[marked=true]:opacity-100'\n      />\n    </span>\n  );\n}\n\nexport type VectorSearchProps = {\n  /** The three documents that are cut into chunks. */\n  documents?: [string, string, string];\n  /** The three topics their chunks gather around. */\n  topics?: [string, string, string];\n  className?: string;\n};\n\nconst DEFAULT_DOCUMENTS: [string, string, string] = [\n  'refunds.md',\n  'billing.md',\n  'plans.md',\n];\n\nconst DEFAULT_TOPICS: [string, string, string] = [\n  'Refunds',\n  'Invoices',\n  'Plans',\n];\n\nexport function VectorSearch({\n  documents = DEFAULT_DOCUMENTS,\n  topics = DEFAULT_TOPICS,\n  className,\n}: VectorSearchProps) {\n  const { ref, isPlaying, isStill } = useScenePlay();\n  const stageRef = useRef<HTMLDivElement>(null);\n  const walkerRef = useRef<HTMLSpanElement>(null);\n  const [chapter, setChapter] = useState(RANK_CHAPTER);\n  const [round, setRound] = useState(0);\n  const [isPaused, setIsPaused] = useState(false);\n  const [hasTakenOver, setHasTakenOver] = useState(false);\n  const current = CHAPTERS[chapter];\n  const isRunning = isPlaying && !isPaused;\n  const isStageHeld = !isRunning && !isStill;\n  const isEmbedded = chapter >= EMBED_CHAPTER;\n  const isIndexed = chapter >= INDEX_CHAPTER;\n  const isQueried = chapter >= QUERY_CHAPTER;\n  const isAsked = chapter === QUERY_CHAPTER;\n  const isRanked = chapter >= RANK_CHAPTER;\n  const presence = risePresenceOf(isStill);\n\n  // Before the paint: one frame later the walker would show on its last point first.\n  useLayoutEffect(() => {\n    const walker = walkerRef.current;\n    const isWalking = isAsked && !isStill;\n    if (!walker || !isWalking) {\n      return;\n    }\n    const walk = walker.animate(WALK_KEYFRAMES, { duration: WALK_MS });\n    return () => walk.cancel();\n  }, [isAsked, isStill, round]);\n\n  useEffect(() => {\n    const stage = stageRef.current;\n    if (!stage) {\n      return;\n    }\n    holdStage(stage, isStageHeld);\n  }, [isStageHeld]);\n\n  function advance() {\n    setChapter(nextChapterOf(chapter));\n  }\n\n  function jumpTo(index: number) {\n    const stage = stageRef.current;\n    if (stage) {\n      finishHeld(stage);\n    }\n    setChapter(index);\n    setRound((count) => count + 1);\n    setHasTakenOver(true);\n  }\n\n  function togglePause() {\n    setIsPaused((paused) => !paused);\n    setHasTakenOver(true);\n  }\n\n  return (\n    <div\n      ref={ref}\n      className={cn('flex w-full max-w-[34rem] flex-col gap-3', className)}\n    >\n      <div\n        ref={stageRef}\n        aria-hidden='true'\n        className='@container relative aspect-[16/10] w-full'\n      >\n        <div className='bg-foreground/[0.03] absolute top-[3.5cqw] left-[30cqw] h-[55.5cqw] w-[67cqw] rounded-lg' />\n        <span className='text-muted-foreground absolute top-[5cqw] right-[4.5cqw] text-[10px] leading-3'>\n          Vector space\n        </span>\n        {TOPIC_CENTRES.map((centre, topic) => (\n          <span\n            key={topic}\n            data-shown={isEmbedded}\n            style={{ translate: translateOf(centre) }}\n            className='absolute top-0 left-0 opacity-0 transition-opacity duration-500 ease-(--ease-out-strong) data-[shown=true]:opacity-100 data-[shown=true]:delay-300'\n          >\n            <span\n              style={{\n                backgroundColor: seriesColorOf(TOPIC_SERIES[topic]),\n                width: HALO_SIZE,\n                height: HALO_SIZE,\n              }}\n              className='absolute top-0 left-0 -translate-x-1/2 -translate-y-1/2 rounded-full opacity-10'\n            />\n            <span\n              style={{ top: HALO_TOP }}\n              className='text-muted-foreground absolute left-0 -translate-x-1/2 -translate-y-full pb-0.5 text-[10px] leading-3 whitespace-nowrap'\n            >\n              {topics[topic]}\n            </span>\n          </span>\n        ))}\n        {documents.map((name, index) => (\n          <div\n            key={index}\n            style={{ ...documentCornerOf(index), ...DOCUMENT_SIZE }}\n            className='bg-card hairline-ring ring-border absolute rounded-md px-[2.5cqw] pt-[1cqw] shadow-[0_1px_2px_rgb(0_0_0/0.04)]'\n          >\n            <p className='text-muted-foreground truncate text-[10px] leading-3'>\n              {name}\n            </p>\n          </div>\n        ))}\n        {CHUNKS.map((chunk) => (\n          <span\n            key={chunk.id}\n            style={cornerOf(chunk.home)}\n            className='bg-foreground/[0.06] absolute h-[1.7cqw] w-[16cqw] -translate-y-1/2 rounded-full'\n          />\n        ))}\n        {LINK_SEATS.map(([fromTopic, fromSeat, toTopic, toSeat], index) => {\n          const from = seatPlaceOf(fromTopic, fromSeat);\n          const to = seatPlaceOf(toTopic, toSeat);\n          const drawDelayMs = index * LINK_STAGGER_MS;\n\n          return (\n            <span\n              key={`${fromTopic}${fromSeat}${toTopic}${toSeat}`}\n              style={{\n                ...segmentStyleOf(from, to, isIndexed),\n                ...delayWhile(isIndexed, drawDelayMs),\n              }}\n              className='bg-foreground/15 absolute h-px origin-left transition-transform duration-300 ease-(--ease-out-strong)'\n            />\n          );\n        })}\n        {WALK.map((hop) => (\n          <span\n            key={hop.leavesMs}\n            style={{\n              ...segmentStyleOf(hop.from, hop.to, isQueried),\n              ...delayWhile(isAsked, hop.leavesMs),\n            }}\n            className='bg-primary absolute -mt-px h-0.5 origin-left rounded-full transition-transform duration-300 ease-(--ease-in-out-strong)'\n          />\n        ))}\n        {CHUNKS.map((chunk, index) => (\n          <ChunkMark\n            key={chunk.id}\n            chunk={chunk}\n            order={index}\n            chapter={chapter}\n          />\n        ))}\n        <span\n          data-shown={isQueried}\n          style={{ translate: translateOf(QUESTION) }}\n          className='absolute top-0 left-0 opacity-0 transition-opacity duration-300 ease-(--ease-out-strong) data-[shown=true]:opacity-100'\n        >\n          <span className='bg-primary ring-primary/25 absolute top-0 left-0 size-[2.4cqw] -translate-x-1/2 -translate-y-1/2 rounded-full ring-[3px]' />\n          <span className='text-primary-ink absolute top-0 left-[2.6cqw] -translate-y-1/2 text-[10px] leading-3 font-medium whitespace-nowrap'>\n            Question\n          </span>\n        </span>\n        <span\n          ref={walkerRef}\n          data-shown={isQueried}\n          style={{ translate: translateOf(WALK_END) }}\n          className='absolute top-0 left-0 opacity-0 data-[shown=true]:opacity-100'\n        >\n          <span className='ring-primary absolute top-0 left-0 size-[3.2cqw] -translate-x-1/2 -translate-y-1/2 rounded-full ring-2' />\n        </span>\n        <div\n          data-shown={isRanked}\n          className='surface-raised absolute bottom-[3.5cqw] left-[3cqw] w-[44cqw] max-w-52 min-w-32 translate-y-2 rounded-lg p-2 opacity-0 transition-[opacity,translate] duration-200 ease-(--ease-out-strong) data-[shown=true]:translate-y-0 data-[shown=true]:opacity-100 data-[shown=true]:duration-300'\n        >\n          <p className='text-muted-foreground flex items-baseline justify-between gap-2 text-[10px] leading-3'>\n            Top matches\n            <span>Illustrative</span>\n          </p>\n          <ol className='mt-1.5 flex flex-col gap-1'>\n            {RESULTS.map((result, index) => (\n              <li\n                key={result.chunkId}\n                data-shown={isRanked}\n                style={delayWhile(isRanked, resultDelayOf(index))}\n                className='flex -translate-x-1.5 items-center gap-1.5 text-[10px] leading-4 opacity-0 transition-[opacity,translate] duration-300 ease-(--ease-out-strong) data-[shown=true]:translate-x-0 data-[shown=true]:opacity-100'\n              >\n                <span className='text-muted-foreground tabular-nums'>\n                  {index + 1}\n                </span>\n                <span className='min-w-0 flex-1 truncate font-medium'>\n                  {documents[result.documentIndex]}\n                </span>\n                <span className='text-muted-foreground hidden @md:inline'>\n                  chunk {result.chunkNumber}\n                </span>\n                <span className='tabular-nums'>\n                  {formatScore(result.score)}\n                </span>\n              </li>\n            ))}\n          </ol>\n        </div>\n      </div>\n      <div className='flex min-h-10 items-start'>\n        <AnimatePresence mode='wait' initial={false}>\n          <motion.p\n            key={current.id}\n            className='text-muted-foreground text-[13px] leading-5 text-balance'\n            {...presence}\n          >\n            {current.caption}\n          </motion.p>\n        </AnimatePresence>\n      </div>\n      <div className='flex items-center gap-2'>\n        {!isStill && (\n          <Button\n            type='button'\n            variant='ghost'\n            size='icon-sm'\n            aria-label={playLabelOf(isPaused)}\n            onClick={togglePause}\n            className='shrink-0'\n          >\n            <Swap swapKey={playLabelOf(isPaused)}>\n              {isPaused && <PlayIcon />}\n              {!isPaused && <PauseIcon />}\n            </Swap>\n          </Button>\n        )}\n        <ol className='grid min-w-0 flex-1 grid-cols-5 gap-1.5'>\n          {CHAPTERS.map((item, index) => {\n            const isCurrent = index === chapter;\n            const isPast = index < chapter;\n            const isHeldFull = isCurrent && isStill;\n            const isFull = isPast || isHeldFull;\n            const isTiming = isCurrent && !isStill;\n\n            return (\n              <li key={item.id} className='min-w-0'>\n                <button\n                  type='button'\n                  aria-current={currentStepOf(isCurrent)}\n                  aria-label={stepLabelOf(item, index)}\n                  data-current={isCurrent}\n                  onClick={() => jumpTo(index)}\n                  className='group/step text-muted-foreground hover:text-foreground data-[current=true]:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background flex w-full cursor-pointer flex-col gap-1.5 rounded-md py-1 text-start text-[11px] leading-4 font-medium transition-colors duration-150 outline-none focus-visible:ring-2 focus-visible:ring-offset-2'\n                >\n                  <span className='truncate'>{item.label}</span>\n                  <span className='bg-foreground/10 group-hover/step:bg-foreground/15 relative block h-0.5 overflow-hidden rounded-full transition-colors duration-150'>\n                    {isFull && (\n                      <span className='bg-primary absolute inset-0 rounded-full' />\n                    )}\n                    {isTiming && (\n                      <ChapterFill\n                        key={round}\n                        durationMs={item.durationMs}\n                        isRunning={isRunning}\n                        onDone={advance}\n                      />\n                    )}\n                  </span>\n                </button>\n              </li>\n            );\n          })}\n        </ol>\n      </div>\n      <LiveRegion message={spokenUnless(!hasTakenOver, current.caption)} />\n    </div>\n  );\n}\n\nexport default function Illustration08() {\n  return <VectorSearch />;\n}\n",
      "type": "registry:component",
      "target": "components/illustration/illustration-08.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/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/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"
}