{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"fuzzy-match-input","type":"registry:component","title":"Fuzzy Match Input","description":"A fuzzy search field that scores by run length and word starts and lights up the exact letters that matched. Results slide to their new rank as you type, a spring cursor follows the arrow keys, scores get a small bar, and recent picks and a calm no-match state are built in. Dark or light, dependency-free.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/fuzzy-match-input.tsx","content":"\"use client\";\n\nimport {\n  useEffect,\n  useId,\n  useLayoutEffect,\n  useMemo,\n  useRef,\n  useState,\n  type CSSProperties,\n} from \"react\";\n\ntype Match = { indices: number[]; score: number } | null;\n\n/**\n * Subsequence matcher. Returns the matched INDICES as well as a score -\n * returning only a boolean is why most \"fuzzy search\" fields cannot highlight\n * what actually matched.\n */\nexport function fuzzyMatch(query: string, target: string): Match {\n  if (!query) return { indices: [], score: 0 };\n  const q = query.toLowerCase();\n  const t = target.toLowerCase();\n\n  const indices: number[] = [];\n  let score = 0;\n  let run = 0;\n  let ti = 0;\n\n  for (let qi = 0; qi < q.length; qi++) {\n    const ch = q.charAt(qi);\n    if (ch === \" \") continue;\n\n    let found = -1;\n    while (ti < t.length) {\n      if (t.charAt(ti) === ch) {\n        found = ti;\n        break;\n      }\n      ti++;\n    }\n    if (found === -1) return null; // a query char is missing -> no match\n\n    // Consecutive hits are worth far more than scattered ones, so \"cmd\"\n    // prefers a contiguous run over three letters spread across the string.\n    const prev = indices.length > 0 ? (indices[indices.length - 1] ?? -2) : -2;\n    indices.push(found);\n    run = found === prev + 1 ? run + 1 : 0;\n    score += 1 + run * 4;\n    // Word starts are a strong signal of intent.\n    if (found === 0 || t.charAt(found - 1) === \" \" || t.charAt(found - 1) === \"-\") score += 6;\n    ti = found + 1;\n  }\n\n  return { indices, score };\n}\n\nexport type FuzzyMatchInputProps = {\n  rows: readonly string[];\n  /** Most rows shown at once. */\n  limit?: number;\n  placeholder?: string;\n  /** Print each row's match score (and a small bar), which makes the ranking legible. */\n  showScore?: boolean;\n  /** \"dark\" paints a near-black panel, \"light\" a white one. */\n  tone?: \"dark\" | \"light\";\n  /** Highlight colour (any CSS colour). Defaults to blue. */\n  accent?: string;\n  /** Controlled query. */\n  value?: string;\n  /** Initial query when uncontrolled. */\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  /** Fires on Enter or click/tap on a row. */\n  onSelect?: (row: string) => void;\n  /** Accessible name of the field. */\n  label?: string;\n  /** Headline of the no-match state. */\n  emptyText?: string;\n  className?: string;\n  style?: CSSProperties;\n};\n\nconst ROW = 44;\nconst MAX_VISIBLE = 8;\nconst EMPTY_H = 136;\nconst COLOR_RE = /^(#[0-9a-f]{3,8}|(rgb|hsl)a?\\([0-9\\s.,%/]+\\)|[a-z]{3,20})$/i;\nconst useIsoLayoutEffect = typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n\nconst CSS = [\n  \"@layer components {\",\n  \".fmi-root{--fmi-bg:#0b0c0f;--fmi-ring:rgba(255,255,255,.1);--fmi-ink:#f4f4f5;--fmi-mute:rgba(244,244,245,.56);--fmi-faint:rgba(244,244,245,.42);--fmi-pill:rgba(255,255,255,.065);--fmi-accent:#60a5fa;--fmi-shadow:0 30px 70px -28px rgba(0,0,0,.85),0 2px 0 rgba(255,255,255,.04) inset;--fmi-sheen:rgba(255,255,255,.2);position:relative;display:block;width:100%;isolation:isolate;overflow:hidden;border-radius:18px;background:var(--fmi-bg);color:var(--fmi-ink);box-shadow:0 0 0 1px var(--fmi-ring),var(--fmi-shadow);font-size:15px;line-height:1.35;text-align:left;-webkit-tap-highlight-color:transparent}\",\n  \".fmi-root[data-tone=light]{--fmi-bg:#ffffff;--fmi-ring:#e4e4e7;--fmi-ink:#18181b;--fmi-mute:#52525b;--fmi-faint:#71717a;--fmi-pill:rgba(24,24,27,.055);--fmi-accent:#2563eb;--fmi-shadow:0 26px 60px -30px rgba(24,24,27,.3);--fmi-sheen:rgba(255,255,255,0)}\",\n  \".fmi-root::before{content:'';position:absolute;left:12%;right:12%;top:0;height:1px;background:linear-gradient(90deg,transparent,var(--fmi-sheen),transparent);z-index:3;pointer-events:none}\",\n  \".fmi-root:focus-within{box-shadow:0 0 0 1px color-mix(in srgb,var(--fmi-accent) 55%,transparent),0 0 0 4px color-mix(in srgb,var(--fmi-accent) 16%,transparent),var(--fmi-shadow)}\",\n  \".fmi-glow{position:absolute;inset:0;z-index:0;pointer-events:none;opacity:0;transition:opacity .35s ease;background:radial-gradient(260px circle at var(--fmi-mx,50%) var(--fmi-my,0%),color-mix(in srgb,var(--fmi-accent) 11%,transparent),transparent 70%)}\",\n  \"@media (hover:hover){.fmi-root:hover .fmi-glow{opacity:1}}\",\n  \".fmi-in{position:relative;z-index:1;display:flex;align-items:center;gap:10px;height:56px;padding:0 10px 0 18px;border-bottom:1px solid var(--fmi-ring)}\",\n  \".fmi-sweep{position:absolute;left:0;right:0;bottom:-1px;height:2px;background:var(--fmi-accent);transform:scaleX(0);transform-origin:left;transition:transform .55s cubic-bezier(.22,1,.36,1)}\",\n  \".fmi-root:focus-within .fmi-sweep{transform:scaleX(1)}\",\n  \".fmi-ico{flex:none;width:18px;height:18px;color:var(--fmi-faint);transition:color .2s ease,transform .3s cubic-bezier(.34,1.4,.5,1)}\",\n  \".fmi-root:focus-within .fmi-ico{color:var(--fmi-accent);transform:scale(1.08)}\",\n  \".fmi-input{flex:1;min-width:0;height:100%;background:transparent;border:0;color:var(--fmi-ink);font:inherit;font-size:16px;letter-spacing:-.005em;caret-color:var(--fmi-accent)}\",\n  \".fmi-input,.fmi-input:focus,.fmi-input:focus-visible{outline:0!important;box-shadow:none}\",\n  \".fmi-input::placeholder{color:var(--fmi-faint);opacity:1}\",\n  \".fmi-x{flex:none;display:grid;place-items:center;width:40px;height:40px;border:0;border-radius:10px;background:transparent;color:var(--fmi-faint);cursor:pointer;transition:background .15s ease,color .15s ease,opacity .2s ease,transform .25s cubic-bezier(.34,1.4,.5,1)}\",\n  \".fmi-x svg{width:16px;height:16px}\",\n  \".fmi-x:hover{background:var(--fmi-pill);color:var(--fmi-ink)}\",\n  \".fmi-x:active{transform:scale(.9)}\",\n  \".fmi-x[data-off]{opacity:0;pointer-events:none;transform:scale(.7)}\",\n  \".fmi-x:focus-visible,.fmi-clear:focus-visible{outline:2px solid var(--fmi-accent)!important;outline-offset:1px!important;border-radius:10px!important}\",\n  \".fmi-hd{position:relative;z-index:1;display:flex;align-items:center;justify-content:space-between;height:30px;padding:0 18px;font-size:11px;letter-spacing:.14em;text-transform:uppercase;color:var(--fmi-faint)}\",\n  \".fmi-hd b{font-weight:500;font-variant-numeric:tabular-nums}\",\n  \".fmi-wrap{position:relative;z-index:1;transition:height .3s cubic-bezier(.22,1,.36,1)}\",\n  \".fmi-list{position:relative;height:100%;overflow-y:auto;overflow-x:hidden;overscroll-behavior:contain;scrollbar-width:none}\",\n  \".fmi-list::-webkit-scrollbar{display:none}\",\n  \".fmi-pill{position:absolute;left:6px;right:6px;top:0;height:\" + ROW + \"px;border-radius:12px;background:var(--fmi-pill);pointer-events:none;transition:transform .32s cubic-bezier(.3,1.25,.5,1),opacity .2s ease,background .5s ease}\",\n  \".fmi-pill::before{content:'';position:absolute;left:0;top:13px;bottom:13px;width:2px;border-radius:2px;background:var(--fmi-accent)}\",\n  \".fmi-pill[data-flash]{background:color-mix(in srgb,var(--fmi-accent) 24%,transparent);transition:transform .32s cubic-bezier(.3,1.25,.5,1),background .08s ease}\",\n  \".fmi-row{position:relative;display:flex;align-items:center;gap:10px;height:\" + ROW + \"px;padding:0 18px;cursor:pointer;touch-action:manipulation}\",\n  \".fmi-lead{flex:none;width:14px;height:14px;display:grid;place-items:center;color:var(--fmi-faint)}\",\n  \".fmi-lead svg{width:14px;height:14px}\",\n  \".fmi-arrow{opacity:0;transform:translateX(-5px);transition:opacity .2s ease,transform .3s cubic-bezier(.22,1,.36,1);color:var(--fmi-accent)}\",\n  \".fmi-row[data-active] .fmi-arrow{opacity:1;transform:none}\",\n  \".fmi-text{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\",\n  \".fmi-c{color:var(--fmi-ink);transition:color .18s ease,box-shadow .18s ease}\",\n  \".fmi-root[data-q='1'] .fmi-c{color:var(--fmi-mute)}\",\n  \".fmi-root[data-q='1'] .fmi-row[data-active] .fmi-c{color:color-mix(in srgb,var(--fmi-ink) 78%,transparent)}\",\n  \".fmi-root[data-q='1'] .fmi-c[data-hit]{color:var(--fmi-accent);box-shadow:inset 0 -1.5px 0 color-mix(in srgb,var(--fmi-accent) 70%,transparent);transition-delay:calc(var(--k,0)*18ms)}\",\n  \".fmi-score{flex:none;display:flex;align-items:center;gap:8px;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:11px;color:var(--fmi-faint);font-variant-numeric:tabular-nums}\",\n  \".fmi-bar{display:block;width:30px;height:3px;border-radius:3px;background:var(--fmi-pill);overflow:hidden}\",\n  \".fmi-bar i{display:block;height:100%;width:100%;border-radius:3px;background:var(--fmi-accent);opacity:.8;transform-origin:left;transition:transform .45s cubic-bezier(.22,1,.36,1)}\",\n  \".fmi-check{flex:none;width:18px;height:18px;color:var(--fmi-accent);animation:fmi-pop .45s cubic-bezier(.34,1.5,.5,1) both}\",\n  \"@keyframes fmi-pop{from{opacity:0;transform:scale(.4)}to{opacity:1;transform:none}}\",\n  \".fmi-empty{position:relative;z-index:1;height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;padding:0 24px;text-align:center}\",\n  \".fmi-empty svg{width:22px;height:22px;color:var(--fmi-faint);margin-bottom:6px}\",\n  \".fmi-empty p{margin:0}\",\n  \".fmi-empty .t{font-size:14px;color:var(--fmi-ink);max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\",\n  \".fmi-empty .s{font-size:12.5px;color:var(--fmi-mute)}\",\n  \".fmi-clear{margin-top:10px;height:36px;min-width:40px;padding:0 14px;border:0;border-radius:10px;background:var(--fmi-pill);color:var(--fmi-ink);font:inherit;font-size:12.5px;cursor:pointer;transition:background .15s ease,transform .2s cubic-bezier(.34,1.4,.5,1)}\",\n  \".fmi-clear:hover{background:color-mix(in srgb,var(--fmi-accent) 20%,transparent)}\",\n  \".fmi-clear:active{transform:scale(.95)}\",\n  \".fmi-ft{position:relative;z-index:1;display:flex;align-items:center;gap:16px;height:38px;padding:0 18px;border-top:1px solid var(--fmi-ring);font-size:11.5px;color:var(--fmi-faint)}\",\n  \".fmi-ft span{display:inline-flex;align-items:center;gap:6px}\",\n  \".fmi-ft kbd{display:inline-grid;place-items:center;min-width:20px;height:20px;padding:0 5px;border-radius:6px;background:var(--fmi-pill);color:var(--fmi-mute);font:inherit;font-size:11px}\",\n  \"@media (hover:none){.fmi-ft{display:none}}\",\n  \".fmi-sr{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}\",\n  \"@media (prefers-reduced-motion:reduce){.fmi-root *,.fmi-root *::before{transition-duration:.01ms!important;transition-delay:0s!important;animation-duration:.01ms!important}}\",\n  \"}\",\n].join(\"\\n\");\n\nconst Svg = ({ d, className }: { d: string; className?: string }) => (\n  <svg\n    viewBox=\"0 0 24 24\"\n    fill=\"none\"\n    stroke=\"currentColor\"\n    strokeWidth=\"2\"\n    strokeLinecap=\"round\"\n    strokeLinejoin=\"round\"\n    aria-hidden=\"true\"\n    className={className}\n  >\n    <path d={d} />\n  </svg>\n);\n\ntype Item = { row: string; indices: number[]; score: number; recent: boolean };\n\nexport function FuzzyMatchInput({\n  rows,\n  limit = 5,\n  placeholder = \"Search…\",\n  showScore = true,\n  tone = \"dark\",\n  accent,\n  value,\n  defaultValue = \"\",\n  onValueChange,\n  onSelect,\n  label = \"Search\",\n  emptyText = \"Nothing matches\",\n  className,\n  style,\n}: FuzzyMatchInputProps) {\n  const uid = useId();\n  const listId = uid + \"-list\";\n  const [inner, setInner] = useState(defaultValue);\n  const query = value ?? inner;\n  const [active, setActive] = useState(0);\n  const [recent, setRecent] = useState<string[]>([]);\n  const [picked, setPicked] = useState<string | null>(null);\n  const inputRef = useRef<HTMLInputElement>(null);\n  const rootRef = useRef<HTMLDivElement>(null);\n  const listRef = useRef<HTMLDivElement>(null);\n  const prevPos = useRef<Map<string, number>>(new Map());\n  const timer = useRef(0);\n\n  const hasQuery = query.trim().length > 0;\n  const max = Math.max(1, Math.floor(limit));\n\n  const { items, total } = useMemo(() => {\n    const uniq = Array.from(new Set(rows));\n    if (!hasQuery) {\n      const rec = recent.filter((r) => uniq.includes(r)).slice(0, 3);\n      const list: Item[] = [\n        ...rec.map((row) => ({ row, indices: [], score: 0, recent: true })),\n        ...uniq.filter((r) => !rec.includes(r)).map((row) => ({ row, indices: [], score: 0, recent: false })),\n      ];\n      return { items: list.slice(0, max), total: uniq.length };\n    }\n    const scored: Item[] = [];\n    for (const row of uniq) {\n      const m = fuzzyMatch(query, row);\n      if (m) scored.push({ row, indices: m.indices, score: m.score, recent: false });\n    }\n    // Ties: the shorter row is the closer match. Array.sort is stable, so\n    // equal rows keep their input order.\n    scored.sort((a, b) => b.score - a.score || a.row.length - b.row.length);\n    return { items: scored.slice(0, max), total: scored.length };\n  }, [rows, query, hasQuery, recent, max]);\n\n  const n = items.length;\n  const ai = Math.min(active, Math.max(0, n - 1));\n  const topScore = items.reduce((m, it) => Math.max(m, it.score), 1);\n\n  // Rows slide to their new rank and new rows rise in. Positions are measured\n  // in layout pixels, so it also works inside a transform-scaled preview.\n  useIsoLayoutEffect(() => {\n    const list = listRef.current;\n    if (!list) return;\n    const calm = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const next = new Map<string, number>();\n    const els = list.querySelectorAll<HTMLElement>(\"[data-row]\");\n    els.forEach((el, idx) => {\n      const k = el.dataset.row ?? \"\";\n      const top = el.offsetTop;\n      next.set(k, top);\n      if (calm || typeof el.animate !== \"function\") return;\n      const was = prevPos.current.get(k);\n      if (was === undefined) {\n        el.animate(\n          [\n            { opacity: 0, transform: \"translateY(8px)\" },\n            { opacity: 1, transform: \"none\" },\n          ],\n          { duration: 260, delay: Math.min(idx, 6) * 28, easing: \"cubic-bezier(.22,1,.36,1)\", fill: \"backwards\" },\n        );\n      } else if (was !== top) {\n        el.animate([{ transform: \"translateY(\" + (was - top) + \"px)\" }, { transform: \"none\" }], {\n          duration: 340,\n          easing: \"cubic-bezier(.3,1.2,.5,1)\",\n        });\n      }\n    });\n    prevPos.current = next;\n  }, [items]);\n\n  const setQuery = (v: string) => {\n    if (value === undefined) setInner(v);\n    onValueChange?.(v);\n    setActive(0);\n  };\n\n  const choose = (row: string) => {\n    setRecent((r) => [row, ...r.filter((x) => x !== row)].slice(0, 6));\n    setPicked(row);\n    window.clearTimeout(timer.current);\n    timer.current = window.setTimeout(() => setPicked(null), 1100);\n    onSelect?.(row);\n  };\n\n  const reveal = (i: number) => {\n    const list = listRef.current;\n    if (!list) return;\n    const top = i * ROW;\n    if (top < list.scrollTop) list.scrollTop = top;\n    else if (top + ROW > list.scrollTop + list.clientHeight) list.scrollTop = top + ROW - list.clientHeight;\n  };\n\n  const onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n    if (e.nativeEvent.isComposing) return;\n    if ((e.key === \"ArrowDown\" || e.key === \"ArrowUp\") && n > 0) {\n      e.preventDefault();\n      const i = (ai + (e.key === \"ArrowDown\" ? 1 : n - 1)) % n;\n      setActive(i);\n      reveal(i);\n    } else if (e.key === \"Enter\") {\n      const it = items[ai];\n      if (it) {\n        e.preventDefault();\n        choose(it.row);\n      }\n    } else if (e.key === \"Escape\") {\n      if (query) {\n        e.preventDefault();\n        setQuery(\"\");\n      } else {\n        e.currentTarget.blur();\n      }\n    }\n  };\n\n  const onPointerMove = (e: React.PointerEvent<HTMLDivElement>) => {\n    const el = rootRef.current;\n    if (!el || e.pointerType !== \"mouse\") return;\n    const r = el.getBoundingClientRect();\n    if (!r.width) return;\n    const k = el.offsetWidth / r.width;\n    el.style.setProperty(\"--fmi-mx\", (e.clientX - r.left) * k + \"px\");\n    el.style.setProperty(\"--fmi-my\", (e.clientY - r.top) * k + \"px\");\n  };\n\n  const rootStyle = {\n    ...(accent && COLOR_RE.test(accent.trim()) ? { \"--fmi-accent\": accent.trim() } : null),\n    ...style,\n  } as CSSProperties;\n  const wrapH = n > 0 ? Math.min(n, MAX_VISIBLE) * ROW : EMPTY_H;\n  const heading = hasQuery ? \"Best matches\" : recent.length > 0 ? \"Recent\" : \"Suggested\";\n  const status = n > 0 ? (hasQuery ? total + (total === 1 ? \" match\" : \" matches\") : n + \" suggestions\") : \"No matches\";\n\n  return (\n    <div\n      ref={rootRef}\n      className={\"fmi-root\" + (className ? \" \" + className : \"\")}\n      style={rootStyle}\n      data-tone={tone === \"light\" ? \"light\" : \"dark\"}\n      data-q={hasQuery ? \"1\" : \"0\"}\n      onPointerMove={onPointerMove}\n    >\n      <style>{CSS}</style>\n      <div className=\"fmi-glow\" aria-hidden=\"true\" />\n\n      <div className=\"fmi-in\">\n        <svg\n          className=\"fmi-ico\"\n          viewBox=\"0 0 24 24\"\n          fill=\"none\"\n          stroke=\"currentColor\"\n          strokeWidth=\"2\"\n          strokeLinecap=\"round\"\n          aria-hidden=\"true\"\n        >\n          <circle cx=\"11\" cy=\"11\" r=\"7\" />\n          <path d=\"m20 20-3.6-3.6\" />\n        </svg>\n        <input\n          ref={inputRef}\n          value={query}\n          onChange={(e) => setQuery(e.target.value)}\n          onKeyDown={onKeyDown}\n          placeholder={placeholder}\n          aria-label={label}\n          role=\"combobox\"\n          aria-expanded={n > 0}\n          aria-controls={listId}\n          aria-autocomplete=\"list\"\n          aria-activedescendant={n > 0 ? uid + \"-o\" + ai : undefined}\n          className=\"fmi-input\"\n          type=\"text\"\n          autoComplete=\"off\"\n          autoCorrect=\"off\"\n          autoCapitalize=\"off\"\n          spellCheck={false}\n          enterKeyHint=\"go\"\n        />\n        <button\n          type=\"button\"\n          className=\"fmi-x\"\n          data-off={query ? undefined : \"\"}\n          aria-label=\"Clear search\"\n          tabIndex={query ? 0 : -1}\n          onClick={() => {\n            setQuery(\"\");\n            inputRef.current?.focus();\n          }}\n        >\n          <Svg d=\"M18 6 6 18M6 6l12 12\" />\n        </button>\n        <span className=\"fmi-sweep\" aria-hidden=\"true\" />\n      </div>\n\n      <div className=\"fmi-hd\" aria-hidden=\"true\">\n        <span>{heading}</span>\n        <b>{hasQuery && n > 0 ? n + \" of \" + total : \"\"}</b>\n      </div>\n\n      <div className=\"fmi-wrap\" style={{ height: wrapH }}>\n        {n > 0 ? (\n          <div className=\"fmi-list\" ref={listRef} role=\"listbox\" id={listId} aria-label={label + \" results\"}>\n            <div className=\"fmi-pill\" aria-hidden=\"true\" data-flash={picked ? \"\" : undefined} style={{ transform: \"translateY(\" + ai * ROW + \"px)\" }} />\n            {items.map((it, i) => {\n              const hit = new Set(it.indices);\n              let k = 0;\n              return (\n                <div\n                  key={it.row}\n                  id={uid + \"-o\" + i}\n                  role=\"option\"\n                  aria-selected={i === ai}\n                  aria-label={it.row}\n                  data-row={it.row}\n                  data-active={i === ai ? \"\" : undefined}\n                  className=\"fmi-row\"\n                  onPointerMove={(e) => {\n                    if (e.pointerType === \"mouse\" && i !== ai) setActive(i);\n                  }}\n                  onClick={() => {\n                    setActive(i);\n                    choose(it.row);\n                  }}\n                >\n                  <span className=\"fmi-lead\" aria-hidden=\"true\">\n                    {it.recent ? (\n                      <Svg d=\"M12 7v5l3 2M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z\" />\n                    ) : (\n                      <Svg className=\"fmi-arrow\" d=\"M5 12h14M13 6l6 6-6 6\" />\n                    )}\n                  </span>\n                  <span className=\"fmi-text\" aria-hidden=\"true\">\n                    {it.row.split(\"\").map((ch, ci) => {\n                      const on = hit.has(ci);\n                      return (\n                        <span\n                          key={ci}\n                          className=\"fmi-c\"\n                          data-hit={on ? \"\" : undefined}\n                          style={on ? ({ \"--k\": k++ } as CSSProperties) : undefined}\n                        >\n                          {ch}\n                        </span>\n                      );\n                    })}\n                  </span>\n                  {picked === it.row ? (\n                    <Svg className=\"fmi-check\" d=\"m5 12.5 4.5 4.5L19 7.5\" />\n                  ) : showScore && hasQuery ? (\n                    <span className=\"fmi-score\" aria-hidden=\"true\">\n                      <span className=\"fmi-bar\">\n                        <i style={{ transform: \"scaleX(\" + Math.max(0.08, it.score / topScore) + \")\" }} />\n                      </span>\n                      {it.score}\n                    </span>\n                  ) : null}\n                </div>\n              );\n            })}\n          </div>\n        ) : (\n          <div className=\"fmi-empty\">\n            <Svg d=\"M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14ZM20 20l-4-4M8.5 8.5l5 5M13.5 8.5l-5 5\" />\n            <p className=\"t\">\n              {emptyText} “{query.trim()}”\n            </p>\n            <p className=\"s\">Every letter has to appear in order. Try fewer.</p>\n            <button\n              type=\"button\"\n              className=\"fmi-clear\"\n              onClick={() => {\n                setQuery(\"\");\n                inputRef.current?.focus();\n              }}\n            >\n              Clear search\n            </button>\n          </div>\n        )}\n      </div>\n\n      <div className=\"fmi-ft\" aria-hidden=\"true\">\n        <span>\n          <kbd>↑</kbd>\n          <kbd>↓</kbd> move\n        </span>\n        <span>\n          <kbd>↵</kbd> pick\n        </span>\n        <span>\n          <kbd>esc</kbd> clear\n        </span>\n      </div>\n\n      <div className=\"fmi-sr\" role=\"status\" aria-live=\"polite\">\n        {status}\n      </div>\n    </div>\n  );\n}\n","type":"registry:component","target":"components/viberdy/fuzzy-match-input.tsx"}],"meta":{"tier":"free","tags":["search","fuzzy","input","filter","combobox","keyboard","highlight"],"href":"https://viberdy.dev/library/fuzzy-match-input","aiPrompt":"Build a dependency-free React \"FuzzyMatchInput\" as one \"use client\" file (React only; a plain <style> element in @layer components carries the CSS, classes prefixed fmi-). Export fuzzyMatch and FuzzyMatchInput plus the FuzzyMatchInputProps type.\n\nMatcher: fuzzyMatch(query, target) returns null or { indices, score }. Lowercase both, skip spaces in the query, walk the query in order advancing a pointer through the target; a missing character returns null. Return the matched INDICES, not just a boolean, so the UI can highlight. Score per matched character: 1 + run * 4, where run counts consecutive hits (reset to 0 on a gap), plus 6 when the hit is at index 0 or follows a space or hyphen. Empty query returns { indices: [], score: 0 }.\n\nProps: rows (readonly string[], required), limit = 5, placeholder = \"Search…\", showScore = true, tone \"dark\" (default) | \"light\", accent (any CSS colour, validated with a regex; defaults #60a5fa dark / #2563eb light), value / defaultValue = \"\" / onValueChange (controlled or uncontrolled), onSelect(row), label = \"Search\", emptyText = \"Nothing matches\", className and style on the root.\n\nResults: dedupe rows; with a query, score all, sort by score desc then shorter row first, slice to limit. With an empty query show recent picks first (up to 3, with a clock glyph) then the rest in order, header \"Recent\" or \"Suggested\"; with a query the header reads \"Best matches\" and \"n of total\". Each row is 44px: a 14px lead slot (arrow that slides in on the active row), the row text split into one span per character (hit characters get the accent colour, a 1.5px inset underline and a colour transition delayed 18ms per hit index; do NOT change font weight, it shifts widths), then a score: a 30px x 3px bar (scaleX = score / best score, min .08) and the number in a tabular mono 11px. Non-hit text is muted while a query is active.\n\nSurface: root is a full-width block, radius 18, near-black #0b0c0f (light: #fff), 1px ring made with box-shadow (not border), deep drop shadow, a 1px top sheen, a 260px pointer-following accent glow (11%) on hover-capable devices (map pointer coords through offsetWidth / rect.width). On :focus-within the ring becomes accent 55% plus a 4px accent 16% halo. Search row 56px high with a 2px accent underline that sweeps in from the left (550ms) on focus; input 16px, outline removed with !important, accent caret; a 40px clear button (scale/fade in when there is text).\n\nMotion: one absolute cursor pill (radius 12, accent 2px left tick) translates to the active row with transform .32s cubic-bezier(.3,1.25,.5,1). When results change, FLIP in a layout effect: rows whose offsetTop changed animate translateY(old - new) to none over 340ms cubic-bezier(.3,1.2,.5,1) with Element.animate; new rows rise 8px and fade in over 260ms with 28ms stagger (max 6). The list wrapper height transitions (.3s cubic-bezier(.22,1,.36,1)) to min(count, 8) * 44px; more than 8 rows scroll with the scrollbar hidden. Choosing a row (Enter or click) shows a pop-in check for 1.1s, flashes the pill, adds the row to recent (max 6) and calls onSelect.\n\nKeyboard: ArrowUp/Down wrap and keep the active row scrolled into view, Enter picks, Escape clears the query, or blurs when already empty. Mouse hover moves the active row (mouse pointers only). Input is role=combobox with aria-expanded, aria-controls, aria-autocomplete=list and aria-activedescendant; rows are role=option with aria-label = the row text and the per-letter spans aria-hidden; a visually hidden role=status region announces \"n matches\" / \"No matches\".\n\nEmpty state (136px tall): a crossed-search glyph, “Nothing matches “query””, \"Every letter has to appear in order. Try fewer.\", and a \"Clear search\" button that clears and refocuses. Footer (38px) lists the keys (up/down move, enter pick, esc clear) and is hidden on hover:none devices.\n\nReduced motion: all transitions/animations collapse to ~0 and the FLIP is skipped. Do not rely on any page colour tokens; light tone uses ring #e4e4e7, ink #18181b, mute #52525b.","license":"https://viberdy.dev/license"}}