{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "voice-04",
  "title": "Particle orb",
  "description": "A sphere of a few hundred particles that turns slowly and surges outward with the voice, then falls back on springs: it breathes when idle, tightens and spins while thinking, pulses while speaking, and one key starts and ends the call.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.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-word-roll.json",
    "https://ui.ndekocode.dev/r/speech-envelope.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-agent-run.json",
    "https://ui.ndekocode.dev/r/use-autoplay.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/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/voice/voice-04.tsx",
      "content": "'use client';\n\nimport { useEffect, useRef, useState } from 'react';\n\nimport { WordRoll } from '@/components/core/word-roll';\nimport { useDocumentVisible } from '@/registry/ndeko/hooks/use-agent-run';\nimport {\n  useAutoplay,\n  type AutoplayStep,\n} from '@/registry/ndeko/hooks/use-autoplay';\nimport { useKeptHeight } from '@/registry/ndeko/hooks/use-kept-height';\nimport {\n  hold,\n  PRESS_LEAD_MS,\n  pressedQuietOf,\n  pressedSolidOf,\n  spokenUnless,\n  usePress,\n} from '@/registry/ndeko/lib/demonstration';\nimport { MicIcon, PhoneOffIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\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 { penOf, tokenOf, watchTheme } from './_parts/canvas';\nimport { followLevel } from './_parts/level';\nimport {\n  createField,\n  drawField,\n  geometryOf,\n  levelOf,\n  settleField,\n  stepField,\n  stillFrameOf,\n  type FieldFrame,\n  type FieldPalette,\n  type ParticleField,\n} from './_parts/particle-field';\nimport { usePlayWhileSeen } from './_parts/use-play-while-seen';\nimport {\n  easeWeights,\n  oneHotOf,\n  VOICE_STATE_LABELS,\n  VOICE_STATE_WORD,\n  type StateTable,\n  type VoiceState,\n} from './_parts/voice-state';\n\nexport type { VoiceState } from './_parts/voice-state';\n\nconst STATE_EASE_S = 0.25;\n\n/** A frame is skipped when the last one is younger than this: the sphere never draws above about 66 frames a second. */\nconst MIN_FRAME_MS = 15;\n\n/** A long stall (a tab that was hidden) moves the springs by this much at most. */\nconst MAX_STEP_S = 0.05;\n\nfunction paletteOf(canvas: HTMLCanvasElement): FieldPalette {\n  return {\n    primary: tokenOf(canvas, '--primary'),\n    foreground: tokenOf(canvas, '--foreground'),\n  };\n}\n\nfunction fieldOf(holder: { current: ParticleField | null }) {\n  if (holder.current === null) {\n    holder.current = createField();\n  }\n  return holder.current;\n}\n\nexport type ParticleOrbProps = {\n  state: VoiceState;\n  /** The live level of the voice, between 0 and 1. Left out, a simulated voice drives the sphere. */\n  level?: () => number;\n  size?: number;\n  className?: string;\n};\n\nexport function ParticleOrb({\n  state,\n  level,\n  size = 200,\n  className,\n}: ParticleOrbProps) {\n  const { ref: canvasRef, isPlaying } = usePlayWhileSeen<HTMLCanvasElement>();\n  const stateRef = useRef(state);\n  const levelRef = useRef(level);\n  const fieldRef = useRef<ParticleField | null>(null);\n\n  useEffect(() => {\n    stateRef.current = state;\n    levelRef.current = level;\n  }, [state, level]);\n\n  useEffect(() => {\n    const canvas = canvasRef.current;\n    if (!canvas || isPlaying) {\n      return;\n    }\n    const pen = penOf(canvas, size);\n    if (!pen) {\n      return;\n    }\n    const surface: HTMLCanvasElement = canvas;\n    const context: CanvasRenderingContext2D = pen;\n    const field = fieldOf(fieldRef);\n    const geometry = geometryOf(size);\n    const frame = stillFrameOf(state);\n\n    function drawStill() {\n      const palette = paletteOf(surface);\n      drawField(context, geometry, field, frame, palette);\n    }\n\n    settleField(field, frame);\n    drawStill();\n    return watchTheme(drawStill);\n  }, [canvasRef, isPlaying, state, size]);\n\n  useEffect(() => {\n    const canvas = canvasRef.current;\n    if (!canvas || !isPlaying) {\n      return;\n    }\n    const pen = penOf(canvas, size);\n    if (!pen) {\n      return;\n    }\n    const surface: HTMLCanvasElement = canvas;\n    const context: CanvasRenderingContext2D = pen;\n    const field = fieldOf(fieldRef);\n    const geometry = geometryOf(size);\n    const weights: StateTable = oneHotOf(stateRef.current);\n    const frame: FieldFrame = { weights, level: 0, seconds: 0 };\n    let palette = paletteOf(surface);\n    const stopWatching = watchTheme(() => {\n      palette = paletteOf(surface);\n    });\n    const startedAt = performance.now();\n    let last = startedAt;\n    let handle = 0;\n\n    function draw(now: number) {\n      handle = requestAnimationFrame(draw);\n      const sinceLast = now - last;\n      if (sinceLast < MIN_FRAME_MS) {\n        return;\n      }\n      last = now;\n      const step = Math.min(MAX_STEP_S, sinceLast / 1000);\n      const elapsed = now - startedAt;\n      const stateEase = 1 - Math.exp(-step / STATE_EASE_S);\n      easeWeights(weights, oneHotOf(stateRef.current), stateEase);\n      const target = levelOf(levelRef.current, weights, elapsed);\n      frame.level = followLevel(frame.level, target, step);\n      frame.seconds = elapsed / 1000;\n      stepField(field, frame, step);\n      drawField(context, geometry, field, frame, palette);\n    }\n\n    handle = requestAnimationFrame(draw);\n    return () => {\n      cancelAnimationFrame(handle);\n      stopWatching();\n    };\n  }, [canvasRef, isPlaying, size]);\n\n  return (\n    <canvas\n      ref={canvasRef}\n      aria-hidden='true'\n      style={{ width: size, height: size }}\n      className={cn('block', className)}\n    />\n  );\n}\n\ntype CallKey = {\n  key: 'start' | 'end';\n  label: string;\n  icon: React.ReactNode;\n  variant: 'default' | 'outline';\n};\n\nfunction callKeyOf(isCalling: boolean): CallKey {\n  if (isCalling) {\n    return {\n      key: 'end',\n      label: 'End call',\n      icon: <PhoneOffIcon />,\n      variant: 'outline',\n    };\n  }\n  return {\n    key: 'start',\n    label: 'Start talking',\n    icon: <MicIcon />,\n    variant: 'default',\n  };\n}\n\nfunction pressClassOf(isCalling: boolean, isPressed: boolean) {\n  if (isCalling) {\n    return pressedQuietOf(isPressed);\n  }\n  return pressedSolidOf(isPressed);\n}\n\nconst TURN_MS: StateTable = {\n  idle: 0,\n  listening: 2800,\n  thinking: 1900,\n  speaking: 3200,\n};\n\nconst NEXT_STATE: Record<VoiceState, VoiceState> = {\n  idle: 'idle',\n  listening: 'thinking',\n  thinking: 'speaking',\n  speaking: 'listening',\n};\n\n/** Listens, thinks and speaks once, then listens again before the demonstration ends the call. */\nconst CALL_MS = 9300;\n\nexport default function Voice04() {\n  const [state, setState] = useState<VoiceState>('idle');\n  const { pressed, press } = usePress<'call'>();\n  const isTabVisible = useDocumentVisible();\n  const isCalling = state !== 'idle';\n  const key = callKeyOf(isCalling);\n\n  function startCall() {\n    setState('listening');\n  }\n\n  function endCall() {\n    setState('idle');\n  }\n\n  function toggleCall() {\n    if (isCalling) {\n      endCall();\n      return;\n    }\n    startCall();\n  }\n\n  const steps: AutoplayStep[] = [\n    { after: 1500, run: () => press('call') },\n    { after: PRESS_LEAD_MS, run: startCall },\n    { after: CALL_MS, run: () => press('call') },\n    { after: PRESS_LEAD_MS, run: endCall },\n    { after: 2200, run: hold },\n  ];\n  const { ref, isInView, isAutoplaying } = useAutoplay(steps, {\n    loopAfter: 700,\n    onReset: endCall,\n  });\n  const isOnScreen = isInView && isTabVisible;\n\n  useEffect(() => {\n    if (!isCalling || !isOnScreen) {\n      return;\n    }\n    function nextTurn() {\n      setState(NEXT_STATE[state]);\n    }\n\n    const timer = setTimeout(nextTurn, TURN_MS[state]);\n    return () => clearTimeout(timer);\n  }, [state, isCalling, isOnScreen]);\n\n  useKeptHeight(ref);\n\n  return (\n    <div\n      ref={ref}\n      className='flex w-full max-w-[22rem] flex-col items-center gap-4'\n    >\n      <div className='bg-card hairline-ring ring-border flex w-full flex-col items-center gap-3 rounded-xl px-4 pt-6 pb-4 shadow-[0_1px_2px_rgb(0_0_0/0.04)]'>\n        <ParticleOrb state={state} />\n        <div className='flex flex-col items-center gap-0.5'>\n          <p className='text-sm font-medium'>\n            <WordRoll\n              text={VOICE_STATE_WORD[state]}\n              labels={VOICE_STATE_LABELS}\n            />\n          </p>\n          <p className='text-muted-foreground text-xs'>Simulated voice</p>\n        </div>\n        <Button\n          type='button'\n          variant={key.variant}\n          onClick={toggleCall}\n          className={pressClassOf(isCalling, pressed === 'call')}\n        >\n          <AnimatedSize\n            as='span'\n            axis='width'\n            contentClassName='flex items-center'\n          >\n            <Swap swapKey={key.key}>\n              <span className='flex items-center gap-1.5'>\n                {key.icon}\n                {key.label}\n              </span>\n            </Swap>\n          </AnimatedSize>\n        </Button>\n      </div>\n      <LiveRegion\n        message={spokenUnless(isAutoplaying, VOICE_STATE_WORD[state])}\n      />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/voice/voice-04.tsx"
    },
    {
      "path": "registry/ndeko/components/voice/_parts/canvas.ts",
      "content": "/** A backing store above two device pixels a point costs four times the fill for a picture nobody sees sharper. */\nconst MAX_PIXEL_RATIO = 2;\n\nexport function pixelRatioOf() {\n  const screenRatio = window.devicePixelRatio || 1;\n  return Math.min(screenRatio, MAX_PIXEL_RATIO);\n}\n\nexport function penOf(canvas: HTMLCanvasElement, size: number) {\n  const ratio = pixelRatioOf();\n  const pixels = Math.round(size * ratio);\n  if (canvas.width !== pixels) {\n    canvas.width = pixels;\n    canvas.height = pixels;\n  }\n  const pen = canvas.getContext('2d');\n  pen?.setTransform(ratio, 0, 0, ratio, 0, 0);\n  return pen;\n}\n\nexport function tokenOf(element: Element, token: string) {\n  const styles = getComputedStyle(element);\n  const value = styles.getPropertyValue(token).trim();\n  return value || styles.color;\n}\n\n/** A canvas holds the colours it was drawn with: it is told when the theme of the page changes. */\nexport function watchTheme(onChange: () => void) {\n  const observer = new MutationObserver(onChange);\n  observer.observe(document.documentElement, {\n    attributes: true,\n    attributeFilter: ['class', 'style', 'data-theme'],\n  });\n  return () => observer.disconnect();\n}\n",
      "type": "registry:component",
      "target": "components/voice/_parts/canvas.ts"
    },
    {
      "path": "registry/ndeko/components/voice/_parts/level.ts",
      "content": "const ATTACK_S = 0.04;\n\nconst RELEASE_S = 0.2;\n\n/** Rises fast and falls slowly, whatever the frame rate. */\nexport function followLevel(current: number, target: number, step: number) {\n  const gap = target - current;\n  const isRising = gap > 0;\n  let constant = RELEASE_S;\n  if (isRising) {\n    constant = ATTACK_S;\n  }\n  const amount = 1 - Math.exp(-step / constant);\n  return current + gap * amount;\n}\n",
      "type": "registry:component",
      "target": "components/voice/_parts/level.ts"
    },
    {
      "path": "registry/ndeko/components/voice/_parts/particle-field.ts",
      "content": "import { noiseAt, speechLevelAt } from '@/registry/ndeko/lib/speech-envelope';\n\nimport {\n  blendOf,\n  oneHotOf,\n  type StateTable,\n  type VoiceState,\n} from './voice-state';\n\nconst TAU = Math.PI * 2;\n\nexport const PARTICLE_COUNT = 340;\n\nconst GOLDEN_ANGLE = Math.PI * (3 - Math.sqrt(5));\n\n/** Radius of the sphere, as a share of the canvas: the voice pushes particles out to 1.6 times that, and the pulse of speech adds 7% more, so the edge of the canvas is never reached. */\nconst RADIUS_SHARE = 0.26;\n\nconst MIN_DOT = 0.0036;\n\nconst DOT_RANGE = 0.0062;\n\nconst MIN_SPIN = 0.6;\n\nconst SPIN_RANGE = 0.8;\n\n/** Each particle falls back on its own spring, so a surge does not return as one block. */\nconst MIN_STIFFNESS = 260;\n\nconst STIFFNESS_RANGE = 440;\n\nconst DAMPING = 17;\n\nconst MIN_REACH = 0.3;\n\nconst REACH_RANGE = 0.7;\n\nconst MIN_PUSH = -0.2;\n\nconst MAX_PUSH = 0.6;\n\nconst DEPTH = 0.3;\n\nconst TILT = 0.42;\n\nconst ALPHA_BUCKETS = 6;\n\nconst MIN_ALPHA = 0.16;\n\nconst MAX_ALPHA = 0.8;\n\nconst SPIN_SPEED: StateTable = {\n  idle: 0.14,\n  listening: 0.24,\n  thinking: 1.3,\n  speaking: 0.32,\n};\n\nconst REACH: StateTable = {\n  idle: 0,\n  listening: 0.8,\n  thinking: 0,\n  speaking: 0.5,\n};\n\nconst BRIGHTNESS: StateTable = {\n  idle: 0.55,\n  listening: 0.8,\n  thinking: 0.9,\n  speaking: 1,\n};\n\nconst TIGHTEN = 0.18;\n\nconst PULSE = 0.07;\n\nconst BREATH_HERTZ = 0.2;\n\nconst BREATH_DEPTH = 0.035;\n\nconst THINKING_INK = 0.35;\n\nconst LISTEN_SEED = 0.4;\n\nconst SPEAK_SEED = 2.2;\n\nconst STILL_LEVEL = 0.6;\n\nconst STILL_SECONDS = 0.4;\n\nconst STILL_TURN = 0.5;\n\ntype Particle = {\n  x: number;\n  y: number;\n  z: number;\n  dot: number;\n  spin: number;\n  reach: number;\n  stiffness: number;\n};\n\nfunction particleAt(index: number): Particle {\n  const share = (index + 0.5) / PARTICLE_COUNT;\n  const y = 1 - 2 * share;\n  const ring = Math.sqrt(1 - y * y);\n  const angle = index * GOLDEN_ANGLE;\n  return {\n    x: Math.cos(angle) * ring,\n    y,\n    z: Math.sin(angle) * ring,\n    dot: MIN_DOT + noiseAt(index, 1.7) * DOT_RANGE,\n    spin: MIN_SPIN + noiseAt(index, 5.1) * SPIN_RANGE,\n    reach: MIN_REACH + noiseAt(index, 9.3) * REACH_RANGE,\n    stiffness: MIN_STIFFNESS + noiseAt(index, 2.9) * STIFFNESS_RANGE,\n  };\n}\n\nconst PARTICLES: readonly Particle[] = Array.from(\n  { length: PARTICLE_COUNT },\n  (_, index) => particleAt(index)\n);\n\nexport type ParticleField = {\n  turns: Float32Array;\n  pushes: Float32Array;\n  speeds: Float32Array;\n  xs: Float32Array;\n  ys: Float32Array;\n  radii: Float32Array;\n  buckets: Uint8Array;\n};\n\nexport function createField(): ParticleField {\n  return {\n    turns: new Float32Array(PARTICLE_COUNT),\n    pushes: new Float32Array(PARTICLE_COUNT),\n    speeds: new Float32Array(PARTICLE_COUNT),\n    xs: new Float32Array(PARTICLE_COUNT),\n    ys: new Float32Array(PARTICLE_COUNT),\n    radii: new Float32Array(PARTICLE_COUNT),\n    buckets: new Uint8Array(PARTICLE_COUNT),\n  };\n}\n\nexport type FieldFrame = {\n  weights: StateTable;\n  level: number;\n  seconds: number;\n};\n\nexport type FieldGeometry = {\n  size: number;\n  centre: number;\n  radius: number;\n};\n\nexport type FieldPalette = {\n  primary: string;\n  foreground: string;\n};\n\nexport function geometryOf(size: number): FieldGeometry {\n  return { size, centre: size / 2, radius: size * RADIUS_SHARE };\n}\n\nexport function stillFrameOf(state: VoiceState): FieldFrame {\n  return {\n    weights: oneHotOf(state),\n    level: STILL_LEVEL,\n    seconds: STILL_SECONDS,\n  };\n}\n\nexport function levelOf(\n  provider: (() => number) | undefined,\n  weights: StateTable,\n  elapsed: number\n) {\n  if (provider) {\n    return provider();\n  }\n  const heard = speechLevelAt(elapsed, LISTEN_SEED);\n  const spoken = speechLevelAt(elapsed, SPEAK_SEED);\n  return weights.listening * heard + weights.speaking * spoken;\n}\n\nfunction reachOf(frame: FieldFrame) {\n  const share = blendOf(REACH, frame.weights);\n  return share * frame.level;\n}\n\nfunction scaleOf(frame: FieldFrame) {\n  const breathAngle = frame.seconds * TAU * BREATH_HERTZ;\n  const breath = Math.sin(breathAngle) * BREATH_DEPTH;\n  const tightened = frame.weights.thinking * TIGHTEN;\n  const calmBreath = frame.weights.idle * breath;\n  const pulse = frame.weights.speaking * frame.level * PULSE;\n  return 1 - tightened + calmBreath + pulse;\n}\n\nfunction inkOf(weights: StateTable) {\n  const thinking = weights.thinking * THINKING_INK;\n  return Math.min(1, weights.speaking + thinking);\n}\n\nexport function stepField(\n  field: ParticleField,\n  frame: FieldFrame,\n  step: number\n) {\n  const spin = blendOf(SPIN_SPEED, frame.weights);\n  const reach = reachOf(frame);\n  for (let index = 0; index < PARTICLE_COUNT; index += 1) {\n    const particle = PARTICLES[index];\n    field.turns[index] += spin * particle.spin * step;\n    const target = reach * particle.reach;\n    const pull = particle.stiffness * (target - field.pushes[index]);\n    const drag = DAMPING * field.speeds[index];\n    field.speeds[index] += (pull - drag) * step;\n    field.pushes[index] += field.speeds[index] * step;\n  }\n}\n\nexport function settleField(field: ParticleField, frame: FieldFrame) {\n  const reach = reachOf(frame);\n  for (let index = 0; index < PARTICLE_COUNT; index += 1) {\n    const particle = PARTICLES[index];\n    field.turns[index] = STILL_TURN * particle.spin;\n    field.pushes[index] = reach * particle.reach;\n    field.speeds[index] = 0;\n  }\n}\n\nfunction boundedPush(push: number) {\n  return Math.min(MAX_PUSH, Math.max(MIN_PUSH, push));\n}\n\nfunction bucketOf(depth: number) {\n  const share = (depth + 1) / 2;\n  const bucket = Math.floor(share * ALPHA_BUCKETS);\n  return Math.min(ALPHA_BUCKETS - 1, bucket);\n}\n\nconst COS_TILT = Math.cos(TILT);\n\nconst SIN_TILT = Math.sin(TILT);\n\nfunction projectField(\n  field: ParticleField,\n  geometry: FieldGeometry,\n  frame: FieldFrame\n) {\n  const base = geometry.radius * scaleOf(frame);\n  for (let index = 0; index < PARTICLE_COUNT; index += 1) {\n    const particle = PARTICLES[index];\n    const cos = Math.cos(field.turns[index]);\n    const sin = Math.sin(field.turns[index]);\n    const turnedX = particle.x * cos + particle.z * sin;\n    const turnedZ = particle.z * cos - particle.x * sin;\n    const tiltedY = particle.y * COS_TILT - turnedZ * SIN_TILT;\n    const tiltedZ = particle.y * SIN_TILT + turnedZ * COS_TILT;\n    const push = boundedPush(field.pushes[index]);\n    const reach = base * (1 + push);\n    const lens = 1 / (1 - tiltedZ * DEPTH);\n    field.xs[index] = geometry.centre + turnedX * reach * lens;\n    field.ys[index] = geometry.centre + tiltedY * reach * lens;\n    field.radii[index] = particle.dot * geometry.size * lens;\n    field.buckets[index] = bucketOf(tiltedZ);\n  }\n}\n\nfunction alphaOfBucket(bucket: number) {\n  const share = (bucket + 0.5) / ALPHA_BUCKETS;\n  return MIN_ALPHA + share * (MAX_ALPHA - MIN_ALPHA);\n}\n\n/** Every dot of one depth in one path, so a few hundred dots cost a few fills. */\nfunction fillBucket(\n  context: CanvasRenderingContext2D,\n  field: ParticleField,\n  bucket: number,\n  alpha: number,\n  color: string\n) {\n  if (alpha < 0.01) {\n    return;\n  }\n  context.globalAlpha = alpha;\n  context.fillStyle = color;\n  context.beginPath();\n  for (let index = 0; index < PARTICLE_COUNT; index += 1) {\n    if (field.buckets[index] !== bucket) {\n      continue;\n    }\n    const radius = field.radii[index];\n    context.moveTo(field.xs[index] + radius, field.ys[index]);\n    context.arc(field.xs[index], field.ys[index], radius, 0, TAU);\n  }\n  context.fill();\n}\n\n/** Neutral while the sphere listens, in the brand colour while the agent speaks; nearer dots are stronger. */\nexport function drawField(\n  context: CanvasRenderingContext2D,\n  geometry: FieldGeometry,\n  field: ParticleField,\n  frame: FieldFrame,\n  palette: FieldPalette\n) {\n  context.clearRect(0, 0, geometry.size, geometry.size);\n  projectField(field, geometry, frame);\n  const brightness = blendOf(BRIGHTNESS, frame.weights);\n  const ink = inkOf(frame.weights);\n  for (let bucket = 0; bucket < ALPHA_BUCKETS; bucket += 1) {\n    const alpha = alphaOfBucket(bucket) * brightness;\n    fillBucket(context, field, bucket, alpha * (1 - ink), palette.foreground);\n    fillBucket(context, field, bucket, alpha * ink, palette.primary);\n  }\n}\n",
      "type": "registry:component",
      "target": "components/voice/_parts/particle-field.ts"
    },
    {
      "path": "registry/ndeko/components/voice/_parts/use-play-while-seen.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.2;\n\n/**\n * A voice indicator moves only while someone can see it: on screen, in the tab that is shown,\n * without reduced motion. `isStill` asks for the still frame instead, and `isOnScreen` is for the\n * clocks that keep a session going under reduced motion.\n */\nexport function usePlayWhileSeen<Element extends HTMLElement = HTMLElement>() {\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, isOnScreen, isPlaying, isStill };\n}\n",
      "type": "registry:component",
      "target": "components/voice/_parts/use-play-while-seen.ts"
    },
    {
      "path": "registry/ndeko/components/voice/_parts/voice-state.ts",
      "content": "export type VoiceState = 'idle' | 'listening' | 'thinking' | 'speaking';\n\nexport const VOICE_STATES: readonly VoiceState[] = [\n  'idle',\n  'listening',\n  'thinking',\n  'speaking',\n];\n\nexport const VOICE_STATE_WORD: Record<VoiceState, string> = {\n  idle: 'Idle',\n  listening: 'Listening',\n  thinking: 'Thinking',\n  speaking: 'Speaking',\n};\n\nexport const VOICE_STATE_LABELS = VOICE_STATES.map(\n  (state) => VOICE_STATE_WORD[state]\n);\n\nexport type StateTable = Record<VoiceState, number>;\n\nexport function oneHotOf(state: VoiceState): StateTable {\n  return {\n    idle: Number(state === 'idle'),\n    listening: Number(state === 'listening'),\n    thinking: Number(state === 'thinking'),\n    speaking: Number(state === 'speaking'),\n  };\n}\n\nexport function easeWeights(\n  weights: StateTable,\n  target: StateTable,\n  amount: number\n) {\n  for (const state of VOICE_STATES) {\n    const gap = target[state] - weights[state];\n    weights[state] += gap * amount;\n  }\n}\n\nexport function blendOf(values: StateTable, weights: StateTable) {\n  let total = 0;\n  for (const state of VOICE_STATES) {\n    total += values[state] * weights[state];\n  }\n  return total;\n}\n",
      "type": "registry:component",
      "target": "components/voice/_parts/voice-state.ts"
    }
  ],
  "categories": [
    "components",
    "voice"
  ],
  "type": "registry:component"
}