{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"flip-grid-reorder","type":"registry:component","title":"FLIP Grid Reorder","description":"A filterable, shuffleable grid of rich tiles that travel to their new positions on a hand-sampled spring: survivors glide, leavers fade out of the flow, newcomers pop in, and a pointer light follows your cursor across each tile.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/flip-grid-reorder.tsx","content":"\"use client\";\n\nimport { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport type { CSSProperties, PointerEvent as ReactPointerEvent } from \"react\";\n\nexport type FlipGridItem = {\n  id: string;\n  /** Short label, shown as the pill on the card. */\n  label: string;\n  /** Which filter this tile belongs to. */\n  group: string;\n  /** Optional headline on the tile. Sorting uses it (or the label). */\n  title?: string;\n  /** Optional small line under the headline. */\n  meta?: string;\n  /** Optional 0-360 hue for the tile art. Derived from the group when omitted. */\n  hue?: number;\n};\n\nexport type FlipGridFilter = { id: string; label: string };\n\nconst DEFAULT_ITEMS: FlipGridItem[] = [\n  { id: \"halide\", label: \"01\", group: \"brand\", title: \"Halide Rail\", meta: \"Identity system\" },\n  { id: \"tessel\", label: \"02\", group: \"product\", title: \"Tessel Home\", meta: \"Mobile app\" },\n  { id: \"orbit\", label: \"03\", group: \"motion\", title: \"Orbit Loader\", meta: \"Loop, 4s\" },\n  { id: \"nocturne\", label: \"04\", group: \"brand\", title: \"Nocturne\", meta: \"Packaging\" },\n  { id: \"ledger\", label: \"05\", group: \"product\", title: \"Ledger Pro\", meta: \"Dashboard\" },\n  { id: \"tidemark\", label: \"06\", group: \"motion\", title: \"Tidemark\", meta: \"Title sequence\" },\n  { id: \"kiln\", label: \"07\", group: \"brand\", title: \"Kiln & Co.\", meta: \"Wordmark\" },\n  { id: \"meridian\", label: \"08\", group: \"product\", title: \"Meridian\", meta: \"Web platform\" },\n];\n\nconst DEFAULT_FILTERS: FlipGridFilter[] = [\n  { id: \"all\", label: \"All\" },\n  { id: \"brand\", label: \"Brand\" },\n  { id: \"product\", label: \"Product\" },\n  { id: \"motion\", label: \"Motion\" },\n];\n\nconst HUES = [214, 268, 332, 24, 164, 48];\nconst EASE_OUT = \"cubic-bezier(0.2, 0.9, 0.25, 1)\";\n\ntype Mode = \"original\" | \"shuffle\" | \"az\";\ntype Leaving = { item: FlipGridItem; left: number; top: number; w: number; h: number };\ntype Box = { l: number; t: number; w: number; h: number };\ntype Pending = { before: Map<string, Box>; hBefore: number; exiting: string[]; fx: boolean; reduce: boolean };\n\nconst CSS = [\n  \".fgr{--ink:#f4f5f7;--mute:rgba(244,245,247,.56);--tray:#111216;--tray-hi:#1a1b20;--line:rgba(255,255,255,.09);--chip:#f4f5f7;--chip-ink:#0b0c0e;--card:#0d0e11;--ring:rgba(255,255,255,.88);--halo:rgba(0,0,0,.6);--shadow:0 18px 36px -22px rgba(0,0,0,.9);color:var(--ink);container-type:inline-size;container-name:fgr;display:flex;flex-direction:column;gap:14px}\",\n  '.fgr[data-tone=\"light\"]{--ink:#14161a;--mute:rgba(20,22,26,.56);--tray:#eceef1;--tray-hi:#e1e4e8;--line:rgba(20,22,26,.1);--chip:#14161a;--chip-ink:#fff;--card:#fff;--ring:#14161a;--halo:rgba(255,255,255,.9);--shadow:0 18px 32px -22px rgba(20,22,26,.5)}',\n  \".fgr *{box-sizing:border-box}\",\n  \".fgr-bar{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:10px}\",\n  \".fgr-tray{position:relative;display:inline-flex;gap:2px;padding:4px;border-radius:999px;background:var(--tray);border:1px solid var(--line);max-width:100%;overflow-x:auto;scrollbar-width:none}\",\n  \".fgr-ind{position:absolute;top:4px;bottom:4px;left:0;width:0;border-radius:999px;background:var(--chip);box-shadow:0 4px 14px -6px rgba(0,0,0,.6);pointer-events:none;will-change:transform,width}\",\n  \".fgr-ind[data-ready]{transition:transform .5s \" + EASE_OUT + \",width .5s \" + EASE_OUT + \"}\",\n  \".fgr-btn{position:relative;z-index:1;display:inline-flex;align-items:center;justify-content:center;gap:7px;min-height:40px;padding:0 15px;border:0;border-radius:999px;background:transparent;color:var(--mute);font:500 13px/1 ui-sans-serif,system-ui,sans-serif;letter-spacing:.005em;white-space:nowrap;cursor:pointer;transition:color .25s,background-color .25s,transform .2s;-webkit-tap-highlight-color:transparent}\",\n  \".fgr-chip[aria-pressed=true]{color:var(--chip-ink)}\",\n  \".fgr-chip:hover{color:var(--ink)}.fgr-chip[aria-pressed=true]:hover{color:var(--chip-ink)}\",\n  \".fgr-count{font:500 10px/1 ui-monospace,SFMono-Regular,Menlo,monospace;opacity:.55;font-variant-numeric:tabular-nums}\",\n  \".fgr-tools{display:inline-flex;gap:6px}\",\n  \".fgr-tool{background:var(--tray);box-shadow:inset 0 0 0 1px var(--line);color:var(--ink);padding:0 14px 0 12px}\",\n  \".fgr-tool:hover{background:var(--tray-hi)}.fgr-tool:active{transform:scale(.96)}\",\n  \".fgr-tool[aria-pressed=true]{background:var(--chip);color:var(--chip-ink);box-shadow:none}\",\n  \".fgr-tool svg{flex:none;transition:transform .55s \" + EASE_OUT + \"}\",\n  \".fgr-btn:focus-visible{outline:2px solid var(--ring)!important;outline-offset:2px!important;border-radius:999px!important;box-shadow:0 0 0 5px var(--halo)!important}\",\n  \"@container fgr (min-width:560px){.fgr-btn{min-height:36px}}\",\n  \".fgr-grid{position:relative;display:grid;gap:10px;margin:0;padding:0;list-style:none;grid-template-columns:repeat(var(--cs,2),minmax(0,1fr));touch-action:pan-y}\",\n  \"@container fgr (min-width:460px){.fgr-grid{gap:12px;grid-template-columns:repeat(var(--c,4),minmax(0,1fr))}}\",\n  \".fgr-card{position:relative;aspect-ratio:1/1;list-style:none;margin:0;padding:0}\",\n  \".fgr-card[data-leaving]{aspect-ratio:auto;pointer-events:none}\",\n  \".fgr-in{position:absolute;inset:0;border-radius:18px;overflow:hidden;isolation:isolate;background:var(--card);border:1px solid var(--line);box-shadow:var(--shadow);transition:transform .45s \" + EASE_OUT + \",box-shadow .45s}\",\n  \".fgr-art{position:absolute;inset:0;z-index:-1;background:radial-gradient(120% 90% at 18% 6%,hsl(var(--h) 92% 68%/.96),transparent 56%),radial-gradient(95% 85% at 94% 104%,hsl(calc(var(--h) + 52) 88% 54%/.92),transparent 62%),linear-gradient(160deg,hsl(var(--h) 46% 17%),hsl(calc(var(--h) + 34) 52% 7%));transition:transform .8s \" + EASE_OUT + \"}\",\n  \".fgr-sheen{position:absolute;inset:0;z-index:-1;background:linear-gradient(115deg,transparent 30%,rgba(255,255,255,.16) 48%,transparent 66%);opacity:.5;mix-blend-mode:soft-light}\",\n  \".fgr-glow{position:absolute;inset:0;pointer-events:none;opacity:0;transition:opacity .3s;background:radial-gradient(170px circle at var(--mx,50%) var(--my,50%),rgba(255,255,255,.34),transparent 66%);mix-blend-mode:soft-light}\",\n  \".fgr-edge{position:absolute;inset:0;border-radius:inherit;padding:1px;pointer-events:none;opacity:0;transition:opacity .3s;background:radial-gradient(130px circle at var(--mx,50%) var(--my,50%),rgba(255,255,255,.85),transparent 70%);-webkit-mask:linear-gradient(#000 0 0) content-box,linear-gradient(#000 0 0);-webkit-mask-composite:xor;mask:linear-gradient(#000 0 0) content-box exclude,linear-gradient(#000 0 0)}\",\n  \".fgr-pill{position:absolute;top:10px;left:10px;padding:4px 8px;border-radius:999px;background:rgba(8,9,11,.42);box-shadow:inset 0 0 0 1px rgba(255,255,255,.16);backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px);color:#fff;font:500 10px/1 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.06em}\",\n  \".fgr-text{position:absolute;left:0;right:0;bottom:0;padding:38px 13px 12px;background:linear-gradient(to top,rgba(5,6,8,.82),rgba(5,6,8,.4) 55%,transparent);color:#fff}\",\n  \".fgr-title{margin:0;font:600 14px/1.2 ui-sans-serif,system-ui,sans-serif;letter-spacing:-.005em;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\",\n  \".fgr-sub{margin:3px 0 0;font:500 11px/1.2 ui-sans-serif,system-ui,sans-serif;color:rgba(255,255,255,.62);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\",\n  \"@media (hover:hover){.fgr-card:hover .fgr-in{transform:translateY(-3px);box-shadow:0 26px 40px -22px rgba(0,0,0,.95)}.fgr-card:hover .fgr-art{transform:scale(1.07)}.fgr-card:hover .fgr-glow,.fgr-card:hover .fgr-edge{opacity:1}}\",\n  \".fgr-card[data-lit] .fgr-glow,.fgr-card[data-lit] .fgr-edge{opacity:1}\",\n  \".fgr-empty{margin:0;padding:28px 0;text-align:center;color:var(--mute);font:500 13px/1.4 ui-sans-serif,system-ui,sans-serif}\",\n  \".fgr-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){.fgr-in,.fgr-art,.fgr-tool svg,.fgr-ind[data-ready]{transition:none!important}.fgr-card:hover .fgr-in,.fgr-card:hover .fgr-art{transform:none!important}}\",\n].join(\"\\n\");\n\nconst useIsoLayoutEffect = typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n\nconst prefersReduced = () =>\n  typeof window !== \"undefined\" &&\n  typeof window.matchMedia === \"function\" &&\n  window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n\n/* Sampled spring: progress 0 -> 1 for x'' = k(1 - x) - c x', unit mass. Cached per (k, c). */\nconst springCache = new Map<string, { p: number[]; ms: number }>();\nfunction spring(k: number, c: number) {\n  const key = k + \":\" + c;\n  const hit = springCache.get(key);\n  if (hit) return hit;\n  const dt = 1 / 240;\n  let x = 0;\n  let v = 0;\n  let t = 0;\n  const p: number[] = [0];\n  let settled = 0;\n  while (t < 1.6 && settled < 12) {\n    v += (k * (1 - x) - c * v) * dt;\n    x += v * dt;\n    t += dt;\n    if (Math.round(t / dt) % 4 === 0) {\n      p.push(x);\n      settled = Math.abs(1 - x) < 0.0015 && Math.abs(v) < 0.02 ? settled + 1 : 0;\n    }\n  }\n  p.push(1);\n  const out = { p, ms: Math.max(240, Math.round(t * 1000)) };\n  springCache.set(key, out);\n  return out;\n}\n\nfunction hash(s: string) {\n  let h = 2166136261;\n  for (let i = 0; i < s.length; i++) h = Math.imul(h ^ s.charCodeAt(i), 16777619);\n  return h >>> 0;\n}\n\nfunction order(items: FlipGridItem[], filter: string, mode: Mode, seed: number) {\n  const base = items.filter((i) => filter === \"all\" || i.group === filter);\n  if (mode === \"az\") {\n    return [...base].sort((a, b) => (a.title ?? a.label).localeCompare(b.title ?? b.label));\n  }\n  if (mode === \"shuffle\") {\n    const key = (i: FlipGridItem) => hash(i.id + \":\" + seed);\n    return [...base].sort((a, b) => key(a) - key(b));\n  }\n  return base;\n}\n\nexport function FlipGridReorder({\n  items = DEFAULT_ITEMS,\n  filters = DEFAULT_FILTERS,\n  columns = 4,\n  stiffness = 320,\n  fadeExit = true,\n  damping = 30,\n  controls = false,\n  defaultFilter = \"all\",\n  tone = \"dark\",\n  className,\n}: {\n  items?: FlipGridItem[];\n  filters?: FlipGridFilter[];\n  /** Columns when the component is at least 460px wide. Narrower, it uses two. */\n  columns?: number;\n  /** Spring stiffness for the reorder travel. */\n  stiffness?: number;\n  /** Fade and scale tiles as they enter and leave. Off, only layout moves. */\n  fadeExit?: boolean;\n  /** Spring damping. Lower is bouncier. */\n  damping?: number;\n  /** Show the Shuffle and A-Z buttons beside the filter chips (off by default). */\n  controls?: boolean;\n  /** Filter id selected on first render. */\n  defaultFilter?: string;\n  tone?: \"dark\" | \"light\";\n  className?: string;\n}) {\n  const [filter, setFilter] = useState(defaultFilter);\n  const [mode, setMode] = useState<Mode>(\"original\");\n  const [seed, setSeed] = useState(0);\n  const [leaving, setLeaving] = useState<Leaving[]>([]);\n\n  const gridRef = useRef<HTMLUListElement | null>(null);\n  const trayRef = useRef<HTMLDivElement | null>(null);\n  const indRef = useRef<HTMLDivElement | null>(null);\n  const nodes = useRef(new Map<string, HTMLLIElement>());\n  const moveAnims = useRef(new Map<string, Animation>());\n  const exitAnims = useRef(new Map<string, Animation>());\n  const heightAnim = useRef<Animation | null>(null);\n  const pending = useRef<Pending | null>(null);\n\n  const cols = Math.min(6, Math.max(1, Math.round(columns) || 4));\n  const visible = useMemo(() => order(items, filter, mode, seed), [items, filter, mode, seed]);\n  const visibleIds = useMemo(() => new Set(visible.map((i) => i.id)), [visible]);\n  const hueFor = useCallback(\n    (item: FlipGridItem) => {\n      if (typeof item.hue === \"number\" && isFinite(item.hue)) return Math.round(item.hue) % 360;\n      const gi = Math.max(0, filters.findIndex((f) => f.id === item.group) - 1);\n      return (HUES[gi % HUES.length] ?? 214) + (hash(item.id) % 24) - 12;\n    },\n    [filters],\n  );\n\n  /** Snapshot everything on screen, then commit the next state. */\n  const commit = (next: { filter?: string; mode?: Mode; seed?: number }) => {\n    const nf = next.filter ?? filter;\n    const nm = next.mode ?? mode;\n    const ns = next.seed ?? seed;\n    const grid = gridRef.current;\n    const reduce = prefersReduced();\n    const fx = fadeExit && !reduce;\n    if (grid) {\n      const gr = grid.getBoundingClientRect();\n      const s = grid.offsetWidth ? gr.width / grid.offsetWidth : 1;\n      const before = new Map<string, Box>();\n      nodes.current.forEach((el, id) => {\n        const r = el.getBoundingClientRect();\n        before.set(id, { l: r.left, t: r.top, w: r.width, h: r.height });\n      });\n      const nextIds = new Set(order(items, nf, nm, ns).map((i) => i.id));\n      const alreadyLeaving = new Set(leaving.map((l) => l.item.id));\n      const fresh: Leaving[] = [];\n      if (fx) {\n        before.forEach((r, id) => {\n          if (nextIds.has(id) || alreadyLeaving.has(id)) return;\n          const item = items.find((i) => i.id === id);\n          if (item) fresh.push({ item, left: (r.l - gr.left) / s, top: (r.t - gr.top) / s, w: r.w / s, h: r.h / s });\n        });\n      }\n      pending.current = { before, hBefore: gr.height / s, exiting: fresh.map((l) => l.item.id), fx, reduce };\n      setLeaving((prev) => (fx ? [...prev.filter((l) => !nextIds.has(l.item.id)), ...fresh] : []));\n    } else {\n      setLeaving([]);\n    }\n    if (next.filter !== undefined) setFilter(nf);\n    if (next.mode !== undefined) setMode(nm);\n    if (next.seed !== undefined) setSeed(ns);\n  };\n\n  // The FLIP: runs after the DOM has its new order, before paint.\n  useIsoLayoutEffect(() => {\n    const p = pending.current;\n    const grid = gridRef.current;\n    if (!p || !grid) return;\n    pending.current = null;\n    const gr0 = grid.getBoundingClientRect();\n    const s = grid.offsetWidth ? gr0.width / grid.offsetWidth : 1;\n\n    heightAnim.current?.cancel();\n    moveAnims.current.forEach((a) => a.cancel());\n    moveAnims.current.clear();\n    visibleIds.forEach((id) => {\n      exitAnims.current.get(id)?.cancel();\n      exitAnims.current.delete(id);\n    });\n\n    const sp = spring(Math.max(40, stiffness), Math.max(4, damping));\n    let enterIndex = 0;\n    visible.forEach((item) => {\n      const el = nodes.current.get(item.id);\n      if (!el) return;\n      const b = p.before.get(item.id);\n      if (b) {\n        if (p.reduce) return;\n        const r = el.getBoundingClientRect();\n        const dx = (b.l - r.left) / s;\n        const dy = (b.t - r.top) / s;\n        if (Math.abs(dx) + Math.abs(dy) < 0.5) return;\n        const frames = sp.p.map((v, i) => ({\n          offset: i / (sp.p.length - 1),\n          transform: \"translate(\" + (dx * (1 - v)).toFixed(2) + \"px,\" + (dy * (1 - v)).toFixed(2) + \"px)\",\n        }));\n        moveAnims.current.set(item.id, el.animate(frames, { duration: sp.ms, easing: \"linear\" }));\n      } else if (p.reduce) {\n        el.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 160, easing: \"ease-out\" });\n      } else if (p.fx) {\n        const delay = 60 + enterIndex++ * 28;\n        el.animate(\n          [\n            { opacity: 0, transform: \"scale(0.82)\" },\n            { opacity: 1, transform: \"scale(1)\" },\n          ],\n          { duration: 300, delay, easing: EASE_OUT, fill: \"backwards\" },\n        );\n      }\n    });\n\n    p.exiting.forEach((id) => {\n      const el = nodes.current.get(id);\n      if (!el) return;\n      const a = el.animate(\n        [\n          { opacity: 1, transform: \"scale(1)\" },\n          { opacity: 0, transform: \"scale(0.82)\" },\n        ],\n        { duration: 200, easing: \"ease-out\", fill: \"forwards\" },\n      );\n      exitAnims.current.set(id, a);\n      a.onfinish = () => {\n        exitAnims.current.delete(id);\n        setLeaving((l) => l.filter((x) => x.item.id !== id));\n      };\n    });\n\n    const hAfter = grid.getBoundingClientRect().height / s;\n    if (!p.reduce && Math.abs(hAfter - p.hBefore) > 1) {\n      heightAnim.current = grid.animate(\n        [{ height: p.hBefore + \"px\" }, { height: hAfter + \"px\" }],\n        { duration: 420, easing: EASE_OUT },\n      );\n    }\n  });\n\n  // Sliding chip indicator, measured in layout pixels.\n  useEffect(() => {\n    const tray = trayRef.current;\n    const ind = indRef.current;\n    if (!tray || !ind) return;\n    const place = () => {\n      const on = tray.querySelector<HTMLElement>('[data-chip][aria-pressed=\"true\"]');\n      if (!on) {\n        ind.style.width = \"0px\";\n        return;\n      }\n      ind.style.width = on.offsetWidth + \"px\";\n      ind.style.transform = \"translateX(\" + on.offsetLeft + \"px)\";\n    };\n    place();\n    const raf = requestAnimationFrame(() => ind.setAttribute(\"data-ready\", \"\"));\n    const ro = typeof ResizeObserver !== \"undefined\" ? new ResizeObserver(place) : null;\n    ro?.observe(tray);\n    return () => {\n      cancelAnimationFrame(raf);\n      ro?.disconnect();\n    };\n  }, [filter, filters]);\n\n  const lightUp = (e: ReactPointerEvent<HTMLUListElement>) => {\n    const li = (e.target as Element).closest?.(\"[data-fgr-card]\") as HTMLElement | null;\n    if (!li || li.hasAttribute(\"data-leaving\")) return;\n    const r = li.getBoundingClientRect();\n    const k = r.width ? li.offsetWidth / r.width : 1;\n    li.style.setProperty(\"--mx\", ((e.clientX - r.left) * k).toFixed(1) + \"px\");\n    li.style.setProperty(\"--my\", ((e.clientY - r.top) * k).toFixed(1) + \"px\");\n    if (e.pointerType !== \"mouse\") {\n      unlightOthers(e.currentTarget, li);\n      li.setAttribute(\"data-lit\", \"\");\n    }\n  };\n\n  const countFor = (id: string) => (id === \"all\" ? items.length : items.filter((i) => i.group === id).length);\n  const shown = visible.length;\n\n  const cardStyle = (item: FlipGridItem, extra?: CSSProperties) =>\n    ({ \"--h\": hueFor(item), ...extra }) as CSSProperties;\n\n  const renderCard = (item: FlipGridItem, out?: Leaving) => (\n    <li\n      key={item.id}\n      ref={(el) => {\n        if (el) nodes.current.set(item.id, el);\n        else nodes.current.delete(item.id);\n      }}\n      className=\"fgr-card\"\n      data-fgr-card=\"\"\n      data-leaving={out ? \"\" : undefined}\n      aria-hidden={out ? true : undefined}\n      style={\n        out\n          ? cardStyle(item, { position: \"absolute\", left: out.left, top: out.top, width: out.w, height: out.h, margin: 0 })\n          : cardStyle(item)\n      }\n    >\n      <div className=\"fgr-in\">\n        <div className=\"fgr-art\" />\n        <div className=\"fgr-sheen\" />\n        <span className=\"fgr-pill\">{item.label}</span>\n        {item.title || item.meta ? (\n          <div className=\"fgr-text\">\n            {item.title ? <p className=\"fgr-title\">{item.title}</p> : null}\n            {item.meta ? <p className=\"fgr-sub\">{item.meta}</p> : null}\n          </div>\n        ) : null}\n        <div className=\"fgr-glow\" />\n        <div className=\"fgr-edge\" />\n      </div>\n    </li>\n  );\n\n  return (\n    <div\n      className={\"fgr\" + (className ? \" \" + className : \"\")}\n      data-tone={tone === \"light\" ? \"light\" : \"dark\"}\n      style={{ \"--c\": cols, \"--cs\": Math.min(cols, 2) } as CSSProperties}\n    >\n      <style>{CSS}</style>\n\n      <div className=\"fgr-bar\">\n        <div className=\"fgr-tray\" ref={trayRef} role=\"group\" aria-label=\"Filter\">\n          <div className=\"fgr-ind\" ref={indRef} aria-hidden=\"true\" />\n          {filters.map((f) => (\n            <button\n              key={f.id}\n              type=\"button\"\n              data-chip=\"\"\n              className=\"fgr-btn fgr-chip\"\n              aria-pressed={filter === f.id}\n              onClick={() => filter !== f.id && commit({ filter: f.id })}\n            >\n              {f.label}\n              <span className=\"fgr-count\">{countFor(f.id)}</span>\n            </button>\n          ))}\n        </div>\n\n        {controls ? (\n          <div className=\"fgr-tools\" role=\"group\" aria-label=\"Arrange\">\n            <button\n              type=\"button\"\n              className=\"fgr-btn fgr-tool\"\n              onClick={() => commit({ mode: \"shuffle\", seed: seed + 1 })}\n            >\n              <svg width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" style={{ transform: \"rotate(\" + seed * 180 + \"deg)\" }}>\n                <path d=\"M16 3h5v5\" />\n                <path d=\"M4 20 21 3\" />\n                <path d=\"M21 16v5h-5\" />\n                <path d=\"m15 15 6 6\" />\n                <path d=\"m4 4 5 5\" />\n              </svg>\n              Shuffle\n            </button>\n            <button\n              type=\"button\"\n              className=\"fgr-btn fgr-tool\"\n              aria-pressed={mode === \"az\"}\n              onClick={() => commit({ mode: mode === \"az\" ? \"original\" : \"az\" })}\n            >\n              <svg width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                <path d=\"m3 16 4 4 4-4\" />\n                <path d=\"M7 20V4\" />\n                <path d=\"M15 5h5l-5 6h5\" />\n                <path d=\"M15 20v-3.5a2.5 2.5 0 0 1 5 0V20\" />\n                <path d=\"M15 17h5\" />\n              </svg>\n              A–Z\n            </button>\n          </div>\n        ) : null}\n      </div>\n\n      <ul\n        ref={gridRef}\n        className=\"fgr-grid\"\n        aria-label=\"Items\"\n        onPointerMove={lightUp}\n        onPointerDown={lightUp}\n      >\n        {visible.map((item) => renderCard(item))}\n        {leaving.filter((l) => !visibleIds.has(l.item.id)).map((l) => renderCard(l.item, l))}\n      </ul>\n\n      {shown === 0 ? <p className=\"fgr-empty\">Nothing in this filter yet.</p> : null}\n      <p className=\"fgr-sr\" role=\"status\" aria-live=\"polite\">\n        {\"Showing \" + shown + \" of \" + items.length + (mode === \"az\" ? \", sorted A to Z\" : mode === \"shuffle\" ? \", shuffled\" : \"\")}\n      </p>\n    </div>\n  );\n}\n\n/** Touch has no hover: keep exactly one tile lit, the one last touched. */\nfunction unlightOthers(grid: HTMLElement, keep: HTMLElement) {\n  grid.querySelectorAll(\"[data-lit]\").forEach((el) => {\n    if (el !== keep) el.removeAttribute(\"data-lit\");\n  });\n}\n","type":"registry:component","target":"components/viberdy/flip-grid-reorder.tsx"}],"meta":{"tier":"free","tags":["flip","layout","filter","grid","spring","shuffle","sort","tiles"],"href":"https://viberdy.dev/library/flip-grid-reorder","aiPrompt":"Create a React + TypeScript component named FlipGridReorder (one \"use client\" file, React only, no animation library, plain CSS in a <style> element, no site colour tokens): a filterable grid of tiles that travel to their new positions with a hand-written FLIP on the Web Animations API.\n\nProps: items ({id, label, group, title?, meta?, hue?}[], default 8 demo tiles in three groups), filters ({id, label}[], default All/Brand/Product/Motion; the id \"all\" means no filter), columns (default 4, clamped 1-6), stiffness (default 320), fadeExit (default true), damping (default 30), controls (default false, shows Shuffle and A-Z), defaultFilter (default \"all\"), tone (\"dark\" | \"light\", default \"dark\"), className.\n\nLayout: root is a flex column, gap 14px, container-type inline-size. A bar holds a pill tray of filter chips (each chip shows a tiny tabular count) and, on the right, two pill buttons Shuffle and A-Z (aria-pressed). The tray has a sliding indicator pill positioned from the pressed chip's offsetLeft/offsetWidth, transitioning transform and width over 500ms cubic-bezier(.2,.9,.25,1); no transition on first paint. Below, a <ul> CSS grid, gap 10px (12px from 460px container width), 2 columns below 460px and `columns` above, via a container query. Tiles are square <li> with an inner rounded-18px card: generated art from a hue h (two radial gradients hsl(h 92% 68%) top-left and hsl(h+52 88% 54%) bottom-right over a dark linear gradient), a mono pill with the label top-left, and a bottom scrim with the title (14px/600) and meta (11px). Hue defaults from the group index in `filters` plus a per-id jitter of +-12.\n\nFLIP: every state change goes through commit(). It reads getBoundingClientRect of every rendered tile (includes any running transform, so interruptions start from the visible position), computes the next visible ids, and stores the \"before\" boxes and the leaving tiles (those that will vanish: their box relative to the grid in layout pixels, divided by s = rect.width / offsetWidth). Leaving tiles stay rendered after the visible ones with position:absolute at that box (popLayout behaviour) so the survivors reflow at once. In a layout effect after commit: cancel previous move animations (and exit animations of tiles that came back), measure each visible tile again, and animate el.animate(keyframes, {duration, easing:\"linear\"}) from translate(dx,dy) to 0, where the keyframes are a sampled damped spring (unit mass, x'' = k(1-x) - c x', integrate at 240Hz, keep every 4th step until settled, cache per (k,c), duration = settle time, min 240ms). Entering tiles scale .82 -> 1 and fade 0 -> 1 over 300ms, delay 60ms + 28ms per entering tile, fill backwards. Leaving tiles scale 1 -> .82 and fade out over 200ms with fill forwards, then are removed from state. The grid's height animates between old and new values over 420ms. fadeExit=false skips enter/exit animation and removes leavers immediately. Keys are the stable item ids.\n\nShuffle sets a seed (seed+1) and orders by hash(id + \":\" + seed); A-Z toggles sorting by (title ?? label).localeCompare. Filtering applies first.\n\nPointer light: on pointermove over a tile set --mx/--my (layout px: (clientX - rect.left) * offsetWidth / rect.width). On hover show a soft-light radial glow (170px) and a 1px masked edge glow (130px, mask-composite exclude); the card lifts 3px and the art scales 1.07 (only inside @media (hover:hover)). On touch the last touched tile gets data-lit, which shows the same glow.\n\nTone light: chip tray #eceef1, cards white, text #14161a; dark: tray #111216, cards #0d0e11, text #f4f5f7.\n\nA11y: chips and tools are <button type=\"button\"> with aria-pressed; focus-visible uses an important 2px outline with a 5px halo in a contrasting colour so it reads on both page tones; buttons 40px tall (36px from 560px container width); leaving tiles are aria-hidden; a visually hidden role=\"status\" says \"Showing N of M\" plus \"sorted A to Z\" or \"shuffled\"; an empty filter shows \"Nothing in this filter yet.\" prefers-reduced-motion (matchMedia read at action time plus a CSS media query): tiles do not travel, the new order appears at once, entering tiles fade in over 160ms, leavers vanish, transitions are off.","license":"https://viberdy.dev/license"}}