{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"liquid-tabs","type":"registry:component","title":"Liquid tabs","description":"Tabs whose highlight has a little surface tension: it draws out and pinches for a moment, then it is a pill again.","author":"Hairline UI","dependencies":[],"files":[{"path":"registry/liquid-tabs.tsx","type":"registry:component","content":"// Hairline UI · liquid-tabs · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n\"use client\";\n\nimport * as React from \"react\";\nimport { INTERACTION_FOCUS, MATERIAL_RECESS, createSpring, rubberBand, useInteractionReducedMotion, type Spring } from \"./ui-interaction-motion\";\n\n/* ─────────────────────────────────────────────────────────\n * LIQUID TABS: a selection with a little surface tension\n *\n *   pick     the edge in front leads and the edge behind follows a\n *            moment later, so the highlight draws out slightly and\n *            its middle pinches, then it's a pill again. About 0.3s,\n *            with no overshoot: you can notice\n *            it, and you can use it all day without noticing it\n *   far      the same on a long jump: how far it can draw out has a\n *            limit, so the distance never makes it louder\n *   labels   each label turns exactly where the highlight touches\n *            it, because the same outline clips the light copy\n *   colour   with a colour per tab, the new one comes in from the\n *            front and the old one leaves with the tail\n *\n * The outline is one pure function of three springs, written to one\n * path per frame. No filter, no layout, no render while it moves.\n * ───────────────────────────────────────────────────────── */\n\nexport interface LiquidTab {\n  value: string;\n  label: React.ReactNode;\n  icon?: React.ReactNode;\n  /** Required when `label` isn't text. */\n  ariaLabel?: string;\n  /** Renders a link and reports aria-current instead of a tab. */\n  href?: string;\n  disabled?: boolean;\n  /** The drop's colour on this tab, any CSS colour. Defaults to var(--primary). */\n  color?: string;\n  /** The label's colour on the drop. Defaults to var(--primary-foreground). */\n  foreground?: string;\n  /** The id of the panel this tab shows. */\n  panelId?: string;\n}\n\nexport interface LiquidTabsProps {\n  tabs: LiquidTab[];\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  /** Accessible name of the row. */\n  label: string;\n  /** 32px, 40px or 48px tall. */\n  size?: \"sm\" | \"md\" | \"lg\";\n  /** Fill the parent with equal tabs. */\n  block?: boolean;\n  className?: string;\n}\n\nconst SIZES = {\n  sm: { row: \"h-8 p-[3px]\", tab: \"px-3 text-[12.5px] gap-1.5 [&_svg]:size-3.5\" },\n  md: { row: \"h-10 p-1\", tab: \"px-4 text-[13.5px] gap-2 [&_svg]:size-4\" },\n  lg: { row: \"h-12 p-[5px]\", tab: \"px-5 text-[15px] gap-2 [&_svg]:size-[18px]\" },\n} as const;\n\n// Both critically damped, so nothing overshoots. The front is a touch quicker, and the difference is the whole effect.\nconst FRONT = { stiffness: 620, damping: 49.8 };\nconst BEHIND = { stiffness: 380, damping: 39 };\nconst WIDTH = { stiffness: 450, damping: 42.4 };\n\n/** How far the highlight can draw out past its width, in heights, however far it's going. */\nconst REACH = 0.45;\n/** The most the waist pinches, as a share of the height. */\nconst PINCH = 0.2;\n\nconst clamp = (n: number, low: number, high: number) => Math.min(high, Math.max(low, n));\nconst n1 = (n: number) => Math.round(n * 100) / 100;\n\n/** One half's outline, end cap to waist: `tip` is the middle of the waist. */\nfunction half(capX: number, tipX: number, top: number, bottom: number, thin: number, side: 1 | -1) {\n  const cy = (top + bottom) / 2;\n  const r = Math.min((bottom - top) / 2, Math.abs(tipX - capX));\n  const start = capX + side * r;\n  const pull = (tipX - start) * 0.56;\n  const edge = (y: number, tipY: number) => `${n1(start + pull)} ${n1(y)} ${n1(tipX - pull)} ${n1(tipY)} ${n1(tipX)} ${n1(tipY)}`;\n  const sweep = side === 1 ? 1 : 0;\n  return {\n    start: { x: n1(start), top: n1(cy - r), bottom: n1(cy + r) },\n    r: n1(r),\n    sweep,\n    toTip: { top: edge(cy - r, cy - thin), bottom: edge(cy + r, cy + thin) },\n    tipTop: n1(cy - thin),\n    tipBottom: n1(cy + thin),\n    backTop: `${n1(tipX - pull)} ${n1(cy - thin)} ${n1(start + pull)} ${n1(cy - r)} ${n1(start)} ${n1(cy - r)}`,\n    backBottom: `${n1(tipX - pull)} ${n1(cy + thin)} ${n1(start + pull)} ${n1(cy + r)} ${n1(start)} ${n1(cy + r)}`,\n  };\n}\n\n/**\n * The outline from its left and right edges, its resting width, and its top and bottom. A pure function: any interruption\n * is just another pair of edges, so it never has to restart anything.\n */\nexport function liquidPath(left: number, right: number, rest: number, top: number, bottom: number) {\n  const height = bottom - top;\n  const width = right - left;\n  const mid = (left + right) / 2;\n  const drawn = clamp((width - rest) / (height * REACH), 0, 1);\n  const thin = (height / 2) * (1 - PINCH * drawn * (2 - drawn));\n  const a = half(left, mid, top, bottom, thin, 1);\n  const c = half(right, mid, top, bottom, thin, -1);\n  return (\n    `M${a.start.x} ${a.start.top}C${a.toTip.top}C${c.backTop}` +\n    `A${c.r} ${c.r} 0 0 1 ${c.start.x} ${c.start.bottom}` +\n    `C${c.toTip.bottom}C${a.backBottom}` +\n    `A${a.r} ${a.r} 0 0 1 ${a.start.x} ${a.start.top}Z`\n  );\n}\n\nconst colorOf = (tab?: LiquidTab) => tab?.color ?? \"var(--primary)\";\n\ntype Mark = { x: number; w: number };\n\nexport function LiquidTabs({ tabs, value, defaultValue, onValueChange, label, size = \"md\", block, className = \"\" }: LiquidTabsProps) {\n  const reduced = useInteractionReducedMotion();\n  const [own, setOwn] = React.useState(defaultValue ?? tabs[0]?.value);\n  const current = value !== undefined ? value : own;\n  const [measured, setMeasured] = React.useState(false);\n  const [hovered, setHovered] = React.useState<string | null>(null);\n\n  const rowRef = React.useRef<HTMLDivElement>(null);\n  const pathRef = React.useRef<SVGPathElement>(null);\n  const sheenRef = React.useRef<SVGPathElement>(null);\n  const lightRef = React.useRef<HTMLDivElement>(null);\n  const flowRef = React.useRef<SVGLinearGradientElement>(null);\n  const fromStopRef = React.useRef<SVGStopElement>(null);\n  const toStopRef = React.useRef<SVGStopElement>(null);\n  const flowId = React.useId();\n  const sheenId = React.useId();\n  const springs = React.useRef<{ left: Spring; right: Spring; rest: Spring } | null>(null);\n  const motion = React.useRef({ top: 0, bottom: 0, heading: 1, target: 0, flowing: false, frontFrom: 0, tailFrom: 0, tailTo: 0 });\n  const marks = React.useRef(new Map<string, Mark>());\n\n  const paint = React.useCallback(() => {\n    const s = springs.current;\n    if (!s) return;\n    const m = motion.current;\n    const rest = s.rest.get();\n    const height = m.bottom - m.top;\n    const most = rest + height * REACH;\n    let left = s.left.get();\n    let right = s.right.get();\n    // On a long jump the tail is carried along behind the front, so the distance never makes the shape any bigger.\n    const over = right - left - most;\n    if (over > 0) {\n      const kept = rubberBand(over, height * 0.3);\n      if (m.heading > 0) left = right - most - kept;\n      else right = left + most + kept;\n    }\n    const d = liquidPath(left, right, rest, m.top, m.bottom);\n    pathRef.current?.setAttribute(\"d\", d);\n    sheenRef.current?.setAttribute(\"d\", d);\n    if (lightRef.current) lightRef.current.style.clipPath = `path(\"${d}\")`;\n\n    // The new colour starts at the front of the drop and the old one leaves with its tail: where the two meet follows how\n    // far both edges have got. Before the first frame of a flight the drop is all old colour, and after the last all new.\n    const flow = flowRef.current;\n    if (m.flowing && flow) {\n      const front = m.heading > 0 ? right : left;\n      const tail = m.heading > 0 ? left : right;\n      const done = (now: number, from: number, to: number) => clamp((now - from) / (Math.abs(to - from) < 1 ? 1 : to - from), 0, 1);\n      const through = (done(front, m.frontFrom, m.target) + done(tail, m.tailFrom, m.tailTo)) / 2;\n      const soft = Math.min(20, Math.abs(front - tail) * 0.25);\n      const a = front + m.heading * soft;\n      const seam = a + (tail - m.heading * soft - a) * through;\n      flow.setAttribute(\"x1\", `${n1(seam - m.heading * soft)}`);\n      flow.setAttribute(\"x2\", `${n1(seam + m.heading * soft)}`);\n      if (through > 0.995) m.flowing = false;\n    } else if (flow) {\n      flow.setAttribute(\"x1\", \"0\");\n      flow.setAttribute(\"x2\", \"0\");\n    }\n  }, []);\n\n  const measure = React.useCallback(() => {\n    const row = rowRef.current;\n    if (!row) return false;\n    marks.current.clear();\n    row.querySelectorAll<HTMLElement>(\"[data-liquid-tab]\").forEach((el) => {\n      // Offsets count from the controls' own layer, which sits inside the row's padding.\n      const layer = el.offsetParent as HTMLElement;\n      marks.current.set(el.dataset.liquidTab!, { x: layer.offsetLeft + el.offsetLeft, w: el.offsetWidth });\n      motion.current.top = layer.offsetTop + el.offsetTop;\n      motion.current.bottom = motion.current.top + el.offsetHeight;\n    });\n    return true;\n  }, []);\n\n  const aim = React.useCallback(\n    (next: string | undefined, instant: boolean) => {\n      const s = springs.current;\n      const mark = next ? marks.current.get(next) : undefined;\n      if (!s || !mark) return;\n      const m = motion.current;\n      const end = mark.x + mark.w;\n      if (instant) {\n        m.flowing = false;\n        s.left.jump(mark.x);\n        s.right.jump(end);\n        s.rest.jump(mark.w);\n        return;\n      }\n      const heading = mark.x + mark.w / 2 >= (s.left.get() + s.right.get()) / 2 ? 1 : -1;\n      m.heading = heading;\n      m.target = heading > 0 ? end : mark.x;\n      m.frontFrom = heading > 0 ? s.right.get() : s.left.get();\n      m.tailFrom = heading > 0 ? s.left.get() : s.right.get();\n      m.tailTo = heading > 0 ? mark.x : end;\n      m.flowing = true;\n      (heading > 0 ? s.right : s.left).configure(FRONT);\n      (heading > 0 ? s.left : s.right).configure(BEHIND);\n      s.left.set(mark.x);\n      s.right.set(end);\n      s.rest.set(mark.w);\n      // Now, not next frame: the stops have already changed, and the drop must still be all old colour when it next paints.\n      paint();\n    },\n    [paint],\n  );\n\n  // The first placement, and again whenever the row changes size: fonts arriving, a label changing, a narrower parent.\n  React.useLayoutEffect(() => {\n    const row = rowRef.current;\n    if (!row || !measure()) return;\n    const start = current ? marks.current.get(current) : undefined;\n    const s = {\n      left: createSpring(start?.x ?? 0, FRONT, paint),\n      right: createSpring(start ? start.x + start.w : 0, BEHIND, paint),\n      rest: createSpring(start?.w ?? 0, WIDTH, paint),\n    };\n    springs.current = s;\n    paint();\n    setMeasured(true);\n    let first = true;\n    const observer = new ResizeObserver(() => {\n      if (first) return void (first = false);\n      measure();\n      aim(row.dataset.current, true);\n    });\n    observer.observe(row);\n    document.fonts?.ready.then(() => {\n      if (springs.current !== s) return;\n      measure();\n      aim(row.dataset.current, true);\n    });\n    return () => {\n      observer.disconnect();\n      s.left.stop();\n      s.right.stop();\n      s.rest.stop();\n      springs.current = null;\n    };\n    // Mount only: `current` is read from the row's data attribute from then on, and changes go through the effect below.\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [measure, aim, paint, tabs.length]);\n\n  // A new choice: the colour first, so its stops are right from the first frame of the flight.\n  const shownRef = React.useRef(current);\n  React.useLayoutEffect(() => {\n    if (shownRef.current === current) return;\n    const before = tabs.find((t) => t.value === shownRef.current);\n    const after = tabs.find((t) => t.value === current);\n    shownRef.current = current;\n    fromStopRef.current?.setAttribute(\"stop-color\", colorOf(before));\n    toStopRef.current?.setAttribute(\"stop-color\", colorOf(after));\n    aim(current, reduced);\n    const row = rowRef.current;\n    const el = row?.querySelector<HTMLElement>(`[data-liquid-tab=\"${CSS.escape(current ?? \"\")}\"]`);\n    const scroller = row?.parentElement;\n    if (el && scroller && scroller.scrollWidth > scroller.clientWidth) {\n      scroller.scrollTo({ left: el.offsetLeft - (scroller.clientWidth - el.offsetWidth) / 2, behavior: reduced ? \"auto\" : \"smooth\" });\n    }\n  }, [current, tabs, aim, reduced]);\n\n  const pick = (next: string) => {\n    if (value === undefined) setOwn(next);\n    onValueChange?.(next);\n  };\n\n  const onKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n    const enabled = tabs.filter((t) => !t.disabled);\n    const index = enabled.findIndex((t) => t.value === current);\n    let next = -1;\n    if (event.key === \"ArrowRight\" || event.key === \"ArrowDown\") next = (index + 1) % enabled.length;\n    else if (event.key === \"ArrowLeft\" || event.key === \"ArrowUp\") next = (index - 1 + enabled.length) % enabled.length;\n    else if (event.key === \"Home\") next = 0;\n    else if (event.key === \"End\") next = enabled.length - 1;\n    if (next < 0) return;\n    event.preventDefault();\n    const tab = enabled[next];\n    pick(tab.value);\n    rowRef.current?.querySelector<HTMLElement>(`[data-liquid-tab=\"${CSS.escape(tab.value)}\"]`)?.focus();\n  };\n\n  const sizes = SIZES[size];\n  const isNav = tabs.some((t) => t.href);\n  const row = `flex items-stretch ${block ? \"w-full\" : \"w-max\"}`;\n  const cell = `flex min-w-0 items-center justify-center whitespace-nowrap rounded-full font-medium ${sizes.tab} ${block ? \"flex-1 basis-0\" : \"\"}`;\n  const activeTab = tabs.find((t) => t.value === current);\n\n  return (\n    <div className={`relative isolate rounded-full bg-background outline outline-1 -outline-offset-1 outline-border ${MATERIAL_RECESS} ${block ? \"w-full\" : \"w-fit max-w-full\"} ${className}`}>\n      <div className=\"overflow-x-auto overflow-y-clip rounded-full [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\">\n        <div\n          ref={rowRef}\n          data-current={current}\n          role={isNav ? undefined : \"tablist\"}\n          aria-label={isNav ? undefined : label}\n          onKeyDown={isNav ? undefined : onKeyDown}\n          className={`relative grid select-none ${sizes.row} ${block ? \"w-full grid-cols-[minmax(0,1fr)]\" : \"w-max\"}`}\n        >\n          {/* What's under the highlight: the dark copy of the labels. Before the first measure the chosen tab paints its own drop. */}\n          <div aria-hidden=\"true\" className={`${row} [grid-area:1/1]`}>\n            {tabs.map((tab) => {\n              const on = tab.value === current;\n              const lit = on && !measured;\n              return (\n                <span\n                  key={tab.value}\n                  className={`${cell} transition-colors duration-200 motion-reduce:transition-none ${tab.disabled ? \"opacity-40\" : \"\"} ${hovered === tab.value && !on ? \"text-foreground\" : \"text-muted-foreground\"}`}\n                  style={lit ? { background: colorOf(tab), color: tab.foreground ?? \"var(--primary-foreground)\" } : undefined}\n                >\n                  {tab.icon}\n                  {tab.label}\n                </span>\n              );\n            })}\n          </div>\n\n          <svg aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 size-full overflow-visible [contain:layout]\" style={{ opacity: measured ? 1 : 0 }}>\n            <defs>\n              <linearGradient ref={flowRef} id={flowId} gradientUnits=\"userSpaceOnUse\" x1=\"0\" x2=\"0\" y1=\"0\" y2=\"0\">\n                <stop ref={fromStopRef} offset=\"0\" stopColor={colorOf(activeTab)} />\n                <stop ref={toStopRef} offset=\"1\" stopColor={colorOf(activeTab)} />\n              </linearGradient>\n              <linearGradient id={sheenId} x1=\"0\" x2=\"0\" y1=\"0\" y2=\"1\">\n                <stop offset=\"0\" stopColor=\"white\" stopOpacity=\"0.12\" />\n                <stop offset=\"0.5\" stopColor=\"white\" stopOpacity=\"0\" />\n              </linearGradient>\n            </defs>\n            <path ref={pathRef} fill={`url(#${flowId})`} />\n            <path ref={sheenRef} fill={`url(#${sheenId})`} />\n          </svg>\n\n          {/* The same labels in the drop's text colour, cut to the drop's outline, so a letter turns exactly where the highlight reaches it. */}\n          <div ref={lightRef} aria-hidden=\"true\" className={`${row} pointer-events-none absolute inset-0 ${sizes.row}`} style={{ visibility: measured ? \"visible\" : \"hidden\" }}>\n            {tabs.map((tab) => (\n              <span key={tab.value} className={cell} style={{ color: tab.foreground ?? \"var(--primary-foreground)\" }}>\n                {tab.icon}\n                {tab.label}\n              </span>\n            ))}\n          </div>\n\n          {/* The real controls, on top, invisible: their own text keeps the sizes and the names, and their focus ring shows over the highlight. */}\n          <div className={`${row} relative [grid-area:1/1]`}>\n            {tabs.map((tab) => {\n              const on = tab.value === current;\n              const shared = {\n                \"data-liquid-tab\": tab.value,\n                onPointerMove: (event: React.PointerEvent) => {\n                  if (event.pointerType === \"mouse\" && !tab.disabled && hovered !== tab.value) setHovered(tab.value);\n                },\n                onPointerLeave: () => setHovered(null),\n                className: `${cell} cursor-pointer text-transparent aria-disabled:cursor-default ${INTERACTION_FOCUS} [&_svg]:opacity-0`,\n              };\n              return tab.href ? (\n                <a key={tab.value} {...shared} href={tab.disabled ? undefined : tab.href} aria-current={on ? \"page\" : undefined} aria-label={tab.ariaLabel} aria-disabled={tab.disabled || undefined} onClick={() => !tab.disabled && pick(tab.value)}>\n                  {tab.icon}\n                  {tab.label}\n                </a>\n              ) : (\n                <button\n                  key={tab.value}\n                  {...shared}\n                  type=\"button\"\n                  role=\"tab\"\n                  aria-selected={on}\n                  aria-label={tab.ariaLabel}\n                  aria-controls={tab.panelId}\n                  aria-disabled={tab.disabled || undefined}\n                  tabIndex={on ? 0 : -1}\n                  onClick={() => !tab.disabled && pick(tab.value)}\n                >\n                  {tab.icon}\n                  {tab.label}\n                </button>\n              );\n            })}\n          </div>\n        </div>\n      </div>\n    </div>\n  );\n}\n\nexport default LiquidTabs;\n"},{"path":"registry/ui-interaction-motion.ts","type":"registry:component","content":"// Hairline UI · liquid-tabs · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n'use client';\n\nimport * as React from 'react';\n\nexport const EASE_OUT = 'cubic-bezier(0.16, 1, 0.3, 1)';\nexport const EASE_SETTLE = 'cubic-bezier(0.22, 1.18, 0.36, 1)';\n/** Thrown things (indicators, thumbs): a slight overshoot on transform only. */\nexport const EASE_THROW = 'cubic-bezier(0.34, 1.36, 0.64, 1)';\n/**\n * The press every button primitive shares: a 3% give that eases in and settles back.\n * Tailwind v4's scale-* writes the `scale` property, so `scale` has to be in the list\n * or the press snaps.\n */\nexport const INTERACTION_PRESS =\n  'transition-[background-color,color,box-shadow,opacity,scale] duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] active:scale-[0.97] motion-reduce:transition-none motion-reduce:active:scale-100';\nexport const INTERACTION_FOCUS ='focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:ring-offset-2 focus-visible:ring-offset-background';\n\nconst query = '(prefers-reduced-motion: reduce)';\nconst subscribe = (notify: () => void) => {\n  const media = window.matchMedia(query);\n  media.addEventListener('change', notify);\n  return () => media.removeEventListener('change', notify);\n};\nexport const useInteractionReducedMotion = () => React.useSyncExternalStore(subscribe, () => window.matchMedia(query).matches, () => false);\n\nexport function useInteractionActivity<T extends Element>() {\n  const ref = React.useRef<T>(null);\n  const [visible, setVisible] = React.useState(false);\n  const [hidden, setHidden] = React.useState(false);\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const observer = new IntersectionObserver(([entry]) => setVisible(entry.isIntersecting));\n    observer.observe(el);\n    const visibility = () => setHidden(document.hidden);\n    visibility(); document.addEventListener('visibilitychange', visibility);\n    return () => { observer.disconnect(); document.removeEventListener('visibilitychange', visibility); };\n  }, []);\n  return { ref, active: visible && !hidden };\n}\n\nexport function interactionIcon(on: boolean, reduced: boolean): React.CSSProperties {\n  return { opacity: on ? 1 : 0, transform: on ? 'none' : 'scale(0.6)', filter: on ? 'blur(0px)' : 'blur(3px)', transition: reduced ? 'none' : `opacity 220ms ${EASE_OUT}, transform 380ms ${EASE_OUT}, filter 220ms ${EASE_OUT}` };\n}\n\n/** A raised object: one tight contact shadow, one short ambient, a hairline of light on its top edge. */\nexport const MATERIAL_LIFT =\n  'shadow-[0_1px_1.5px_rgb(0_0_0/0.07),0_3px_8px_-2px_rgb(0_0_0/0.1),inset_0_0.5px_0_rgb(255_255_255/0.8)] dark:shadow-[0_1px_2px_rgb(0_0_0/0.5),0_4px_10px_-2px_rgb(0_0_0/0.35),inset_0_0.5px_0_rgb(255_255_255/0.1)]';\n/** A trough something sits in, shaded from above, lit along its bottom edge. */\nexport const MATERIAL_RECESS =\n  'shadow-[inset_0_1px_2.5px_rgb(0_0_0/0.09),inset_0_-0.5px_0_rgb(255_255_255/0.7)] dark:shadow-[inset_0_1px_3px_rgb(0_0_0/0.45),inset_0_-0.5px_0_rgb(255_255_255/0.07)]';\n\nexport type SpringConfig = { stiffness: number; damping: number; mass?: number };\nexport interface Spring {\n  get(): number;\n  getVelocity(): number;\n  getTarget(): number;\n  /** Aim somewhere new from wherever it is now, keeping its speed. */\n  set(target: number): void;\n  /** Add speed (units per second), on top of what it already has. */\n  push(velocity: number): void;\n  /** Be there now, at rest. */\n  jump(value: number): void;\n  configure(config: SpringConfig): void;\n  stop(): void;\n}\n\n// Every moving spring on the page shares one frame loop, which sleeps when the last one rests. Each spring's onFrame runs\n// once per frame after all of them have stepped, so several springs that draw one shape paint it once.\nconst SPRING_STEP = 1 / 240;\ntype Running = { step: () => void };\nconst runningSprings = new Set<Running>();\nconst springPainters = new Set<() => void>();\nlet springFrame = 0;\nlet springLast = 0;\nlet springSpare = 0;\n\nfunction springTick(now: number) {\n  // A hidden tab stops the frames, so the first one back must not count the whole gap as time passed.\n  springSpare += Math.min((now - springLast) / 1000, 0.05);\n  springLast = now;\n  while (springSpare >= SPRING_STEP) {\n    runningSprings.forEach((spring) => spring.step());\n    springSpare -= SPRING_STEP;\n  }\n  const painters = [...springPainters];\n  springPainters.clear();\n  painters.forEach((paint) => paint());\n  springFrame = runningSprings.size ? requestAnimationFrame(springTick) : 0;\n}\n\nfunction wakeSprings(spring: Running) {\n  runningSprings.add(spring);\n  if (springFrame) return;\n  springSpare = 0;\n  springFrame = requestAnimationFrame((now) => {\n    springLast = now - 1000 / 60;\n    springTick(now);\n  });\n}\n\n/**\n * A spring that carries its speed: re-aim it mid-flight and it curves on from where it is, push it while it swings and the\n * push adds to the swing. Use it for anything that can be interrupted; a curve restarts from a standstill every time.\n * `onFrame` should write straight to the DOM. `precision` is how close counts as there, in the value's own units.\n */\nexport function createSpring(initial: number, config: SpringConfig, onFrame: () => void, precision = 0.01): Spring {\n  let value = initial;\n  let velocity = 0;\n  let target = initial;\n  let { stiffness, damping, mass = 1 } = config;\n  const running: Running = {\n    step() {\n      velocity += ((-stiffness * (value - target) - damping * velocity) / mass) * SPRING_STEP;\n      value += velocity * SPRING_STEP;\n      if (Math.abs(value - target) < precision && Math.abs(velocity) < precision * 10) {\n        value = target;\n        velocity = 0;\n        runningSprings.delete(running);\n      }\n      springPainters.add(onFrame);\n    },\n  };\n  return {\n    get: () => value,\n    getVelocity: () => velocity,\n    getTarget: () => target,\n    set(next) {\n      if (next === target && !runningSprings.has(running)) return;\n      target = next;\n      wakeSprings(running);\n    },\n    push(speed) {\n      velocity += speed;\n      wakeSprings(running);\n    },\n    jump(next) {\n      value = next;\n      target = next;\n      velocity = 0;\n      runningSprings.delete(running);\n      onFrame();\n    },\n    configure(next) {\n      ({ stiffness, damping, mass = 1 } = next);\n    },\n    stop() {\n      runningSprings.delete(running);\n    },\n  };\n}\n\n/** Sample recent movement rather than averaging a long drag and losing its release velocity. */\nexport type PointerSample = { x: number; time: number };\nexport function samplePointer(samples: PointerSample[], x: number, time: number) {\n  samples.push({ x, time });\n  while (samples.length > 2 && time - samples[0].time > 100) samples.shift();\n}\nexport function releaseVelocity(samples: PointerSample[], now: number) {\n  if (samples.length < 2 || now - samples[samples.length - 1].time > 100) return 0;\n  const first = samples[0], last = samples[samples.length - 1];\n  return (last.x - first.x) / Math.max(1, last.time - first.time);\n}\n\n/** Smooth Apple/rational rubber-band curve: continuous exponential-like resistance without linear kinks. */\nexport function rubberBand(overshoot: number, dimension = 320, constant = 0.55): number {\n  const d = dimension || 320;\n  const abs = Math.abs(overshoot);\n  return Math.sign(overshoot) * (1 - 1 / ((abs * constant) / d + 1)) * d;\n}\n\n/** Projects resting travel from release velocity (velocity in px/ms; time in seconds). */\nexport function projectInertia(distance: number, velocity: number, time = 0.12): number {\n  return distance + velocity * 1000 * time;\n}\n\n/** Smooths incoming release velocity toward a boundary so springs don't slam or clip into walls. */\nexport function softenVelocity(velocity: number, distanceToTarget: number, factor = 10): number {\n  const maxAllowed = Math.abs(distanceToTarget) * factor;\n  return Math.sign(velocity) * Math.min(Math.abs(velocity), maxAllowed);\n}\n\n/** A damped spring sampled by WAAPI: tuned for organic lightness with a hint of life (3% breath). */\nexport function springFrames(\n  from: number,\n  to: number,\n  velocity = 0,\n  duration = 480,\n  config: { omega?: number; damping?: number; steps?: number } = {},\n) {\n  const { omega = 16, damping = 0.74, steps = 36 } = config;\n  const damped = omega * Math.sqrt(Math.max(0.001, 1 - damping * damping));\n  const displacement = from - to;\n  const coefficient = (velocity * 1000 + damping * omega * displacement) / damped;\n  return Array.from({ length: steps + 1 }, (_, i) => {\n    const t = (i / steps) * (duration / 1000);\n    const value = to + Math.exp(-damping * omega * t) * (displacement * Math.cos(damped * t) + coefficient * Math.sin(damped * t));\n    return { value: i === steps ? to : value, offset: i / steps };\n  });\n}\n\n"}],"css":{},"docs":"Docs and live preview: https://hairlineui.com/ui/liquid-tabs. MIT licensed: https://hairlineui.com/license#components","meta":{"license":"MIT"}}