{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ink-filter-bar",
  "title": "Ink Filter Bar",
  "description": "Filter chips beside a solid results pill. Pick a chip and ink buds out of the pill, pulls a liquid neck across the gap, and floods the chip until it docks into one capsule while the count rolls to the new number.",
  "dependencies": [
    "@rexa-developer/tiks",
    "motion",
    "web-haptics"
  ],
  "files": [
    {
      "path": "src/registry/components/ink-filter-bar/ink-filter-bar.tsx",
      "content": "\"use client\";\n\nimport { useTiks } from \"@rexa-developer/tiks/react\";\nimport { useReducedMotion } from \"motion/react\";\nimport {\n\ttype ComponentProps,\n\ttype KeyboardEvent,\n\ttype ReactNode,\n\tuseCallback,\n\tuseEffect,\n\tuseId,\n\tuseLayoutEffect,\n\tuseRef,\n\tuseState,\n} from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { useWebHaptics } from \"web-haptics/react\";\nimport { cn } from \"@/lib/utils\";\n\n// Layout, in px. Chips and the pill share one height, so the capsule is one\n// straight-sided shape once they dock.\nconst HEIGHT = 36;\nconst RADIUS = HEIGHT / 2;\n\n// Motion, in ms from the click. A merge buds a bead from the capsule, joins it\n// to the chip through a neck, floods the chip from its near edge, and docks it.\n/** The bead grows and travels across the gap. */\nconst BEAD_DURATION = 200;\n/** The neck reaches about half the chip's height. */\nconst NECK_DURATION = 180;\n/** Ink starts flooding the chip once the neck has formed. */\nconst FLOOD_DELAY = 120;\nconst FLOOD_DURATION = 300;\n/** The chip holds still while the bead buds, then springs into the capsule. */\nconst DOCK_DELAY = 90;\nconst dockSpring = { stiffness: 420, damping: 36 } as const;\n/** A detaching chip's neck thins out and snaps about 40% of the way through. */\nconst SNAP_DURATION = 170;\nconst DRAIN_DURATION = 320;\nconst DETACH_DURATION = 380;\nconst MERGE_DURATION = 560;\n/** Gap between chips draining back one after another when cleared. */\nconst CLEAR_STAGGER = 40;\n/** The divider fades in as the chip lands and out as soon as the last leaves. */\nconst DIVIDER_IN_DELAY = 260;\nconst DIVIDER_IN = 160;\nconst DIVIDER_OUT = 100;\n/** The clear button sinks into the capsule while chips move, then buds back. */\nconst CLEAR_OUT = 80;\nconst CLEAR_IN_DELAY = 440;\nconst CLEAR_IN = 160;\n/** How fast a neck fades when another chip lies across its path. */\nconst OPEN_RATE = 50;\n/** Blur of the goo filter, in px. A 0.5 alpha threshold keeps straight edges in place. */\nconst GOO_BLUR = 4.5;\n\n// The count rolls one digit at a time as the ink floods.\nconst ROLL_DURATION = 320;\nconst ROLL_STAGGER = 30;\nconst ROLL_EASE = \"cubic-bezier(0.3, 0.7, 0.2, 1)\";\n/** Reduced motion swaps the digits with a short fade instead. */\nconst SWAP_FADE = 120;\n/** Reduced motion moves chips at once and fades them in where they land. */\nconst CROSS_FADE = 150;\n/** The hover wobble: how far the outline ripples, in px, and one cycle. */\nconst WOBBLE_AMPLITUDE = 0.9;\nconst WOBBLE_PERIOD = 1800;\n/** Ms of quiet before the live region announces the count. */\nconst ANNOUNCE_DELAY = 300;\n\n// A soft wet drop when a chip is absorbed: a short sine blip that rises, over\n// a puff of filtered pink noise.\nconst DROP_SOUND = {\n\tname: \"ink-filter-bar-drop\",\n\tbaseFreq: 470,\n\tnoiseColor: \"pink\",\n\toscType: \"sine\",\n\tfilterFreq: 1400,\n\tfilterQ: 1,\n\tattack: 0.002,\n\tdecay: 1.4,\n\tbrightness: 3000,\n} as const;\n/** Lighter and shorter, falling, when a chip tears free. */\nconst UNSTICK_SOUND = {\n\t...DROP_SOUND,\n\tname: \"ink-filter-bar-unstick\",\n\tbaseFreq: 640,\n\tdecay: 0.9,\n} as const;\n\nexport interface InkFilterBarOption {\n\tvalue: string;\n\tlabel: ReactNode;\n\t/** Results for this option alone, shown after the label. */\n\tcount?: number;\n}\n\nexport interface InkFilterBarProps\n\textends Omit<\n\t\tComponentProps<\"div\">,\n\t\t\"children\" | \"defaultValue\" | \"onChange\" | \"role\"\n\t> {\n\toptions: readonly InkFilterBarOption[];\n\t/** Controlled selection, in the order the chips joined the capsule. */\n\tvalue?: string[];\n\t/** Initial selection when uncontrolled. */\n\tdefaultValue?: string[];\n\t/** Called with the new selection when a chip is toggled or cleared. */\n\tonValueChange?: (value: string[]) => void;\n\t/** `single` swaps the selected chip for the new one in one motion. */\n\ttype?: \"multiple\" | \"single\";\n\t/** The live result total shown in the pill. */\n\tcount: number;\n\t/** Text after the number in the pill and the live region. */\n\tlabel?: string;\n\t/** Formats the count. Defaults to `en-US` grouping, such as `1,204`. */\n\tformatCount?: (count: number) => string;\n\t/** Wrap chips onto more lines instead of scrolling the row. */\n\twrap?: boolean;\n\t/** Shows a clear button at the end of the capsule; called after it clears. */\n\tonClear?: () => void;\n\t/** Play a soft drop when a chip is absorbed and a lighter one when it detaches. */\n\tsound?: boolean;\n\t/** Trigger haptics on supported devices. */\n\thaptics?: boolean;\n\t/** Accessible name of the group of chips. */\n\t\"aria-label\": string;\n}\n\ninterface Box {\n\tleft: number;\n\ttop: number;\n\twidth: number;\n}\n\ninterface Tween {\n\tfrom: number;\n\tto: number;\n\tstart: number;\n\tduration: number;\n}\n\ninterface ChipMotion {\n\t/** Offset from the chip's layout slot, in px, sprung back to 0. */\n\tdx: number;\n\tdy: number;\n\tvx: number;\n\tvy: number;\n\t/** Time the spring has been stepped to; it holds until `holdUntil`. */\n\ttime: number;\n\tholdUntil: number;\n\t/** Distance from its slot when the current merge began. */\n\tdistance: number;\n\t/** Share of the chip flooded with ink, from its near edge. */\n\tink: Tween;\n\tkind: \"merge\" | \"detach\" | null;\n\tstart: number;\n\t/** How open the path to its anchor is: 0 while another chip lies across it. */\n\topen: number;\n\t/** Painted values, read by the next frame. */\n\tflood: number;\n\tbond: number;\n}\n\nfunction clamp(value: number, min = 0, max = 1) {\n\treturn Math.min(Math.max(value, min), max);\n}\n\nfunction round(value: number) {\n\treturn Math.round(value * 100) / 100;\n}\n\nfunction smoothstep(t: number) {\n\treturn t * t * (3 - 2 * t);\n}\n\nfunction easeOut(t: number) {\n\treturn 1 - (1 - t) ** 3;\n}\n\nfunction tweenAt(tween: Tween, now: number) {\n\tif (now <= tween.start) return tween.from;\n\tconst t =\n\t\ttween.duration > 0 ? clamp((now - tween.start) / tween.duration) : 1;\n\treturn tween.from + (tween.to - tween.from) * smoothstep(t);\n}\n\nfunction tweenEnd(tween: Tween) {\n\treturn tween.start + tween.duration;\n}\n\nfunction hold(value: number): Tween {\n\treturn { from: value, to: value, start: 0, duration: 0 };\n}\n\n/**\n * A chip's outline as a closed curve whose edge ripples by up to `amplitude`\n * px, for the hover wobble. Every phase has the same commands, so SMIL can\n * morph between them.\n */\nfunction wobblePath(width: number, phase: number, amplitude: number) {\n\tconst inset = 0.75;\n\tconst radius = HEIGHT / 2 - inset;\n\tconst straight = Math.max(width - inset * 2 - radius * 2, 0);\n\tconst arc = Math.PI * radius;\n\tconst perimeter = straight * 2 + arc * 2;\n\tconst count = 36;\n\tconst points: Array<[number, number]> = [];\n\tfor (let index = 0; index < count; index++) {\n\t\tconst along = (index / count) * perimeter;\n\t\t// Round the stadium: top edge, right cap, bottom edge, left cap.\n\t\tconst capRight = along - straight;\n\t\tconst bottom = capRight - arc;\n\t\tconst capLeft = bottom - straight;\n\t\tlet x: number;\n\t\tlet y: number;\n\t\tlet nx: number;\n\t\tlet ny: number;\n\t\tif (along < straight) {\n\t\t\tx = inset + radius + along;\n\t\t\ty = inset;\n\t\t\tnx = 0;\n\t\t\tny = -1;\n\t\t} else if (capRight < arc) {\n\t\t\tconst angle = -Math.PI / 2 + capRight / radius;\n\t\t\tnx = Math.cos(angle);\n\t\t\tny = Math.sin(angle);\n\t\t\tx = inset + radius + straight + nx * radius;\n\t\t\ty = HEIGHT / 2 + ny * radius;\n\t\t} else if (bottom < straight) {\n\t\t\tx = inset + radius + straight - bottom;\n\t\t\ty = HEIGHT - inset;\n\t\t\tnx = 0;\n\t\t\tny = 1;\n\t\t} else {\n\t\t\tconst angle = Math.PI / 2 + capLeft / radius;\n\t\t\tnx = Math.cos(angle);\n\t\t\tny = Math.sin(angle);\n\t\t\tx = inset + radius + nx * radius;\n\t\t\ty = HEIGHT / 2 + ny * radius;\n\t\t}\n\t\tconst t = (index / count) * Math.PI * 2;\n\t\tconst offset =\n\t\t\tamplitude *\n\t\t\t(0.6 * Math.sin(t * 5 + phase) + 0.4 * Math.sin(t * 3 - phase * 1.3));\n\t\tpoints.push([x + nx * offset, y + ny * offset]);\n\t}\n\t// Closed Catmull-Rom through the points, as cubic Béziers.\n\tconst at = (index: number) => points[(index + count) % count];\n\tlet d = `M${round(points[0][0])} ${round(points[0][1])}`;\n\tfor (let index = 0; index < count; index++) {\n\t\tconst [x0, y0] = at(index - 1);\n\t\tconst [x1, y1] = at(index);\n\t\tconst [x2, y2] = at(index + 1);\n\t\tconst [x3, y3] = at(index + 2);\n\t\td += `C${round(x1 + (x2 - x0) / 6)} ${round(y1 + (y2 - y0) / 6)} ${round(x2 - (x3 - x1) / 6)} ${round(y2 - (y3 - y1) / 6)} ${round(x2)} ${round(y2)}`;\n\t}\n\treturn `${d}Z`;\n}\n\nfunction defaultFormat(count: number) {\n\treturn count.toLocaleString(\"en-US\");\n}\n\nfunction sameList(a: readonly string[], b: readonly string[]) {\n\treturn a.length === b.length && a.every((item, index) => item === b[index]);\n}\n\n/** The hovered chip's outline, rippling slowly like a wet edge. */\nfunction WobbleOutline({ width }: { width: number | undefined }) {\n\tif (!width) return null;\n\tconst frames = [0, 2.1, 4.2, 0].map((phase) =>\n\t\twobblePath(width, phase, WOBBLE_AMPLITUDE),\n\t);\n\treturn (\n\t\t<svg\n\t\t\taria-hidden=\"true\"\n\t\t\tclassName=\"pointer-events-none absolute inset-0 size-full overflow-visible\"\n\t\t\tviewBox={`0 0 ${width} ${HEIGHT}`}\n\t\t>\n\t\t\t<path d={frames[0]} fill=\"none\" stroke=\"currentColor\" strokeWidth={1.5}>\n\t\t\t\t<animate\n\t\t\t\t\tattributeName=\"d\"\n\t\t\t\t\tdur={`${WOBBLE_PERIOD}ms`}\n\t\t\t\t\tvalues={frames.join(\";\")}\n\t\t\t\t\trepeatCount=\"indefinite\"\n\t\t\t\t/>\n\t\t\t</path>\n\t\t</svg>\n\t);\n}\n\n/** One digit as a vertical strip of 0 to 9, rolled to `digit`. */\nfunction RollingDigit({\n\tdigit,\n\tdelay,\n\treduced,\n}: {\n\tdigit: number;\n\tdelay: number;\n\treduced: boolean;\n}) {\n\treturn (\n\t\t<span className=\"relative inline-block h-[1lh] overflow-hidden\">\n\t\t\t<span\n\t\t\t\tclassName=\"flex flex-col\"\n\t\t\t\tstyle={{\n\t\t\t\t\ttransform: `translateY(${-digit * 10}%)`,\n\t\t\t\t\ttransition: reduced\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: `transform ${ROLL_DURATION}ms ${ROLL_EASE} ${delay}ms`,\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\t{Array.from({ length: 10 }, (_, index) => (\n\t\t\t\t\t<span\n\t\t\t\t\t\t// biome-ignore lint/suspicious/noArrayIndexKey: the strip is fixed\n\t\t\t\t\t\tkey={index}\n\t\t\t\t\t\tclassName=\"block h-[1lh] text-center\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{index}\n\t\t\t\t\t</span>\n\t\t\t\t))}\n\t\t\t</span>\n\t\t</span>\n\t);\n}\n\n/** The pill's number. Each digit rolls on its own, a beat after the last. */\nfunction RollingNumber({\n\ttext,\n\tdelay,\n\treduced,\n}: {\n\ttext: string;\n\tdelay: number;\n\treduced: boolean;\n}) {\n\tconst ref = useRef<HTMLSpanElement>(null);\n\tconst shown = useRef(text);\n\tconst chars = [...text];\n\tlet digitIndex = 0;\n\n\tuseEffect(() => {\n\t\tif (shown.current === text) return;\n\t\tshown.current = text;\n\t\tif (reduced) {\n\t\t\tref.current?.animate([{ opacity: 0 }, { opacity: 1 }], {\n\t\t\t\tduration: SWAP_FADE,\n\t\t\t\teasing: \"ease-out\",\n\t\t\t});\n\t\t}\n\t}, [text, reduced]);\n\n\treturn (\n\t\t// Numbers read left to right in RTL text too.\n\t\t<span ref={ref} dir=\"ltr\" className=\"inline-flex tabular-nums\">\n\t\t\t{chars.map((char, index) => {\n\t\t\t\t// Places are keyed from the right, so units stay units.\n\t\t\t\tconst place = chars.length - index;\n\t\t\t\tif (reduced || !/\\d/.test(char)) {\n\t\t\t\t\treturn <span key={`c${place}`}>{char}</span>;\n\t\t\t\t}\n\t\t\t\tconst order = digitIndex++;\n\t\t\t\treturn (\n\t\t\t\t\t<RollingDigit\n\t\t\t\t\t\tkey={`d${place}`}\n\t\t\t\t\t\tdigit={Number(char)}\n\t\t\t\t\t\tdelay={delay + order * ROLL_STAGGER}\n\t\t\t\t\t\treduced={reduced}\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t})}\n\t\t</span>\n\t);\n}\n\nexport function InkFilterBar({\n\toptions,\n\tvalue: valueProp,\n\tdefaultValue,\n\tonValueChange,\n\ttype = \"multiple\",\n\tcount,\n\tlabel = \"results\",\n\tformatCount = defaultFormat,\n\twrap = false,\n\tonClear,\n\tsound = true,\n\thaptics = true,\n\tclassName,\n\tonKeyDown,\n\t...props\n}: InkFilterBarProps) {\n\tconst [internalValue, setInternalValue] = useState<string[]>(\n\t\t() => defaultValue ?? [],\n\t);\n\tconst controlled = valueProp !== undefined;\n\tconst rawValue = controlled ? valueProp : internalValue;\n\tconst selected = rawValue.filter(\n\t\t(item, index) =>\n\t\t\trawValue.indexOf(item) === index &&\n\t\t\toptions.some((option) => option.value === item),\n\t);\n\tconst selectedKey = selected.join(\"\\u0000\");\n\tconst clearable = onClear !== undefined;\n\tconst showClear = clearable && selected.length > 0;\n\n\tconst reducedMotion = useReducedMotion() ?? false;\n\tconst [animating, setAnimating] = useState(false);\n\tconst [hovered, setHovered] = useState<string | null>(null);\n\tconst [focusValue, setFocusValue] = useState<string | null>(null);\n\tconst [announcement, setAnnouncement] = useState(\"\");\n\n\tconst { trigger: haptic } = useWebHaptics();\n\t// Sound stays on under reduced motion; only movement is reduced.\n\tconst { toggle: playDrop } = useTiks({\n\t\ttheme: DROP_SOUND,\n\t\trespectReducedMotion: false,\n\t});\n\tconst { toggle: playUnstick } = useTiks({\n\t\ttheme: UNSTICK_SOUND,\n\t\trespectReducedMotion: false,\n\t});\n\n\tconst ids = useId().replace(/[^\\w-]/g, \"\");\n\tconst gooId = `ink-filter-bar-${ids}-goo`;\n\n\tconst rootRef = useRef<HTMLDivElement>(null);\n\tconst scrollerRef = useRef<HTMLDivElement>(null);\n\tconst rowRef = useRef<HTMLDivElement>(null);\n\tconst pillRef = useRef<HTMLDivElement>(null);\n\tconst dividerRef = useRef<HTMLSpanElement>(null);\n\tconst clearRef = useRef<HTMLButtonElement>(null);\n\tconst chipRefs = useRef(new Map<string, HTMLButtonElement>());\n\tconst inkRefs = useRef(new Map<string, HTMLSpanElement>());\n\tconst svgRef = useRef<SVGSVGElement>(null);\n\tconst gooRef = useRef<SVGFilterElement>(null);\n\tconst flipRef = useRef<SVGGElement>(null);\n\tconst shapeRefs = useRef(\n\t\tnew Map<string, SVGRectElement | SVGCircleElement>(),\n\t);\n\n\t/** Layout slots, in px within the row, from the last commit. */\n\tconst boxesRef = useRef(new Map<string, Box>());\n\tconst motionsRef = useRef(new Map<string, ChipMotion>());\n\tconst previousRef = useRef<string[]>(selected);\n\tconst dividerTweenRef = useRef<Tween>(hold(selected.length > 0 ? 1 : 0));\n\t/** The clear button sinks with `clearOut`, then buds back with `clearIn`. */\n\tconst clearOutRef = useRef<Tween>(hold(showClear ? 1 : 0));\n\tconst clearInRef = useRef<Tween | null>(null);\n\tconst frameRef = useRef(0);\n\tconst lastFrameRef = useRef(0);\n\tconst rtlRef = useRef(false);\n\tconst rowSizeRef = useRef({ width: 0, height: 0 });\n\t/** When the last user toggle happened, so the count rolls with the flood. */\n\tconst toggledAtRef = useRef(Number.NEGATIVE_INFINITY);\n\n\t// Event handlers and the render loop read the latest props through refs.\n\tconst latest = useRef({\n\t\tselected,\n\t\tcontrolled,\n\t\tonValueChange,\n\t\tonClear,\n\t\ttype,\n\t\tsound,\n\t\thaptics,\n\t\treducedMotion,\n\t\toptions,\n\t\tshowClear,\n\t});\n\tuseLayoutEffect(() => {\n\t\tlatest.current = {\n\t\t\tselected,\n\t\t\tcontrolled,\n\t\t\tonValueChange,\n\t\t\tonClear,\n\t\t\ttype,\n\t\t\tsound,\n\t\t\thaptics,\n\t\t\treducedMotion,\n\t\t\toptions,\n\t\t\tshowClear,\n\t\t};\n\t});\n\n\tconst clearAt = (now: number) => {\n\t\tconst clearIn = clearInRef.current;\n\t\treturn clearIn && now >= clearIn.start\n\t\t\t? tweenAt(clearIn, now)\n\t\t\t: tweenAt(clearOutRef.current, now);\n\t};\n\n\tconst motionFor = (key: string, on: boolean) => {\n\t\tlet motion = motionsRef.current.get(key);\n\t\tif (!motion) {\n\t\t\tmotion = {\n\t\t\t\tdx: 0,\n\t\t\t\tdy: 0,\n\t\t\t\tvx: 0,\n\t\t\t\tvy: 0,\n\t\t\t\ttime: 0,\n\t\t\t\tholdUntil: 0,\n\t\t\t\tdistance: 0,\n\t\t\t\tink: hold(on ? 1 : 0),\n\t\t\t\tkind: null,\n\t\t\t\tstart: 0,\n\t\t\t\topen: 1,\n\t\t\t\tflood: 0,\n\t\t\t\tbond: 0,\n\t\t\t};\n\t\t\tmotionsRef.current.set(key, motion);\n\t\t}\n\t\treturn motion;\n\t};\n\n\tconst measure = useCallback(() => {\n\t\tconst row = rowRef.current;\n\t\tif (!row) return;\n\t\tconst boxes = new Map<string, Box>();\n\t\tconst read = (key: string, element: HTMLElement | null) => {\n\t\t\tif (!element || element.hidden) return;\n\t\t\tboxes.set(key, {\n\t\t\t\tleft: element.offsetLeft,\n\t\t\t\ttop: element.offsetTop,\n\t\t\t\twidth: element.offsetWidth,\n\t\t\t});\n\t\t};\n\t\tread(\"\\u0000pill\", pillRef.current);\n\t\tread(\"\\u0000clear\", clearRef.current);\n\t\tfor (const [key, element] of chipRefs.current) read(key, element);\n\t\tboxesRef.current = boxes;\n\t\trowSizeRef.current = { width: row.offsetWidth, height: row.offsetHeight };\n\t\trtlRef.current = getComputedStyle(row).direction === \"rtl\";\n\t}, []);\n\n\t/** Draws one frame: chip offsets, ink clips, and the goo shapes beneath. */\n\tconst paint = (now: number) => {\n\t\tconst boxes = boxesRef.current;\n\t\tconst rtl = rtlRef.current;\n\t\tconst { width: rowWidth, height: rowHeight } = rowSizeRef.current;\n\n\t\t// Logical boxes run from the capsule's side, so RTL is LTR mirrored.\n\t\ttype Shape = { key: string; x: number; y: number; w: number; ink: boolean };\n\t\tconst shapes: Shape[] = [];\n\t\tconst logical = (box: Box, dx: number, dy: number, width = box.width) => ({\n\t\t\tx: rtl ? rowWidth - (box.left + dx + box.width) : box.left + dx,\n\t\t\ty: box.top + dy,\n\t\t\tw: width,\n\t\t});\n\n\t\tconst pillBox = boxes.get(\"\\u0000pill\");\n\t\tif (pillBox)\n\t\t\tshapes.push({ key: \"pill\", ...logical(pillBox, 0, 0), ink: true });\n\n\t\tconst clearBox = boxes.get(\"\\u0000clear\");\n\t\tconst clearShown = clearAt(now);\n\t\tif (clearRef.current) {\n\t\t\tclearRef.current.style.opacity = String(round(clearShown));\n\t\t}\n\n\t\tconst chips: Array<{ key: string; motion: ChipMotion; shape: Shape }> = [];\n\t\tfor (const [key, motion] of motionsRef.current) {\n\t\t\tconst box = boxes.get(key);\n\t\t\tconst chip = chipRefs.current.get(key);\n\t\t\tconst ink = inkRefs.current.get(key);\n\t\t\tif (!box || !chip || !ink) continue;\n\t\t\tchip.style.transform =\n\t\t\t\tmotion.dx || motion.dy\n\t\t\t\t\t? `translate(${round(motion.dx)}px, ${round(motion.dy)}px)`\n\t\t\t\t\t: \"\";\n\t\t\tchip.style.zIndex = motion.kind ? \"2\" : \"\";\n\t\t\tconst flood = motion.flood;\n\t\t\tconst cut = round((1 - flood) * box.width);\n\t\t\tink.style.opacity = flood > 0.001 ? \"1\" : \"0\";\n\t\t\tink.style.clipPath = rtl\n\t\t\t\t? `inset(0 0 0 ${cut}px round ${RADIUS}px)`\n\t\t\t\t: `inset(0 ${cut}px 0 0 round ${RADIUS}px)`;\n\t\t\tconst shape = {\n\t\t\t\tkey,\n\t\t\t\t...logical(box, motion.dx, motion.dy),\n\t\t\t\tink: flood > 0.02,\n\t\t\t};\n\t\t\tchips.push({ key, motion, shape });\n\t\t}\n\n\t\tconst divider = dividerRef.current;\n\t\tif (divider) {\n\t\t\tdivider.style.opacity = String(\n\t\t\t\tround(tweenAt(dividerTweenRef.current, now)),\n\t\t\t);\n\t\t}\n\n\t\tconst svg = svgRef.current;\n\t\tif (!svg) return;\n\t\tconst goo = gooRef.current;\n\t\tgoo?.setAttribute(\"x\", \"-24\");\n\t\tgoo?.setAttribute(\"y\", \"-24\");\n\t\tgoo?.setAttribute(\"width\", String(rowWidth + 48));\n\t\tgoo?.setAttribute(\"height\", String(rowHeight + 48));\n\t\tflipRef.current?.setAttribute(\n\t\t\t\"transform\",\n\t\t\trtl ? `matrix(-1 0 0 1 ${rowWidth} 0)` : \"\",\n\t\t);\n\n\t\tconst setRect = (\n\t\t\tkey: string,\n\t\t\tx: number,\n\t\t\ty: number,\n\t\t\tw: number,\n\t\t\th: number,\n\t\t\tsquare = false,\n\t\t) => {\n\t\t\tconst rect = shapeRefs.current.get(key);\n\t\t\tif (!rect) return;\n\t\t\tconst visible = w > 0.5 && h > 0.5;\n\t\t\tconst r = square ? 0 : Math.min(w, h) / 2;\n\t\t\trect.setAttribute(\"x\", String(round(x)));\n\t\t\trect.setAttribute(\"y\", String(round(y)));\n\t\t\trect.setAttribute(\"width\", String(round(visible ? w : 0)));\n\t\t\trect.setAttribute(\"height\", String(round(visible ? h : 0)));\n\t\t\trect.setAttribute(\"rx\", String(round(r)));\n\t\t};\n\n\t\tif (pillBox) {\n\t\t\tconst pill = shapes[0];\n\t\t\tsetRect(\"pill\", pill.x, pill.y, pill.w, HEIGHT);\n\t\t}\n\t\tconst anchors = [...shapes];\n\t\tif (clearBox && clearShown > 0.01) {\n\t\t\tconst clear = logical(clearBox, 0, 0);\n\t\t\tconst width = clearBox.width * clearShown;\n\t\t\tsetRect(\"clear\", clear.x, clear.y, width, HEIGHT);\n\t\t\tanchors.push({ key: \"clear\", ...clear, w: width, ink: true });\n\t\t} else {\n\t\t\tsetRect(\"clear\", 0, 0, 0, 0);\n\t\t}\n\t\tfor (const { shape, motion } of chips) {\n\t\t\tsetRect(\n\t\t\t\t`ink:${shape.key}`,\n\t\t\t\tshape.x,\n\t\t\t\tshape.y,\n\t\t\t\tshape.w * motion.flood,\n\t\t\t\tHEIGHT,\n\t\t\t);\n\t\t\tif (shape.ink) anchors.push(shape);\n\t\t}\n\n\t\tfor (const { key, shape, motion } of chips) {\n\t\t\tconst neck = shapeRefs.current.get(`neck:${key}`);\n\t\t\tconst bead = shapeRefs.current.get(`bead:${key}`) as\n\t\t\t\t| SVGCircleElement\n\t\t\t\t| undefined;\n\t\t\tif (!neck || !bead) continue;\n\t\t\t// The anchor is the inked shape whose end sits nearest this chip's\n\t\t\t// near edge, on the same line.\n\t\t\tlet anchor: Shape | null = null;\n\t\t\tfor (const candidate of anchors) {\n\t\t\t\tif (candidate.key === key) continue;\n\t\t\t\tif (Math.abs(candidate.y - shape.y) > HEIGHT / 2) continue;\n\t\t\t\tconst end = candidate.x + candidate.w;\n\t\t\t\tif (end > shape.x + shape.w / 2) continue;\n\t\t\t\tif (!anchor || end > anchor.x + anchor.w) anchor = candidate;\n\t\t\t}\n\t\t\tconst hide = () => {\n\t\t\t\tsetRect(`neck:${key}`, 0, 0, 0, 0);\n\t\t\t\tbead.setAttribute(\"r\", \"0\");\n\t\t\t};\n\t\t\tif (!anchor || motion.bond <= 0.001) {\n\t\t\t\thide();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst from = anchor.x + anchor.w;\n\t\t\tconst to = shape.x;\n\t\t\tconst middle = shape.y + HEIGHT / 2;\n\t\t\tconst thickness = HEIGHT * motion.bond * motion.open;\n\t\t\tif (to - from > -RADIUS) {\n\t\t\t\t// Square ends that reach a full radius into both shapes, so a\n\t\t\t\t// docked chip fills the notches between the rounded inks. On the\n\t\t\t\t// chip's side it reaches in only as far as the ink has.\n\t\t\t\tconst start = from - RADIUS;\n\t\t\t\tconst end = to + RADIUS * Math.max(0.4, motion.flood);\n\t\t\t\tsetRect(\n\t\t\t\t\t`neck:${key}`,\n\t\t\t\t\tstart,\n\t\t\t\t\tmiddle - thickness / 2,\n\t\t\t\t\tend - start,\n\t\t\t\t\tthickness,\n\t\t\t\t\ttrue,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tsetRect(`neck:${key}`, 0, 0, 0, 0);\n\t\t\t}\n\t\t\t// The bead buds from the capsule's end and runs to the chip.\n\t\t\tconst elapsed = now - motion.start;\n\t\t\tif (motion.kind === \"merge\" && elapsed < BEAD_DURATION + 120) {\n\t\t\t\tconst travel = easeOut(clamp(elapsed / BEAD_DURATION));\n\t\t\t\tconst fade = 1 - smoothstep(clamp((elapsed - BEAD_DURATION) / 120));\n\t\t\t\tconst radius = HEIGHT * (0.14 + 0.14 * travel) * fade * motion.open;\n\t\t\t\tconst gap = Math.max(to - from, 0);\n\t\t\t\tbead.setAttribute(\n\t\t\t\t\t\"cx\",\n\t\t\t\t\tString(round(from - radius * 0.4 + gap * travel * 0.9)),\n\t\t\t\t);\n\t\t\t\tbead.setAttribute(\"cy\", String(round(middle)));\n\t\t\t\tbead.setAttribute(\"r\", String(round(radius)));\n\t\t\t} else {\n\t\t\t\tbead.setAttribute(\"r\", \"0\");\n\t\t\t}\n\t\t}\n\t};\n\n\t/** Advances springs and timelines to `now`; returns true once all is still. */\n\tconst step = (now: number) => {\n\t\tconst selectedNow = latest.current.selected;\n\t\tconst dt = Math.min(Math.max(now - lastFrameRef.current, 0), 64);\n\t\tlastFrameRef.current = now;\n\t\tlet busy = false;\n\t\tconst boxes = boxesRef.current;\n\t\tconst rtl = rtlRef.current;\n\t\tconst rowWidth = rowSizeRef.current.width;\n\n\t\tfor (const [key, motion] of motionsRef.current) {\n\t\t\t// The dock spring, stepped in small slices so it's frame-rate proof.\n\t\t\tif (now < motion.holdUntil) {\n\t\t\t\tmotion.time = now;\n\t\t\t} else {\n\t\t\t\tlet time = Math.max(motion.time, motion.holdUntil);\n\t\t\t\twhile (time < now) {\n\t\t\t\t\tconst h = Math.min(4, now - time) / 1000;\n\t\t\t\t\tconst ax =\n\t\t\t\t\t\t-dockSpring.stiffness * motion.dx - dockSpring.damping * motion.vx;\n\t\t\t\t\tconst ay =\n\t\t\t\t\t\t-dockSpring.stiffness * motion.dy - dockSpring.damping * motion.vy;\n\t\t\t\t\tmotion.vx += ax * h;\n\t\t\t\t\tmotion.vy += ay * h;\n\t\t\t\t\tmotion.dx += motion.vx * h;\n\t\t\t\t\tmotion.dy += motion.vy * h;\n\t\t\t\t\ttime += h * 1000;\n\t\t\t\t}\n\t\t\t\tmotion.time = now;\n\t\t\t\tif (\n\t\t\t\t\tMath.abs(motion.dx) < 0.25 &&\n\t\t\t\t\tMath.abs(motion.dy) < 0.25 &&\n\t\t\t\t\tMath.abs(motion.vx) < 8 &&\n\t\t\t\t\tMath.abs(motion.vy) < 8\n\t\t\t\t) {\n\t\t\t\t\tmotion.dx = 0;\n\t\t\t\t\tmotion.dy = 0;\n\t\t\t\t\tmotion.vx = 0;\n\t\t\t\t\tmotion.vy = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (motion.dx || motion.dy || now < motion.holdUntil) busy = true;\n\n\t\t\tmotion.flood = clamp(tweenAt(motion.ink, now));\n\t\t\tif (now < tweenEnd(motion.ink)) busy = true;\n\n\t\t\tconst isSelected = selectedNow.includes(key);\n\t\t\tconst elapsed = now - motion.start;\n\t\t\tif (motion.kind === \"merge\") {\n\t\t\t\tconst grow = easeOut(clamp(elapsed / NECK_DURATION));\n\t\t\t\tconst docked =\n\t\t\t\t\tmotion.distance > 0.5\n\t\t\t\t\t\t? 1 - clamp(Math.hypot(motion.dx, motion.dy) / motion.distance)\n\t\t\t\t\t\t: 1;\n\t\t\t\tmotion.bond = grow * (0.45 + 0.55 * docked);\n\t\t\t\tif (elapsed >= MERGE_DURATION) motion.kind = null;\n\t\t\t\telse busy = true;\n\t\t\t} else if (motion.kind === \"detach\") {\n\t\t\t\tmotion.bond =\n\t\t\t\t\telapsed < 0 ? 1 : 1 - smoothstep(clamp(elapsed / SNAP_DURATION));\n\t\t\t\tif (elapsed >= DETACH_DURATION) motion.kind = null;\n\t\t\t\telse busy = true;\n\t\t\t} else {\n\t\t\t\tmotion.bond = isSelected ? 1 : 0;\n\t\t\t}\n\n\t\t\t// A neck fades while an outlined chip lies across its path, so ink\n\t\t\t// never shows through another chip's label.\n\t\t\tlet blocked = false;\n\t\t\tconst box = boxes.get(key);\n\t\t\tif (box && motion.kind) {\n\t\t\t\t// A merge checks where chips are drawn now; a detach checks the\n\t\t\t\t// slots they're heading for, so its neck never forms across one.\n\t\t\t\tconst live = motion.kind === \"merge\" ? 1 : 0;\n\t\t\t\tconst x = rtl\n\t\t\t\t\t? rowWidth - (box.left + motion.dx * live + box.width)\n\t\t\t\t\t: box.left + motion.dx * live;\n\t\t\t\tconst pill = boxes.get(\"\\u0000pill\");\n\t\t\t\tconst from = pill\n\t\t\t\t\t? rtl\n\t\t\t\t\t\t? rowWidth - pill.left\n\t\t\t\t\t\t: pill.left + pill.width\n\t\t\t\t\t: 0;\n\t\t\t\tfor (const [other, otherMotion] of motionsRef.current) {\n\t\t\t\t\tif (other === key || otherMotion.flood > 0.05) continue;\n\t\t\t\t\tconst otherBox = boxes.get(other);\n\t\t\t\t\tif (\n\t\t\t\t\t\t!otherBox ||\n\t\t\t\t\t\tMath.abs(\n\t\t\t\t\t\t\totherBox.top + otherMotion.dy * live - box.top - motion.dy * live,\n\t\t\t\t\t\t) >\n\t\t\t\t\t\t\tHEIGHT / 2\n\t\t\t\t\t)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tconst ox = rtl\n\t\t\t\t\t\t? rowWidth -\n\t\t\t\t\t\t\t(otherBox.left + otherMotion.dx * live + otherBox.width)\n\t\t\t\t\t\t: otherBox.left + otherMotion.dx * live;\n\t\t\t\t\tif (ox < x && ox + otherBox.width > from) blocked = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst target = blocked ? 0 : 1;\n\t\t\tmotion.open += (target - motion.open) * (1 - Math.exp(-dt / OPEN_RATE));\n\t\t\tif (Math.abs(target - motion.open) < 0.01) motion.open = target;\n\t\t\telse busy = true;\n\t\t}\n\n\t\tif (now < tweenEnd(dividerTweenRef.current)) busy = true;\n\t\tif (now < tweenEnd(clearOutRef.current)) busy = true;\n\t\tif (clearInRef.current && now < tweenEnd(clearInRef.current)) busy = true;\n\t\treturn !busy;\n\t};\n\n\tconst finish = () => {\n\t\tcancelAnimationFrame(frameRef.current);\n\t\tframeRef.current = 0;\n\t\tfor (const [key, motion] of motionsRef.current) {\n\t\t\tmotion.kind = null;\n\t\t\tconst chip = chipRefs.current.get(key);\n\t\t\tconst ink = inkRefs.current.get(key);\n\t\t\tchip?.style.removeProperty(\"transform\");\n\t\t\tchip?.style.removeProperty(\"z-index\");\n\t\t\tink?.style.removeProperty(\"opacity\");\n\t\t\tink?.style.removeProperty(\"clip-path\");\n\t\t}\n\t\tdividerRef.current?.style.removeProperty(\"opacity\");\n\t\tclearRef.current?.style.removeProperty(\"opacity\");\n\t\t// Swap back to the plain CSS capsule before the next paint.\n\t\tflushSync(() => setAnimating(false));\n\t};\n\n\tconst tick = (now: number) => {\n\t\tconst done = step(now);\n\t\tpaint(now);\n\t\tif (done) finish();\n\t\telse frameRef.current = requestAnimationFrame(tick);\n\t};\n\n\tconst startLoop = (now: number) => {\n\t\tif (!frameRef.current) {\n\t\t\tlastFrameRef.current = now;\n\t\t\tframeRef.current = requestAnimationFrame(tick);\n\t\t}\n\t};\n\n\t// Every commit: spring any chip whose slot moved from where it's drawn, and\n\t// start a merge or detach for chips that joined or left the selection.\n\tuseLayoutEffect(() => {\n\t\tconst previousBoxes = boxesRef.current;\n\t\tmeasure();\n\t\tconst boxes = boxesRef.current;\n\t\tconst previous = previousRef.current;\n\t\tconst next = latest.current.selected;\n\t\tconst changed = !sameList(previous, next);\n\t\tpreviousRef.current = next;\n\t\tconst reduced = latest.current.reducedMotion;\n\n\t\tif (reduced) {\n\t\t\tif (changed) {\n\t\t\t\t// No goo, no neck: chips that moved fade in where they land.\n\t\t\t\tfor (const [key, element] of chipRefs.current) {\n\t\t\t\t\tconst before = previousBoxes.get(key);\n\t\t\t\t\tconst after = boxes.get(key);\n\t\t\t\t\tif (\n\t\t\t\t\t\tbefore &&\n\t\t\t\t\t\tafter &&\n\t\t\t\t\t\t(before.left !== after.left || before.top !== after.top)\n\t\t\t\t\t) {\n\t\t\t\t\t\telement.animate([{ opacity: 0 }, { opacity: 1 }], {\n\t\t\t\t\t\t\tduration: CROSS_FADE,\n\t\t\t\t\t\t\teasing: \"ease-out\",\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst now = performance.now();\n\t\tlet moving = false;\n\t\tconst added = next.filter((item) => !previous.includes(item));\n\t\tconst removed = previous.filter((item) => !next.includes(item));\n\t\tconst merging = added.length > 0;\n\t\t// Cleared chips drain back from the capsule's far end, one after another.\n\t\tconst staggered = removed.length > 1 ? [...removed].reverse() : removed;\n\n\t\tfor (const [key] of chipRefs.current) {\n\t\t\tconst motion = motionFor(key, previous.includes(key));\n\t\t\tconst before = previousBoxes.get(key);\n\t\t\tconst after = boxes.get(key);\n\t\t\tif (before && after) {\n\t\t\t\tconst dx = before.left - after.left;\n\t\t\t\tconst dy = before.top - after.top;\n\t\t\t\tif (dx || dy) {\n\t\t\t\t\tmotion.dx += dx;\n\t\t\t\t\tmotion.dy += dy;\n\t\t\t\t\tmotion.time = now;\n\t\t\t\t\tmotion.holdUntil = Math.max(\n\t\t\t\t\t\tmotion.holdUntil,\n\t\t\t\t\t\tnow + (merging ? DOCK_DELAY : 0),\n\t\t\t\t\t);\n\t\t\t\t\tmoving = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst current = clamp(tweenAt(motion.ink, now));\n\t\t\tif (added.includes(key)) {\n\t\t\t\tmotion.kind = \"merge\";\n\t\t\t\tmotion.start = now;\n\t\t\t\tmotion.distance = Math.hypot(motion.dx, motion.dy);\n\t\t\t\tmotion.open = 1;\n\t\t\t\t// A chip caught mid-drain floods back at once.\n\t\t\t\tconst delay = current > 0.05 ? 0 : FLOOD_DELAY;\n\t\t\t\tmotion.ink = {\n\t\t\t\t\tfrom: current,\n\t\t\t\t\tto: 1,\n\t\t\t\t\tstart: now + delay,\n\t\t\t\t\tduration: FLOOD_DURATION * (1 - current),\n\t\t\t\t};\n\t\t\t\tmoving = true;\n\t\t\t} else if (removed.includes(key)) {\n\t\t\t\tconst start = now + staggered.indexOf(key) * CLEAR_STAGGER;\n\t\t\t\tmotion.kind = \"detach\";\n\t\t\t\tmotion.start = start;\n\t\t\t\tmotion.holdUntil = Math.max(motion.holdUntil, start);\n\t\t\t\tmotion.ink = {\n\t\t\t\t\tfrom: current,\n\t\t\t\t\tto: 0,\n\t\t\t\t\tstart,\n\t\t\t\t\tduration: DRAIN_DURATION * current,\n\t\t\t\t};\n\t\t\t\tmoving = true;\n\t\t\t}\n\t\t}\n\n\t\tif (changed) {\n\t\t\tconst divider = clamp(tweenAt(dividerTweenRef.current, now));\n\t\t\tconst target = next.length > 0 ? 1 : 0;\n\t\t\tif (target !== dividerTweenRef.current.to) {\n\t\t\t\tdividerTweenRef.current =\n\t\t\t\t\ttarget === 1\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tfrom: divider,\n\t\t\t\t\t\t\t\tto: 1,\n\t\t\t\t\t\t\t\tstart: now + DIVIDER_IN_DELAY,\n\t\t\t\t\t\t\t\tduration: DIVIDER_IN,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: { from: divider, to: 0, start: now, duration: DIVIDER_OUT };\n\t\t\t}\n\t\t\t// The clear button sinks into the capsule while chips move and buds\n\t\t\t// back out once they've docked.\n\t\t\tconst shown = clamp(clearAt(now));\n\t\t\tclearOutRef.current = {\n\t\t\t\tfrom: shown,\n\t\t\t\tto: 0,\n\t\t\t\tstart: now,\n\t\t\t\tduration: CLEAR_OUT * shown,\n\t\t\t};\n\t\t\tclearInRef.current = latest.current.showClear\n\t\t\t\t? { from: 0, to: 1, start: now + CLEAR_IN_DELAY, duration: CLEAR_IN }\n\t\t\t\t: null;\n\t\t\tmoving = true;\n\t\t}\n\n\t\tif (!moving) return;\n\t\tif (!animating) setAnimating(true);\n\t\tpaint(now);\n\t\tstartLoop(now);\n\t});\n\n\t// Once the SVG has mounted, draw it before the browser paints.\n\tuseLayoutEffect(() => {\n\t\tif (animating) paint(performance.now());\n\t});\n\n\tuseEffect(() => () => cancelAnimationFrame(frameRef.current), []);\n\n\t// Slots move without animating when the row resizes at rest.\n\tuseEffect(() => {\n\t\tconst row = rowRef.current;\n\t\tconst scroller = scrollerRef.current;\n\t\tif (!row || !scroller) return;\n\t\tconst fades = () => {\n\t\t\tconst max = scroller.scrollWidth - scroller.clientWidth;\n\t\t\tconst at = scroller.scrollLeft;\n\t\t\tconst rtl = getComputedStyle(scroller).direction === \"rtl\";\n\t\t\tconst left = rtl ? max + at : at;\n\t\t\tconst right = rtl ? -at : max - at;\n\t\t\tscroller.style.setProperty(\"--ifb-fade-l\", left > 1 ? \"20px\" : \"0px\");\n\t\t\tscroller.style.setProperty(\"--ifb-fade-r\", right > 1 ? \"20px\" : \"0px\");\n\t\t};\n\t\tconst observer = new ResizeObserver(() => {\n\t\t\tif (!frameRef.current) measure();\n\t\t\tfades();\n\t\t});\n\t\tobserver.observe(row);\n\t\tobserver.observe(scroller);\n\t\tscroller.addEventListener(\"scroll\", fades, { passive: true });\n\t\tfades();\n\t\treturn () => {\n\t\t\tobserver.disconnect();\n\t\t\tscroller.removeEventListener(\"scroll\", fades);\n\t\t};\n\t}, [measure]);\n\n\tconst countText = formatCount(count);\n\tconst announcedRef = useRef(countText);\n\tuseEffect(() => {\n\t\tif (countText === announcedRef.current) return;\n\t\tconst timer = setTimeout(() => {\n\t\t\tannouncedRef.current = countText;\n\t\t\t// A zero-width space makes a repeated count announce again.\n\t\t\tsetAnnouncement((previous) =>\n\t\t\t\tprevious === `${countText} ${label}`\n\t\t\t\t\t? `${countText} ${label}​`\n\t\t\t\t\t: `${countText} ${label}`,\n\t\t\t);\n\t\t}, ANNOUNCE_DELAY);\n\t\treturn () => clearTimeout(timer);\n\t}, [countText, label]);\n\n\tconst silent = () =>\n\t\ttypeof document !== \"undefined\" && document.visibilityState === \"hidden\";\n\n\t// Called only for user input, so the first render and prop changes stay quiet.\n\tconst commit = (next: string[], cue: \"absorb\" | \"detach\") => {\n\t\tconst current = latest.current;\n\t\tif (sameList(next, current.selected)) return;\n\t\ttoggledAtRef.current = performance.now();\n\t\tif (!current.controlled) setInternalValue(next);\n\t\tcurrent.onValueChange?.(next);\n\t\tif (!silent()) {\n\t\t\tif (current.sound) {\n\t\t\t\tif (cue === \"absorb\") playDrop(true);\n\t\t\t\telse playUnstick(false);\n\t\t\t}\n\t\t\tif (current.haptics)\n\t\t\t\tvoid haptic(cue === \"absorb\" ? \"light\" : \"selection\");\n\t\t}\n\t\t// A chip picked while the row is scrolled lands in view at the start.\n\t\tconst scroller = scrollerRef.current;\n\t\tif (cue === \"absorb\" && scroller && scroller.scrollLeft !== 0) {\n\t\t\tscroller.scrollTo({\n\t\t\t\tleft: 0,\n\t\t\t\tbehavior: current.reducedMotion ? \"auto\" : \"smooth\",\n\t\t\t});\n\t\t}\n\t};\n\n\tconst toggle = (item: string) => {\n\t\tconst current = latest.current.selected;\n\t\tconst on = !current.includes(item);\n\t\tif (latest.current.type === \"single\") {\n\t\t\tcommit(on ? [item] : [], on ? \"absorb\" : \"detach\");\n\t\t} else {\n\t\t\tcommit(\n\t\t\t\ton ? [...current, item] : current.filter((entry) => entry !== item),\n\t\t\t\ton ? \"absorb\" : \"detach\",\n\t\t\t);\n\t\t}\n\t};\n\n\tconst clearAll = () => {\n\t\tcommit([], \"detach\");\n\t\tlatest.current.onClear?.();\n\t\t// The clear button hides, so focus moves to the first chip, which is\n\t\t// the first option once nothing is picked.\n\t\tconst first = latest.current.options[0]?.value;\n\t\tif (first) {\n\t\t\tsetFocusValue(first);\n\t\t\trequestAnimationFrame(() => chipRefs.current.get(first)?.focus());\n\t\t}\n\t};\n\n\t/** Chip values in the order they're drawn: the capsule first. */\n\tconst visualOrder = () => {\n\t\tconst chosen = latest.current.selected;\n\t\treturn [\n\t\t\t...chosen,\n\t\t\t...latest.current.options\n\t\t\t\t.map((option) => option.value)\n\t\t\t\t.filter((item) => !chosen.includes(item)),\n\t\t];\n\t};\n\tconst order = [\n\t\t...selected,\n\t\t...options\n\t\t\t.map((option) => option.value)\n\t\t\t.filter((item) => !selected.includes(item)),\n\t];\n\tconst roving =\n\t\tfocusValue && order.includes(focusValue) ? focusValue : order[0];\n\n\tconst handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n\t\tonKeyDown?.(event);\n\t\tif (event.defaultPrevented) return;\n\t\tconst target = event.target as HTMLElement;\n\t\tconst item = target.dataset.value;\n\t\tif (!item || target.dataset.slot !== \"ink-filter-bar-chip\") return;\n\t\tconst list = visualOrder();\n\t\tconst index = list.indexOf(item);\n\t\tconst rtl = rtlRef.current;\n\t\tlet nextIndex: number;\n\t\tswitch (event.key) {\n\t\t\tcase \"ArrowRight\":\n\t\t\t\tnextIndex = index + (rtl ? -1 : 1);\n\t\t\t\tbreak;\n\t\t\tcase \"ArrowLeft\":\n\t\t\t\tnextIndex = index + (rtl ? 1 : -1);\n\t\t\t\tbreak;\n\t\t\tcase \"Home\":\n\t\t\t\tnextIndex = 0;\n\t\t\t\tbreak;\n\t\t\tcase \"End\":\n\t\t\t\tnextIndex = list.length - 1;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\treturn;\n\t\t}\n\t\tevent.preventDefault();\n\t\tconst nextItem = list[clamp(nextIndex, 0, list.length - 1)];\n\t\tif (!nextItem) return;\n\t\tsetFocusValue(nextItem);\n\t\tchipRefs.current.get(nextItem)?.focus();\n\t};\n\n\tconst canHover = () =>\n\t\ttypeof window !== \"undefined\" &&\n\t\twindow.matchMedia(\"(hover: hover) and (pointer: fine)\").matches;\n\n\tconst rollDelay = Math.max(\n\t\t0,\n\t\tFLOOD_DELAY -\n\t\t\t(typeof performance === \"undefined\"\n\t\t\t\t? FLOOD_DELAY\n\t\t\t\t: performance.now() - toggledAtRef.current),\n\t);\n\tconst joined = selected.length > 0;\n\tconst lastDocked = selected[selected.length - 1];\n\n\treturn (\n\t\t<div\n\t\t\t{...props}\n\t\t\tref={rootRef}\n\t\t\trole=\"group\"\n\t\t\tdata-slot=\"ink-filter-bar\"\n\t\t\tclassName={cn(\"relative w-full min-w-0 text-foreground\", className)}\n\t\t>\n\t\t\t<div\n\t\t\t\tref={scrollerRef}\n\t\t\t\tdata-slot=\"ink-filter-bar-viewport\"\n\t\t\t\tclassName={cn(\n\t\t\t\t\t\"-m-1.5 scroll-px-1.5 p-1.5\",\n\t\t\t\t\twrap\n\t\t\t\t\t\t? null\n\t\t\t\t\t\t: \"snap-x snap-proximity overflow-x-auto overflow-y-hidden overscroll-x-contain [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\",\n\t\t\t\t)}\n\t\t\t\tstyle={\n\t\t\t\t\twrap\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tmaskImage:\n\t\t\t\t\t\t\t\t\t\"linear-gradient(to right, transparent, #000 var(--ifb-fade-l, 0px), #000 calc(100% - var(--ifb-fade-r, 0px)), transparent)\",\n\t\t\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tref={rowRef}\n\t\t\t\t\tonKeyDown={handleKeyDown}\n\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\"relative isolate flex items-center\",\n\t\t\t\t\t\twrap ? \"flex-wrap gap-y-2\" : \"w-max\",\n\t\t\t\t\t)}\n\t\t\t\t>\n\t\t\t\t\t{animating ? (\n\t\t\t\t\t\t<svg\n\t\t\t\t\t\t\tref={svgRef}\n\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t\tclassName=\"pointer-events-none absolute inset-0 z-0 size-full overflow-visible text-foreground\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<defs>\n\t\t\t\t\t\t\t\t<filter\n\t\t\t\t\t\t\t\t\tref={gooRef}\n\t\t\t\t\t\t\t\t\tid={gooId}\n\t\t\t\t\t\t\t\t\tfilterUnits=\"userSpaceOnUse\"\n\t\t\t\t\t\t\t\t\tcolorInterpolationFilters=\"sRGB\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<feGaussianBlur stdDeviation={GOO_BLUR} />\n\t\t\t\t\t\t\t\t\t{/* Thresholds alpha at 0.5, so straight edges stay put. */}\n\t\t\t\t\t\t\t\t\t<feColorMatrix values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 20 -10\" />\n\t\t\t\t\t\t\t\t</filter>\n\t\t\t\t\t\t\t</defs>\n\t\t\t\t\t\t\t<g ref={flipRef}>\n\t\t\t\t\t\t\t\t<g filter={`url(#${gooId})`} fill=\"currentColor\">\n\t\t\t\t\t\t\t\t\t{[\"pill\", \"clear\"].map((key) => (\n\t\t\t\t\t\t\t\t\t\t<rect\n\t\t\t\t\t\t\t\t\t\t\tkey={key}\n\t\t\t\t\t\t\t\t\t\t\tref={(node) => {\n\t\t\t\t\t\t\t\t\t\t\t\tif (node) shapeRefs.current.set(key, node);\n\t\t\t\t\t\t\t\t\t\t\t\telse shapeRefs.current.delete(key);\n\t\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t\t\t{options.map((option) =>\n\t\t\t\t\t\t\t\t\t\t[\"ink\", \"neck\", \"bead\"].map((part) => {\n\t\t\t\t\t\t\t\t\t\t\tconst key = `${part}:${option.value}`;\n\t\t\t\t\t\t\t\t\t\t\tconst ref = (\n\t\t\t\t\t\t\t\t\t\t\t\tnode: SVGRectElement | SVGCircleElement | null,\n\t\t\t\t\t\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\t\t\t\t\t\tif (node) shapeRefs.current.set(key, node);\n\t\t\t\t\t\t\t\t\t\t\t\telse shapeRefs.current.delete(key);\n\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\treturn part === \"bead\" ? (\n\t\t\t\t\t\t\t\t\t\t\t\t<circle key={key} ref={ref} r={0} />\n\t\t\t\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t\t\t\t<rect key={key} ref={ref} />\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t</g>\n\t\t\t\t\t\t\t</g>\n\t\t\t\t\t\t</svg>\n\t\t\t\t\t) : null}\n\n\t\t\t\t\t<div\n\t\t\t\t\t\tref={pillRef}\n\t\t\t\t\t\tdata-slot=\"ink-filter-bar-count\"\n\t\t\t\t\t\tstyle={{ order: 0 }}\n\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\"relative z-[1] inline-flex h-9 shrink-0 snap-start items-center gap-1 whitespace-nowrap rounded-full bg-foreground px-3.5 text-background text-sm leading-5\",\n\t\t\t\t\t\t\tjoined ? \"me-0\" : \"me-2\",\n\t\t\t\t\t\t\tjoined && !animating && \"rounded-e-none\",\n\t\t\t\t\t\t)}\n\t\t\t\t\t>\n\t\t\t\t\t\t<span className=\"sr-only\">\n\t\t\t\t\t\t\t{countText} {label}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<span aria-hidden=\"true\" className=\"flex items-center gap-1\">\n\t\t\t\t\t\t\t<span className=\"font-semibold\">\n\t\t\t\t\t\t\t\t<RollingNumber\n\t\t\t\t\t\t\t\t\ttext={countText}\n\t\t\t\t\t\t\t\t\tdelay={rollDelay}\n\t\t\t\t\t\t\t\t\treduced={reducedMotion}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t<span className=\"font-medium text-background/60\">{label}</span>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tref={dividerRef}\n\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t\tdata-slot=\"ink-filter-bar-divider\"\n\t\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\t\"pointer-events-none absolute inset-y-2 end-0 w-px bg-background/25\",\n\t\t\t\t\t\t\t\tjoined ? \"opacity-100\" : \"opacity-0\",\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\n\t\t\t\t\t{options.map((option, index) => {\n\t\t\t\t\t\tconst isSelected = selected.includes(option.value);\n\t\t\t\t\t\tconst position = isSelected\n\t\t\t\t\t\t\t? 1 + selected.indexOf(option.value)\n\t\t\t\t\t\t\t: selected.length + 2 + index;\n\t\t\t\t\t\tconst capsuleEnd =\n\t\t\t\t\t\t\tisSelected && option.value === lastDocked && !showClear;\n\t\t\t\t\t\t// Only an outlined chip at rest wobbles; never while ink moves.\n\t\t\t\t\t\tconst wobble =\n\t\t\t\t\t\t\thovered === option.value &&\n\t\t\t\t\t\t\t!isSelected &&\n\t\t\t\t\t\t\t!animating &&\n\t\t\t\t\t\t\t!reducedMotion;\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tkey={option.value}\n\t\t\t\t\t\t\t\tref={(node) => {\n\t\t\t\t\t\t\t\t\tif (node) chipRefs.current.set(option.value, node);\n\t\t\t\t\t\t\t\t\telse chipRefs.current.delete(option.value);\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\taria-pressed={isSelected}\n\t\t\t\t\t\t\t\ttabIndex={option.value === roving ? 0 : -1}\n\t\t\t\t\t\t\t\tdata-slot=\"ink-filter-bar-chip\"\n\t\t\t\t\t\t\t\tdata-state={isSelected ? \"on\" : \"off\"}\n\t\t\t\t\t\t\t\tdata-value={option.value}\n\t\t\t\t\t\t\t\tstyle={{ order: position }}\n\t\t\t\t\t\t\t\tonClick={() => toggle(option.value)}\n\t\t\t\t\t\t\t\tonFocus={() => setFocusValue(option.value)}\n\t\t\t\t\t\t\t\tonPointerEnter={(event) => {\n\t\t\t\t\t\t\t\t\tif (event.pointerType === \"mouse\" && canHover()) {\n\t\t\t\t\t\t\t\t\t\tsetHovered(option.value);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\tonPointerLeave={() =>\n\t\t\t\t\t\t\t\t\tsetHovered((current) =>\n\t\t\t\t\t\t\t\t\t\tcurrent === option.value ? null : current,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\t\t\"group/chip relative z-[1] inline-flex h-9 shrink-0 cursor-pointer touch-manipulation select-none snap-start items-center whitespace-nowrap rounded-full px-3.5 font-medium text-sm leading-5 outline-offset-2 transition-[scale] duration-150 ease-out focus-visible:outline-2 focus-visible:outline-foreground focus-visible:outline-solid active:scale-[0.97] motion-reduce:transition-none\",\n\t\t\t\t\t\t\t\t\t// A 44 px tall hit area around the 36 px chip.\n\t\t\t\t\t\t\t\t\t\"before:absolute before:inset-x-0 before:-inset-y-1 before:content-['']\",\n\t\t\t\t\t\t\t\t\tisSelected && !capsuleEnd ? \"me-0\" : \"me-2\",\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\t\t\t\"pointer-events-none absolute inset-0 rounded-full border-[1.5px] border-current\",\n\t\t\t\t\t\t\t\t\t\twobble && \"border-transparent\",\n\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t{wobble ? (\n\t\t\t\t\t\t\t\t\t<WobbleOutline\n\t\t\t\t\t\t\t\t\t\twidth={boxesRef.current.get(option.value)?.width}\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t\t<span className=\"relative z-[1] inline-flex items-center gap-1.5\">\n\t\t\t\t\t\t\t\t\t{option.label}\n\t\t\t\t\t\t\t\t\t{option.count !== undefined ? (\n\t\t\t\t\t\t\t\t\t\t<span className=\"tabular-nums opacity-60\">\n\t\t\t\t\t\t\t\t\t\t\t{option.count}\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t{/* The same label in the inverted color, revealed by the ink. */}\n\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\tref={(node) => {\n\t\t\t\t\t\t\t\t\t\tif (node) inkRefs.current.set(option.value, node);\n\t\t\t\t\t\t\t\t\t\telse inkRefs.current.delete(option.value);\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\t\t\t\"pointer-events-none absolute inset-0 z-[2] flex items-center rounded-full bg-foreground px-3.5 text-background\",\n\t\t\t\t\t\t\t\t\t\tisSelected ? \"opacity-100\" : \"opacity-0\",\n\t\t\t\t\t\t\t\t\t\tisSelected && !animating && \"rounded-s-none\",\n\t\t\t\t\t\t\t\t\t\tisSelected && !animating && !capsuleEnd && \"rounded-e-none\",\n\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<span className=\"inline-flex items-center gap-1.5\">\n\t\t\t\t\t\t\t\t\t\t{option.label}\n\t\t\t\t\t\t\t\t\t\t{option.count !== undefined ? (\n\t\t\t\t\t\t\t\t\t\t\t<span className=\"tabular-nums opacity-60\">\n\t\t\t\t\t\t\t\t\t\t\t\t{option.count}\n\t\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t);\n\t\t\t\t\t})}\n\n\t\t\t\t\t{clearable ? (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tref={clearRef}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\thidden={!showClear}\n\t\t\t\t\t\t\taria-label=\"Clear filters\"\n\t\t\t\t\t\t\tdata-slot=\"ink-filter-bar-clear\"\n\t\t\t\t\t\t\tstyle={{ order: selected.length + 1 }}\n\t\t\t\t\t\t\tonClick={clearAll}\n\t\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\t\"relative z-[1] me-2 inline-flex h-9 w-9 shrink-0 cursor-pointer touch-manipulation items-center justify-center rounded-full bg-foreground text-background/70 outline-offset-2 transition-colors hover:text-background focus-visible:outline-2 focus-visible:outline-foreground focus-visible:outline-solid\",\n\t\t\t\t\t\t\t\t\"before:absolute before:inset-x-0 before:-inset-y-1 before:content-['']\",\n\t\t\t\t\t\t\t\t!animating && \"rounded-s-none\",\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<svg\n\t\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t\t\tviewBox=\"0 0 16 16\"\n\t\t\t\t\t\t\t\tclassName=\"size-3.5 -translate-x-0.5 rtl:translate-x-0.5\"\n\t\t\t\t\t\t\t\tfill=\"none\"\n\t\t\t\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\t\t\t\tstrokeWidth=\"1.75\"\n\t\t\t\t\t\t\t\tstrokeLinecap=\"round\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<path d=\"M4 4l8 8M12 4l-8 8\" />\n\t\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t) : null}\n\t\t\t\t</div>\n\t\t\t</div>\n\n\t\t\t<span role=\"status\" aria-live=\"polite\" className=\"sr-only\">\n\t\t\t\t{announcement}\n\t\t\t</span>\n\t\t</div>\n\t);\n}\n\nexport default InkFilterBar;\n",
      "type": "registry:component",
      "target": "@components/ink-filter-bar.tsx"
    }
  ],
  "meta": {
    "createdAt": "2026-11-12",
    "image": "https://cdn.tentui.com/images/components/ink-filter-bar?v=1",
    "video": "https://cdn.tentui.com/videos/components/ink-filter-bar?v=1"
  },
  "docs": "https://tentui.com/components/ink-filter-bar",
  "categories": [
    "inputs"
  ],
  "type": "registry:component"
}