{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "popover-10",
  "title": "Emoji field",
  "description": "Emoji packed in a round field that keeps gliding after a fling and swells under the middle; a tapped one flies into the message where the caret is.",
  "dependencies": [
    "@base-ui/react"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/recipes.json",
    "https://ui.ndekocode.dev/r/theme.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/popover/popover-10.tsx",
      "content": "'use client';\n\nimport { Popover as PopoverPrimitive } from '@base-ui/react/popover';\nimport {\n  useCallback,\n  useEffect,\n  useLayoutEffect,\n  useMemo,\n  useRef,\n  useState,\n  type KeyboardEvent,\n} from 'react';\n\nimport {\n  typingSteps,\n  useAutoplay,\n  type AutoplayStep,\n} from '@/registry/ndeko/hooks/use-autoplay';\nimport { useKeptHeight } from '@/registry/ndeko/hooks/use-kept-height';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { hold } from '@/registry/ndeko/lib/demonstration';\nimport { SmileIcon } from '@/registry/ndeko/lib/icons';\nimport { POPUP_TRANSITION } from '@/registry/ndeko/lib/recipes';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\n\nimport { matchingEmoji, type Cell, type EmojiItem } from './_parts/emoji-data';\nimport { EmojiField, type EmojiFieldHandle } from './_parts/emoji-field';\n\ntype Draft = {\n  text: string;\n  caret: number;\n};\n\ntype Flight = {\n  id: number;\n  char: string;\n  from: Cell;\n  to: Cell;\n};\n\nconst FLIGHT_MS = 420;\nconst FLIGHT_SIZE_PX = 36;\nconst FLIGHT_START_SCALE = 1.5;\nconst FLIGHT_END_SCALE = 0.65;\nconst LANDING_GAP_PX = 8;\n\nconst INITIAL_TEXT = 'Great work on the launch ';\n\nconst REST_DRAFT: Draft = { text: INITIAL_TEXT, caret: INITIAL_TEXT.length };\n\nconst PARTY = '\\u{1F389}';\nconst ROCKET = '\\u{1F680}';\nconst HEART = '❤️';\n\nlet measuringContext: CanvasRenderingContext2D | null = null;\n\nfunction textWidthOf(input: HTMLInputElement, text: string) {\n  if (measuringContext === null) {\n    measuringContext = document.createElement('canvas').getContext('2d');\n  }\n  if (measuringContext === null) {\n    return 0;\n  }\n  const style = getComputedStyle(input);\n  measuringContext.font = `${style.fontWeight} ${style.fontSize} ${style.fontFamily}`;\n  return measuringContext.measureText(text).width;\n}\n\nfunction caretOffsetOf(input: HTMLInputElement, caret: number): Cell {\n  const style = getComputedStyle(input);\n  const paddingLeft = parseFloat(style.paddingLeft);\n  const borderLeft = parseFloat(style.borderLeftWidth);\n  const left = paddingLeft + borderLeft;\n  const top = parseFloat(style.borderTopWidth);\n  const width = textWidthOf(input, input.value.slice(0, caret));\n  return {\n    x: left + width - input.scrollLeft,\n    y: top + input.clientHeight / 2,\n  };\n}\n\nfunction withInserted(draft: Draft, char: string): Draft {\n  const before = draft.text.slice(0, draft.caret);\n  const after = draft.text.slice(draft.caret);\n  return { text: `${before}${char}${after}`, caret: draft.caret + char.length };\n}\n\ntype FlyingEmojiProps = {\n  flight: Flight;\n  onLanded: (id: number, char: string) => void;\n};\n\nfunction FlyingEmoji({ flight, onLanded }: FlyingEmojiProps) {\n  const elementRef = useRef<HTMLSpanElement>(null);\n  const { from, to } = flight;\n  const half = FLIGHT_SIZE_PX / 2;\n\n  useEffect(() => {\n    const element = elementRef.current;\n    if (!element) {\n      return;\n    }\n    const start = `translate(${from.x - half}px, ${from.y - half}px) scale(${FLIGHT_START_SCALE})`;\n    const landingX = to.x + LANDING_GAP_PX - half;\n    const end = `translate(${landingX}px, ${to.y - half}px) scale(${FLIGHT_END_SCALE})`;\n    const animation = element.animate(\n      [{ transform: start }, { transform: end }],\n      {\n        duration: FLIGHT_MS,\n        easing: 'cubic-bezier(0.23, 1, 0.32, 1)',\n        fill: 'forwards',\n      }\n    );\n    animation.onfinish = () => onLanded(flight.id, flight.char);\n    return () => animation.cancel();\n  }, [flight, from, to, half, onLanded]);\n\n  return (\n    <span\n      ref={elementRef}\n      aria-hidden='true'\n      className='pointer-events-none absolute top-0 left-0 z-[70] flex items-center justify-center text-xl'\n      style={{\n        width: FLIGHT_SIZE_PX,\n        height: FLIGHT_SIZE_PX,\n        transform: `translate(${from.x - half}px, ${from.y - half}px)`,\n      }}\n    >\n      {flight.char}\n    </span>\n  );\n}\n\nexport default function Popover10() {\n  const [draft, setDraft] = useState(REST_DRAFT);\n  const [query, setQuery] = useState('');\n  const [isOpen, setIsOpen] = useState(true);\n  const [focusesOnOpen, setFocusesOnOpen] = useState(false);\n  const [isFocused, setIsFocused] = useState(false);\n  const [flights, setFlights] = useState<Flight[]>([]);\n  const [announcement, setAnnouncement] = useState('');\n  const inputRef = useRef<HTMLInputElement>(null);\n  const searchRef = useRef<HTMLInputElement>(null);\n  const ghostRef = useRef<HTMLSpanElement>(null);\n  const fieldRef = useRef<EmojiFieldHandle>(null);\n  const flightCount = useRef(0);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const items = useMemo(() => matchingEmoji(query), [query]);\n  const showsGhost = isOpen && !isFocused;\n\n  const land = useCallback((id: number, char: string) => {\n    setFlights((current) => current.filter((flight) => flight.id !== id));\n    setDraft((current) => withInserted(current, char));\n  }, []);\n\n  useLayoutEffect(() => {\n    const input = inputRef.current;\n    const ghost = ghostRef.current;\n    if (!input || !ghost) {\n      return;\n    }\n    const { x } = caretOffsetOf(input, draft.caret);\n    ghost.style.transform = `translateX(${x}px)`;\n  }, [draft, showsGhost]);\n\n  function changeOpen(next: boolean) {\n    if (next) {\n      setFocusesOnOpen(true);\n    }\n    setIsOpen(next);\n  }\n\n  function launch(item: EmojiItem, source: DOMRect) {\n    const input = inputRef.current;\n    const root = rootRef.current;\n    if (!input || !root || shouldReduceMotion) {\n      setDraft((current) => withInserted(current, item.char));\n      return;\n    }\n    const rootBox = root.getBoundingClientRect();\n    const inputBox = input.getBoundingClientRect();\n    const caret = caretOffsetOf(input, draft.caret);\n    const from = {\n      x: source.left + source.width / 2 - rootBox.left,\n      y: source.top + source.height / 2 - rootBox.top,\n    };\n    const to = {\n      x: inputBox.left + caret.x - rootBox.left,\n      y: inputBox.top + caret.y - rootBox.top,\n    };\n    flightCount.current += 1;\n    const flight = { id: flightCount.current, char: item.char, from, to };\n    setFlights((current) => [...current, flight]);\n  }\n\n  function pickFromField(item: EmojiItem, source: DOMRect) {\n    launch(item, source);\n    if (!isAutoplaying) {\n      setAnnouncement(`${item.name} added to the message`);\n    }\n  }\n\n  function keepCaret(event: React.SyntheticEvent<HTMLInputElement>) {\n    const caret = event.currentTarget.selectionStart;\n    if (caret === null) {\n      return;\n    }\n    setDraft((current) => {\n      if (current.caret === caret) {\n        return current;\n      }\n      return { ...current, caret };\n    });\n  }\n\n  function changeMessage(event: React.ChangeEvent<HTMLInputElement>) {\n    const text = event.currentTarget.value;\n    const caret = event.currentTarget.selectionStart ?? text.length;\n    setDraft({ text, caret });\n  }\n\n  function focusSearchOnOpen() {\n    if (!focusesOnOpen) {\n      return false;\n    }\n    return searchRef.current;\n  }\n\n  function reachFieldFromSearch(event: KeyboardEvent<HTMLInputElement>) {\n    if (event.key !== 'ArrowDown') {\n      return;\n    }\n    event.preventDefault();\n    fieldRef.current?.focusFirst();\n  }\n\n  function startOver() {\n    setDraft(REST_DRAFT);\n    setQuery('');\n    setFlights([]);\n    setIsOpen(true);\n  }\n\n  const steps: AutoplayStep[] = [\n    { after: 2600, run: () => fieldRef.current?.glideTo(PARTY) },\n    { after: 1100, run: () => fieldRef.current?.pick(PARTY) },\n    { after: 1900, run: () => fieldRef.current?.glideTo(ROCKET) },\n    { after: 1100, run: () => fieldRef.current?.pick(ROCKET) },\n    { after: 1700, run: hold },\n    ...typingSteps('heart', setQuery, { startAfter: 300, characterMs: 110 }),\n    { after: 1100, run: () => fieldRef.current?.pick(HEART) },\n    { after: 1600, run: () => setQuery('') },\n    { after: 1800, run: hold },\n  ];\n  const { ref: rootRef, isAutoplaying } = useAutoplay(steps, {\n    loopAfter: 2000,\n    onReset: startOver,\n  });\n\n  useKeptHeight(rootRef);\n\n  return (\n    <div ref={rootRef} className='relative min-h-[27rem] w-full max-w-xs'>\n      <PopoverPrimitive.Root open={isOpen} onOpenChange={changeOpen}>\n        <div className='relative'>\n          <Input\n            ref={inputRef}\n            aria-label='Message'\n            value={draft.text}\n            onChange={changeMessage}\n            onSelect={keepCaret}\n            onFocus={() => setIsFocused(true)}\n            onBlur={() => setIsFocused(false)}\n            autoComplete='off'\n            className='pe-10'\n          />\n          {showsGhost && (\n            <span\n              ref={ghostRef}\n              aria-hidden='true'\n              className='bg-foreground/60 pointer-events-none absolute top-[7px] left-0 h-[18px] w-px'\n            />\n          )}\n          <PopoverPrimitive.Trigger\n            render={\n              <Button\n                variant='ghost'\n                size='icon-sm'\n                aria-label='Add an emoji'\n                className='text-muted-foreground hover:text-foreground absolute end-0.5 top-0.5 size-7'\n              />\n            }\n          >\n            <SmileIcon className='size-4' />\n          </PopoverPrimitive.Trigger>\n        </div>\n        <PopoverPrimitive.Portal container={rootRef}>\n          <PopoverPrimitive.Positioner\n            side='bottom'\n            align='end'\n            sideOffset={8}\n            className='z-50'\n          >\n            <PopoverPrimitive.Popup\n              initialFocus={focusSearchOnOpen}\n              finalFocus={focusesOnOpen}\n              aria-label='Emoji'\n              className={cn(\n                'surface-raised flex w-[18.5rem] flex-col items-center gap-2 rounded-xl p-3 text-[13px] outline-none',\n                POPUP_TRANSITION\n              )}\n            >\n              <Input\n                ref={searchRef}\n                type='search'\n                aria-label='Search emoji'\n                placeholder='Search emoji'\n                value={query}\n                onChange={(event) => setQuery(event.currentTarget.value)}\n                onKeyDown={reachFieldFromSearch}\n                autoComplete='off'\n              />\n              <EmojiField\n                items={items}\n                query={query}\n                onPick={pickFromField}\n                handleRef={fieldRef}\n              />\n              <p className='text-muted-foreground text-xs'>\n                Drag to move, tap or press Enter to add\n              </p>\n            </PopoverPrimitive.Popup>\n          </PopoverPrimitive.Positioner>\n        </PopoverPrimitive.Portal>\n      </PopoverPrimitive.Root>\n      {flights.map((flight) => (\n        <FlyingEmoji key={flight.id} flight={flight} onLanded={land} />\n      ))}\n      <LiveRegion message={announcement} />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/popover/popover-10.tsx"
    },
    {
      "path": "registry/ndeko/components/popover/_parts/emoji-data.ts",
      "content": "export type EmojiItem = {\n  char: string;\n  name: string;\n  keywords: string;\n};\n\nexport type Cell = {\n  x: number;\n  y: number;\n};\n\nexport const EMOJI: EmojiItem[] = [\n  { char: '\\u{1F600}', name: 'Grinning face', keywords: 'happy smile' },\n  { char: '\\u{1F602}', name: 'Laughing', keywords: 'joy funny tears' },\n  { char: '\\u{1F60A}', name: 'Smiling face', keywords: 'happy blush' },\n  { char: '\\u{1F60D}', name: 'Heart eyes', keywords: 'love heart adore' },\n  { char: '\\u{1F60E}', name: 'Cool', keywords: 'sunglasses' },\n  { char: '\\u{1F914}', name: 'Thinking', keywords: 'hmm wonder' },\n  { char: '\\u{1F62E}', name: 'Surprised', keywords: 'wow shock' },\n  { char: '\\u{1F622}', name: 'Crying', keywords: 'sad tear' },\n  { char: '\\u{1F634}', name: 'Sleepy', keywords: 'tired zzz' },\n  { char: '\\u{1F973}', name: 'Partying face', keywords: 'party celebrate' },\n  { char: '\\u{1F643}', name: 'Upside down face', keywords: 'silly irony' },\n  { char: '\\u{1F607}', name: 'Angel', keywords: 'innocent halo' },\n  { char: '\\u{1F44D}', name: 'Thumbs up', keywords: 'yes ok approve' },\n  { char: '\\u{1F44F}', name: 'Clapping', keywords: 'applause bravo' },\n  { char: '\\u{1F64C}', name: 'Raised hands', keywords: 'hooray praise' },\n  { char: '\\u{1F64F}', name: 'Thanks', keywords: 'please pray' },\n  { char: '\\u{1F440}', name: 'Eyes', keywords: 'look watch' },\n  { char: '\\u{1F4AA}', name: 'Strong', keywords: 'muscle power' },\n  { char: '\\u{1F44B}', name: 'Waving hand', keywords: 'hello bye hi' },\n  { char: '✌️', name: 'Peace', keywords: 'victory' },\n  { char: '❤️', name: 'Red heart', keywords: 'love heart' },\n  { char: '\\u{1F525}', name: 'Fire', keywords: 'hot lit' },\n  { char: '⭐', name: 'Star', keywords: 'favorite' },\n  { char: '\\u{1F4AF}', name: 'Hundred', keywords: 'perfect score' },\n  { char: '✅', name: 'Check', keywords: 'done yes' },\n  { char: '❌', name: 'Cross', keywords: 'no wrong' },\n  { char: '⚡', name: 'Lightning', keywords: 'fast zap power' },\n  { char: '\\u{1F4A1}', name: 'Idea', keywords: 'light bulb' },\n  { char: '\\u{1F3AF}', name: 'Target', keywords: 'goal bullseye' },\n  { char: '\\u{1F680}', name: 'Rocket', keywords: 'launch ship' },\n  { char: '\\u{1F389}', name: 'Party popper', keywords: 'tada celebrate party' },\n  { char: '\\u{1F3C6}', name: 'Trophy', keywords: 'win prize' },\n  { char: '\\u{1F4C5}', name: 'Calendar', keywords: 'date schedule' },\n  { char: '\\u{1F4CC}', name: 'Pin', keywords: 'pushpin save' },\n  { char: '\\u{1F4CE}', name: 'Paperclip', keywords: 'attach' },\n  { char: '\\u{1F4AC}', name: 'Speech bubble', keywords: 'chat comment' },\n  { char: '\\u{1F4C8}', name: 'Chart up', keywords: 'growth rise' },\n  { char: '\\u{1F514}', name: 'Bell', keywords: 'notify alert' },\n  { char: '\\u{1F512}', name: 'Lock', keywords: 'secure private' },\n  { char: '\\u{1F6E0}️', name: 'Tools', keywords: 'fix build' },\n  { char: '\\u{1F4E6}', name: 'Package', keywords: 'box ship delivery' },\n  { char: '☕', name: 'Coffee', keywords: 'tea break' },\n  { char: '\\u{1F355}', name: 'Pizza', keywords: 'food lunch' },\n  { char: '\\u{1F382}', name: 'Birthday cake', keywords: 'party sweet' },\n  { char: '\\u{1F30D}', name: 'Earth', keywords: 'world globe africa' },\n  { char: '\\u{1F31E}', name: 'Sun', keywords: 'bright day' },\n  { char: '\\u{1F319}', name: 'Moon', keywords: 'night' },\n  { char: '\\u{1F308}', name: 'Rainbow', keywords: 'colour pride' },\n  { char: '\\u{1F331}', name: 'Seedling', keywords: 'grow plant' },\n  { char: '\\u{1F333}', name: 'Tree', keywords: 'nature forest' },\n  { char: '\\u{1F418}', name: 'Elephant', keywords: 'animal' },\n  { char: '\\u{1F981}', name: 'Lion', keywords: 'animal brave' },\n  { char: '\\u{1F422}', name: 'Turtle', keywords: 'slow animal' },\n  { char: '✈️', name: 'Plane', keywords: 'travel flight' },\n  { char: '\\u{1F6B2}', name: 'Bicycle', keywords: 'bike ride' },\n  { char: '⚽', name: 'Football', keywords: 'soccer sport' },\n  { char: '\\u{1F3B5}', name: 'Music', keywords: 'note song' },\n  { char: '\\u{1F4F7}', name: 'Camera', keywords: 'photo picture' },\n  { char: '\\u{1F381}', name: 'Gift', keywords: 'present surprise' },\n  { char: '\\u{1F9E0}', name: 'Brain', keywords: 'smart mind' },\n  { char: '\\u{1F91D}', name: 'Handshake', keywords: 'deal agree' },\n  { char: '\\u{1F642}', name: 'Slight smile', keywords: 'calm fine' },\n];\n\nexport function matchingEmoji(query: string) {\n  const needle = query.trim().toLowerCase();\n  if (needle === '') {\n    return EMOJI;\n  }\n  return EMOJI.filter((item) => {\n    const haystack = `${item.name} ${item.keywords}`.toLowerCase();\n    return haystack.includes(needle);\n  });\n}\n\ntype Axial = {\n  q: number;\n  r: number;\n};\n\nconst SIDES: Axial[] = [\n  { q: 1, r: 0 },\n  { q: 1, r: -1 },\n  { q: 0, r: -1 },\n  { q: -1, r: 0 },\n  { q: -1, r: 1 },\n  { q: 0, r: 1 },\n];\n\nfunction ringOf(radius: number): Axial[] {\n  const cells: Axial[] = [];\n  let q = -radius;\n  let r = radius;\n  for (const side of SIDES) {\n    for (let step = 0; step < radius; step += 1) {\n      cells.push({ q, r });\n      q += side.q;\n      r += side.r;\n    }\n  }\n  return cells;\n}\n\nfunction pixelOf(cell: Axial, spacing: number): Cell {\n  const rowHeight = (Math.sqrt(3) / 2) * spacing;\n  return { x: spacing * (cell.q + cell.r / 2), y: rowHeight * cell.r };\n}\n\nexport function hexSpiralOf(count: number, spacing: number) {\n  const axials: Axial[] = [{ q: 0, r: 0 }];\n  for (let radius = 1; axials.length < count; radius += 1) {\n    axials.push(...ringOf(radius));\n  }\n  return axials.slice(0, count).map((cell) => pixelOf(cell, spacing));\n}\n\nexport function reachOf(cells: Cell[]) {\n  const reaches = cells.map((cell) => Math.hypot(cell.x, cell.y));\n  return Math.max(0, ...reaches);\n}\n\nexport function neighborIndexOf(\n  cells: Cell[],\n  from: number,\n  directionX: number,\n  directionY: number\n) {\n  const origin = cells[from];\n  let best = -1;\n  let bestScore = Infinity;\n  cells.forEach((cell, index) => {\n    if (index === from) {\n      return;\n    }\n    const dx = cell.x - origin.x;\n    const dy = cell.y - origin.y;\n    const distance = Math.hypot(dx, dy);\n    const alignment = (dx * directionX + dy * directionY) / distance;\n    if (alignment < 0.45) {\n      return;\n    }\n    const score = distance * (2 - alignment);\n    if (score < bestScore) {\n      bestScore = score;\n      best = index;\n    }\n  });\n  return best;\n}\n",
      "type": "registry:component",
      "target": "components/popover/_parts/emoji-data.ts"
    },
    {
      "path": "registry/ndeko/components/popover/_parts/emoji-field.tsx",
      "content": "'use client';\n\nimport {\n  useCallback,\n  useEffect,\n  useImperativeHandle,\n  useLayoutEffect,\n  useMemo,\n  useRef,\n  useState,\n  type KeyboardEvent,\n  type PointerEvent,\n  type Ref,\n} from 'react';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nimport {\n  hexSpiralOf,\n  neighborIndexOf,\n  reachOf,\n  type Cell,\n  type EmojiItem,\n} from './emoji-data';\n\nexport const FIELD_DIAMETER_PX = 272;\n\nconst RADIUS_PX = FIELD_DIAMETER_PX / 2;\nconst SPACING_PX = 46;\nconst ITEM_PX = 36;\nconst DRAG_THRESHOLD_PX = 5;\nconst REPACK_MS = 340;\nconst RESTING_SPEED = 0.02;\nconst COMFORT_SHARE = 0.55;\nconst KEY_LANDING_SHARE = 0.3;\n\nconst ARROW_DIRECTIONS: Record<string, Cell> = {\n  ArrowRight: { x: 1, y: 0 },\n  ArrowLeft: { x: -1, y: 0 },\n  ArrowDown: { x: 0, y: 1 },\n  ArrowUp: { x: 0, y: -1 },\n};\n\ntype Motion = {\n  x: number;\n  y: number;\n  vx: number;\n  vy: number;\n  target: Cell | null;\n  frame: number;\n  lastTime: number;\n};\n\ntype Drag = {\n  startX: number;\n  startY: number;\n  lastX: number;\n  lastY: number;\n  lastTime: number;\n  hasMoved: boolean;\n};\n\nexport type EmojiFieldHandle = {\n  glideTo: (char: string) => void;\n  pick: (char: string) => void;\n  focusFirst: () => void;\n};\n\nfunction swellOf(distance: number) {\n  const share = Math.min(1, distance / RADIUS_PX);\n  return 1.35 - 0.9 * share;\n}\n\nfunction fadeOf(distance: number) {\n  const past = (distance - RADIUS_PX * 0.7) / (RADIUS_PX * 0.4);\n  const share = Math.min(1, Math.max(0, past));\n  return 1 - share * 0.65;\n}\n\nfunction withinReach(x: number, y: number, reach: number) {\n  const distance = Math.hypot(x, y);\n  if (distance <= reach) {\n    return { x, y, isOut: false };\n  }\n  const shrink = reach / distance;\n  return { x: x * shrink, y: y * shrink, isOut: true };\n}\n\nfunction tabIndexOf(isActive: boolean) {\n  if (isActive) {\n    return 0;\n  }\n  return -1;\n}\n\ntype EmojiFieldProps = {\n  items: EmojiItem[];\n  query: string;\n  onPick: (item: EmojiItem, from: DOMRect) => void;\n  handleRef?: Ref<EmojiFieldHandle>;\n  className?: string;\n};\n\nexport function EmojiField({\n  items,\n  query,\n  onPick,\n  handleRef,\n  className,\n}: EmojiFieldProps) {\n  const fieldRef = useRef<HTMLDivElement>(null);\n  const itemRefs = useRef<(HTMLButtonElement | null)[]>([]);\n  const cellsRef = useRef<Cell[]>([]);\n  const motion = useRef<Motion>({\n    x: 0,\n    y: 0,\n    vx: 0,\n    vy: 0,\n    target: null,\n    frame: 0,\n    lastTime: 0,\n  });\n  const drag = useRef<Drag | null>(null);\n  const cells = useMemo(\n    () => hexSpiralOf(items.length, SPACING_PX),\n    [items.length]\n  );\n  const [activeChar, setActiveChar] = useState('');\n  const focusableChar = focusableCharOf(items, activeChar);\n\n  const paint = useCallback(() => {\n    const placed = cellsRef.current;\n    const { x: offsetX, y: offsetY } = motion.current;\n    placed.forEach((cell, index) => {\n      const element = itemRefs.current[index];\n      if (!element) {\n        return;\n      }\n      const x = cell.x + offsetX;\n      const y = cell.y + offsetY;\n      const distance = Math.hypot(x, y);\n      const scale = swellOf(distance);\n      element.style.transform = `translate(${x}px, ${y}px) scale(${scale})`;\n      element.style.opacity = String(fadeOf(distance));\n    });\n  }, []);\n\n  const advance = useCallback(\n    (now: number) => {\n      const state = motion.current;\n      const elapsed = Math.min(now - state.lastTime, 32);\n      state.lastTime = now;\n      const reach = reachOf(cellsRef.current);\n      let isMoving = false;\n      if (state.target) {\n        const follow = 1 - Math.exp(-elapsed / 110);\n        state.x += (state.target.x - state.x) * follow;\n        state.y += (state.target.y - state.y) * follow;\n        const gap = Math.hypot(\n          state.target.x - state.x,\n          state.target.y - state.y\n        );\n        isMoving = gap > 0.4;\n        if (!isMoving) {\n          state.x = state.target.x;\n          state.y = state.target.y;\n          state.target = null;\n        }\n      } else {\n        state.x += state.vx * elapsed;\n        state.y += state.vy * elapsed;\n        const decay = Math.exp(-elapsed / 360);\n        state.vx *= decay;\n        state.vy *= decay;\n        const speed = Math.hypot(state.vx, state.vy);\n        isMoving = speed > RESTING_SPEED;\n      }\n      const kept = withinReach(state.x, state.y, reach);\n      state.x = kept.x;\n      state.y = kept.y;\n      if (kept.isOut) {\n        state.vx = 0;\n        state.vy = 0;\n      }\n      paint();\n      return isMoving;\n    },\n    [paint]\n  );\n\n  const startLoop = useCallback(() => {\n    const state = motion.current;\n    if (state.frame !== 0) {\n      return;\n    }\n    state.lastTime = performance.now();\n\n    function frame(now: number) {\n      const isMoving = advance(now);\n      if (isMoving) {\n        state.frame = requestAnimationFrame(frame);\n        return;\n      }\n      state.frame = 0;\n    }\n\n    state.frame = requestAnimationFrame(frame);\n  }, [advance]);\n\n  useLayoutEffect(() => {\n    cellsRef.current = cells;\n    const state = motion.current;\n    const field = fieldRef.current;\n    state.x = 0;\n    state.y = 0;\n    state.vx = 0;\n    state.vy = 0;\n    state.target = null;\n    if (field) {\n      field.dataset.repack = 'true';\n    }\n    paint();\n    const timer = window.setTimeout(() => {\n      if (field) {\n        delete field.dataset.repack;\n      }\n    }, REPACK_MS);\n    return () => window.clearTimeout(timer);\n  }, [items, cells, paint]);\n\n  useEffect(() => {\n    const state = motion.current;\n    return () => cancelAnimationFrame(state.frame);\n  }, []);\n\n  function offsetToLand(index: number) {\n    const cell = cellsRef.current[index];\n    const state = motion.current;\n    const x = cell.x + state.x;\n    const y = cell.y + state.y;\n    const distance = Math.hypot(x, y);\n    if (distance <= RADIUS_PX * COMFORT_SHARE) {\n      return null;\n    }\n    const landing = (RADIUS_PX * KEY_LANDING_SHARE) / distance;\n    return { x: state.x + x * landing - x, y: state.y + y * landing - y };\n  }\n\n  function glideTo(index: number) {\n    const target = offsetToLand(index);\n    if (target === null) {\n      return;\n    }\n    motion.current.target = target;\n    startLoop();\n  }\n\n  function pickAt(index: number) {\n    const element = itemRefs.current[index];\n    const item = items[index];\n    if (!element || !item) {\n      return;\n    }\n    onPick(item, element.getBoundingClientRect());\n  }\n\n  useImperativeHandle(handleRef, () => ({\n    glideTo(char: string) {\n      const index = items.findIndex((item) => item.char === char);\n      if (index === -1) {\n        return;\n      }\n      const cell = cellsRef.current[index];\n      motion.current.target = { x: -cell.x * 0.7, y: -cell.y * 0.7 };\n      startLoop();\n    },\n    pick(char: string) {\n      const index = items.findIndex((item) => item.char === char);\n      pickAt(index);\n    },\n    focusFirst() {\n      itemRefs.current[0]?.focus({ preventScroll: true });\n    },\n  }));\n\n  function startDrag(event: PointerEvent<HTMLDivElement>) {\n    if (event.button !== 0) {\n      return;\n    }\n    drag.current = {\n      startX: event.clientX,\n      startY: event.clientY,\n      lastX: event.clientX,\n      lastY: event.clientY,\n      lastTime: event.timeStamp,\n      hasMoved: false,\n    };\n  }\n\n  function moveDrag(event: PointerEvent<HTMLDivElement>) {\n    const current = drag.current;\n    if (!current) {\n      return;\n    }\n    const travel = Math.hypot(\n      event.clientX - current.startX,\n      event.clientY - current.startY\n    );\n    if (!current.hasMoved && travel < DRAG_THRESHOLD_PX) {\n      return;\n    }\n    const state = motion.current;\n    if (!current.hasMoved) {\n      current.hasMoved = true;\n      event.currentTarget.setPointerCapture(event.pointerId);\n      state.target = null;\n      state.vx = 0;\n      state.vy = 0;\n    }\n    const elapsed = Math.max(1, event.timeStamp - current.lastTime);\n    const dx = event.clientX - current.lastX;\n    const dy = event.clientY - current.lastY;\n    state.vx = state.vx * 0.5 + (dx / elapsed) * 0.5;\n    state.vy = state.vy * 0.5 + (dy / elapsed) * 0.5;\n    const reach = reachOf(cellsRef.current);\n    const kept = withinReach(state.x + dx, state.y + dy, reach);\n    state.x = kept.x;\n    state.y = kept.y;\n    current.lastX = event.clientX;\n    current.lastY = event.clientY;\n    current.lastTime = event.timeStamp;\n    paint();\n  }\n\n  function endDrag(event: PointerEvent<HTMLDivElement>) {\n    const current = drag.current;\n    drag.current = null;\n    if (!current || !current.hasMoved) {\n      return;\n    }\n    const idleMs = event.timeStamp - current.lastTime;\n    if (idleMs > 90) {\n      motion.current.vx = 0;\n      motion.current.vy = 0;\n    }\n    startLoop();\n  }\n\n  function moveFocus(event: KeyboardEvent<HTMLButtonElement>, index: number) {\n    const lastIndex = items.length - 1;\n    let next = -1;\n    const direction = ARROW_DIRECTIONS[event.key];\n    if (direction) {\n      next = neighborIndexOf(cellsRef.current, index, direction.x, direction.y);\n    }\n    if (event.key === 'Home') {\n      next = 0;\n    }\n    if (event.key === 'End') {\n      next = lastIndex;\n    }\n    if (next === -1) {\n      return;\n    }\n    event.preventDefault();\n    setActiveChar(items[next].char);\n    itemRefs.current[next]?.focus({ preventScroll: true });\n    glideTo(next);\n  }\n\n  const isEmpty = items.length === 0;\n\n  return (\n    <div\n      ref={fieldRef}\n      role='group'\n      aria-label='Emoji'\n      onPointerDown={startDrag}\n      onPointerMove={moveDrag}\n      onPointerUp={endDrag}\n      onPointerCancel={endDrag}\n      className={cn(\n        'group/field bg-foreground/[0.04] relative shrink-0 touch-none overflow-hidden rounded-full select-none',\n        className\n      )}\n      style={{ width: FIELD_DIAMETER_PX, height: FIELD_DIAMETER_PX }}\n    >\n      {items.map((item, index) => (\n        <button\n          key={item.char}\n          ref={(element) => {\n            itemRefs.current[index] = element;\n          }}\n          type='button'\n          aria-label={item.name}\n          tabIndex={tabIndexOf(item.char === focusableChar)}\n          onClick={() => pickAt(index)}\n          onKeyDown={(event) => moveFocus(event, index)}\n          onFocus={() => setActiveChar(item.char)}\n          className={cn(\n            'focus-visible:ring-ring absolute top-1/2 left-1/2 flex cursor-pointer items-center justify-center rounded-full text-xl outline-none focus-visible:ring-2',\n            'group-data-[repack=true]/field:transition-[transform,opacity] group-data-[repack=true]/field:duration-300 group-data-[repack=true]/field:ease-(--ease-out-strong)'\n          )}\n          style={{\n            width: ITEM_PX,\n            height: ITEM_PX,\n            marginLeft: -ITEM_PX / 2,\n            marginTop: -ITEM_PX / 2,\n          }}\n        >\n          {item.char}\n        </button>\n      ))}\n      {isEmpty && (\n        <p className='text-muted-foreground absolute inset-0 flex items-center justify-center px-12 text-center text-[13px]'>\n          No emoji for {'“'}\n          {query.trim()}\n          {'”'}\n        </p>\n      )}\n    </div>\n  );\n}\n\nfunction focusableCharOf(items: EmojiItem[], activeChar: string) {\n  const isShown = items.some((item) => item.char === activeChar);\n  if (isShown) {\n    return activeChar;\n  }\n  return items[0]?.char ?? '';\n}\n",
      "type": "registry:component",
      "target": "components/popover/_parts/emoji-field.tsx"
    }
  ],
  "categories": [
    "components",
    "popover"
  ],
  "type": "registry:component"
}