{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"balance-meter","type":"registry:component","title":"Balance meter","description":"What came in against what went out, and the net on a scale of hairline ticks whose needle swings and settles like a scale’s pointer.","author":"Hairline UI","dependencies":[],"registryDependencies":["https://hairlineui.com/r/number-roll.json?as=dependency"],"files":[{"path":"registry/balance-meter.tsx","type":"registry:component","content":"// Hairline UI · balance-meter · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n\"use client\";\n\nimport * as React from \"react\";\nimport { NumberRoll } from \"./number-roll\";\nimport { createSpring, type Spring } from \"./ui-interaction-motion\";\n\n/* ─────────────────────────────────────────────────────────\n * BALANCE METER: what came in against what went out, and the net\n *\n *   scale     a row of upright hairline ticks centred on zero; the\n *             ticks from zero to the net light in the colour of the\n *             side that's ahead, brighter toward the needle\n *   settle    when the numbers change the needle swings to the new\n *             net on a spring and settles like a scale's pointer;\n *             the ticks it sweeps over keep a little light and let\n *             it go slowly behind it\n *   range     the scale picks round limits for you; when they\n *             change, the labels roll to the new ones\n *\n * One canvas draws the ticks and the needle; it redraws only while\n * the needle moves or the light fades, and takes the theme's colours.\n * ───────────────────────────────────────────────────────── */\n\nexport interface BalanceFlow {\n  label: string;\n  value: number;\n  /** Any CSS colour. Inflow defaults to --chart-1, outflow to --chart-2. */\n  color?: string;\n  icon?: React.ReactNode;\n}\n\nexport interface BalanceMeterProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\"> {\n  /** What came in: money in, calories eaten, capacity added. The net is inflow minus outflow. */\n  inflow: BalanceFlow;\n  /** What went out: money out, calories burned, capacity used. */\n  outflow: BalanceFlow;\n  /** The scale's limit either side of zero. Picked from the numbers when left out. */\n  range?: number;\n  title?: string;\n  unit?: string;\n  format?: Intl.NumberFormatOptions;\n  locales?: string | string[];\n}\n\nconst EASE = \"cubic-bezier(0.16,1,0.3,1)\";\nconst PITCH = 5; // one tick every 5px\nconst TICK = 2;\nconst H = 40; // the canvas\nconst PAD = 16; // room for the end labels to sit centred under their ticks\nconst AFTERGLOW = 900; // ms for the light a passing needle leaves to fade to a third\n\nconst reducedQuery = \"(prefers-reduced-motion: reduce)\";\nconst subscribeReduced = (onChange: () => void) => {\n  const query = window.matchMedia(reducedQuery);\n  query.addEventListener(\"change\", onChange);\n  return () => query.removeEventListener(\"change\", onChange);\n};\nconst useReducedMotion = () =>\n  React.useSyncExternalStore(subscribeReduced, () => window.matchMedia(reducedQuery).matches, () => false);\n\nconst subscribeNothing = () => () => {};\nconst useHydrated = () => React.useSyncExternalStore(subscribeNothing, () => true, () => false);\n\n/** A round limit a little past what's shown: 1, 2, 2.5 or 5 times a power of ten. */\nfunction niceRange(net: number, inflow: number, outflow: number) {\n  const want = Math.max(Math.abs(net) * 1.4, (Math.abs(inflow) + Math.abs(outflow)) * 0.12, 1);\n  const power = 10 ** Math.floor(Math.log10(want));\n  for (const step of [1, 2, 2.5, 5, 10]) if (step * power >= want) return step * power;\n  return 10 * power;\n}\n\ninterface Engine {\n  width: number;\n  half: number;\n  needle: Spring | null;\n  last: number;\n  glow: Float32Array;\n  glowSide: Int8Array;\n  frame: number;\n  time: number;\n  colors: { inflow: string; outflow: string; ink: string; bg: string };\n}\n\n/** One frame: the faint field, the lit run from zero to the needle, the light the needle left behind, and the needle. */\nfunction draw(e: Engine, canvas: HTMLCanvasElement | null) {\n  if (!canvas || !e.width || !e.needle) return;\n  const ctx = canvas.getContext(\"2d\");\n  if (!ctx) return;\n  const dpr = Math.min(window.devicePixelRatio || 1, 2);\n  const w = e.width;\n  if (canvas.width !== Math.round(w * dpr)) {\n    canvas.width = Math.round(w * dpr);\n    canvas.height = Math.round(H * dpr);\n  }\n  ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n  ctx.clearRect(0, 0, w, H);\n\n  const now = performance.now();\n  const dt = e.time ? Math.min(now - e.time, 100) : 0;\n  e.time = now;\n  const fade = Math.exp(-dt / (AFTERGLOW / Math.log(3)));\n  const half = e.half;\n  const cx = w / 2;\n  const pos = Math.max(-1.04, Math.min(1.04, e.needle.get())) * half; // in ticks\n  // The ticks the needle crossed since the last frame keep its light.\n  const lo = Math.min(pos, e.last);\n  const hi = Math.max(pos, e.last);\n  let glowing = false;\n  for (let k = -half; k <= half; k++) {\n    const i = k + half;\n    e.glow[i] *= fade;\n    if (k !== 0 && k >= Math.ceil(lo) && k <= Math.floor(hi) && hi - lo > 0.05) {\n      e.glow[i] = 1;\n      e.glowSide[i] = k > 0 ? 1 : -1;\n    }\n    if (e.glow[i] > 0.01) glowing = true;\n    else e.glow[i] = 0;\n  }\n  e.last = pos;\n\n  const base = H - 6;\n  for (let k = -half; k <= half; k++) {\n    const i = k + half;\n    const x = cx + k * PITCH - TICK / 2;\n    const major = k === 0 ? 2 : k % (half / 2) === 0 ? 1 : 0;\n    const h = major === 2 ? 26 : major === 1 ? 19 : 13;\n    // Faint field\n    ctx.globalAlpha = major === 2 ? 0.42 : major === 1 ? 0.24 : 0.13;\n    ctx.fillStyle = e.colors.ink;\n    const lit = k !== 0 && (k > 0 ? k <= pos : k >= pos) && Math.abs(pos) > 0.01;\n    const light = lit ? 0.32 + 0.68 * Math.min(1, Math.abs(k) / Math.max(1, Math.abs(pos))) ** 1.4 : 0;\n    const after = e.glow[i] * 0.55;\n    if (light <= 0 && after <= 0) {\n      ctx.fillRect(x, base - h, TICK, h);\n      continue;\n    }\n    const side = lit ? (k > 0 ? 1 : -1) : e.glowSide[i];\n    ctx.globalAlpha = Math.max(light, after);\n    ctx.fillStyle = side > 0 ? e.colors.inflow : e.colors.outflow;\n    ctx.fillRect(x, base - h, TICK, h);\n  }\n\n  // The needle, with a gap of the card's colour cut round it so it reads over the ticks.\n  const nx = cx + pos * PITCH;\n  ctx.globalAlpha = 1;\n  ctx.fillStyle = e.colors.bg;\n  ctx.fillRect(nx - 3.5, 0, 7, H);\n  ctx.fillStyle = e.colors.ink;\n  ctx.beginPath();\n  ctx.roundRect(nx - 1.25, 3, 2.5, H - 6, 1.25);\n  ctx.fill();\n  ctx.beginPath();\n  ctx.arc(nx, 4.5, 3.5, 0, Math.PI * 2);\n  ctx.fill();\n\n  const moving = e.needle.getVelocity() !== 0;\n  if (glowing && !moving && !e.frame) {\n    e.frame = requestAnimationFrame(() => {\n      e.frame = 0;\n      draw(e, canvas);\n    });\n  }\n  if (!glowing && !moving) e.time = 0;\n}\n\nexport function BalanceMeter({ inflow, outflow, range: rangeProp, title = \"Net\", unit, format, locales, className = \"\", ...props }: BalanceMeterProps) {\n  const reduced = useReducedMotion();\n  const hydrated = useHydrated();\n  const locale = locales ?? (hydrated ? undefined : \"en-US\");\n  const net = inflow.value - outflow.value;\n  const range = rangeProp ?? niceRange(net, inflow.value, outflow.value);\n  const inColor = inflow.color ?? \"var(--chart-1, var(--primary))\";\n  const outColor = outflow.color ?? \"var(--chart-2, var(--primary))\";\n\n  const [visible, setVisible] = React.useState(false);\n  const [width, setWidth] = React.useState(0);\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const boxRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const probes = React.useRef<(HTMLSpanElement | null)[]>([]);\n  const engine = React.useRef<Engine>({\n    width: 0,\n    half: 0,\n    needle: null,\n    last: 0,\n    glow: new Float32Array(0),\n    glowSide: new Int8Array(0),\n    frame: 0,\n    time: 0,\n    colors: { inflow: \"#305dde\", outflow: \"#e8743b\", ink: \"#454545\", bg: \"#fff\" },\n  });\n\n  const paint = React.useCallback(() => draw(engine.current, canvasRef.current), []);\n\n  // The needle's spring, made before anything paints.\n  React.useLayoutEffect(() => {\n    const e = engine.current;\n    // A little under critical damping: it swings past and settles, like a scale's pointer.\n    e.needle = createSpring(0, { stiffness: 150, damping: 15 }, paint, 0.0005);\n    return () => {\n      e.needle?.stop();\n      e.needle = null;\n      if (e.frame) cancelAnimationFrame(e.frame);\n      e.frame = 0;\n    };\n  }, [paint]);\n\n  React.useLayoutEffect(() => {\n    const box = boxRef.current;\n    if (!box) return;\n    const measure = () => setWidth((w) => (w === box.offsetWidth ? w : box.offsetWidth));\n    measure();\n    const observer = new ResizeObserver(measure);\n    observer.observe(box);\n    return () => observer.disconnect();\n  }, []);\n\n  // Ticks to fit the width, an even number either side so the half-way ticks land on whole ticks.\n  const half = Math.max(4, Math.floor((width - PAD * 2) / PITCH / 4) * 2);\n  React.useLayoutEffect(() => {\n    const e = engine.current;\n    e.width = width;\n    if (e.half !== half) {\n      e.half = half;\n      e.glow = new Float32Array(half * 2 + 1);\n      e.glowSide = new Int8Array(half * 2 + 1);\n      e.last = (e.needle?.get() ?? 0) * half;\n    }\n    paint();\n  }, [width, half, paint]);\n\n  // The theme's colours, read again whenever the theme changes.\n  React.useEffect(() => {\n    const read = () => {\n      const [a, b, c, d] = probes.current.map((p) => (p ? getComputedStyle(p).color : \"\"));\n      engine.current.colors = { inflow: a || \"#305dde\", outflow: b || \"#e8743b\", ink: c || \"#454545\", bg: d || \"#fff\" };\n      paint();\n    };\n    read();\n    const observer = new MutationObserver(read);\n    observer.observe(document.documentElement, { attributes: true, attributeFilter: [\"class\", \"style\", \"data-theme\"] });\n    const media = window.matchMedia(\"(prefers-color-scheme: dark)\");\n    media.addEventListener(\"change\", read);\n    return () => {\n      observer.disconnect();\n      media.removeEventListener(\"change\", read);\n    };\n  }, [inColor, outColor, paint]);\n\n  React.useEffect(() => {\n    const el = rootRef.current;\n    if (!el) return;\n    const observer = new IntersectionObserver(\n      ([entry]) => {\n        if (entry.isIntersecting) {\n          setVisible(true);\n          observer.disconnect();\n        }\n      },\n      { rootMargin: \"0px 0px -10% 0px\" },\n    );\n    observer.observe(el);\n    return () => observer.disconnect();\n  }, []);\n\n  const target = visible ? net / range : 0;\n  React.useEffect(() => {\n    const needle = engine.current.needle;\n    if (!needle) return;\n    if (reduced) needle.jump(target);\n    else needle.set(target);\n  }, [target, reduced]);\n\n  const fmt = (v: number) => new Intl.NumberFormat(locale, format).format(v);\n  const signed: Intl.NumberFormatOptions = { ...format, signDisplay: \"exceptZero\" };\n  const unitText = unit ? ` ${unit}` : \"\";\n  // Five labels where they fit, the ends and zero where they don't.\n  const marks = half * PITCH * 2 >= 300 ? [-1, -0.5, 0, 0.5, 1] : [-1, 0, 1];\n  const low = -range;\n\n  return (\n    <div ref={rootRef} className={`w-full rounded-[22px] bg-background shadow-[0_0_0_1px_var(--border)] ${className}`} {...props}>\n      <div aria-hidden=\"true\" data-natural-width className=\"grid h-0\" style={{ gridTemplateColumns: \"minmax(0, 460px)\" }} />\n      <div className=\"@container w-full\">\n        <div className=\"p-4 @md:p-5\">\n          <div className=\"flex flex-wrap items-end justify-between gap-x-4 gap-y-3\">\n            <div className=\"min-w-0\">\n              <p className=\"text-[26px] font-medium leading-none tracking-[-0.035em] text-foreground tabular-nums @md:text-[32px]\">\n                <NumberRoll value={visible ? net : 0} format={signed} locales={locale} duration={1000} />\n                {unit && <span className=\"ml-1 text-[14px] font-normal tracking-normal text-muted-foreground @md:text-[15px]\">{unit}</span>}\n              </p>\n              <p className=\"mt-1.5 truncate text-[12px] text-muted-foreground @md:text-[13px]\">{title}</p>\n            </div>\n            <dl className=\"flex items-baseline gap-x-4 text-[12px] @md:text-[13px]\">\n              {[outflow, inflow].map((flow, i) => {\n                const color = i === 0 ? outColor : inColor;\n                return (\n                  <div key={i} className=\"flex items-baseline gap-1.5\">\n                    <dt className=\"flex items-center gap-1.5 self-center text-muted-foreground\">\n                      {flow.icon ? (\n                        <span className=\"flex size-3.5 items-center justify-center [&>svg]:size-3.5\" style={{ color }}>\n                          {flow.icon}\n                        </span>\n                      ) : (\n                        <span className=\"size-2 rounded-[2px]\" style={{ background: color }} />\n                      )}\n                      {flow.label}\n                    </dt>\n                    <dd className=\"font-medium tabular-nums\" style={{ color: `color-mix(in oklab, ${color} 82%, var(--foreground))` }}>\n                      <NumberRoll value={visible ? flow.value : 0} format={format} locales={locale} duration={1000} />\n                    </dd>\n                  </div>\n                );\n              })}\n            </dl>\n          </div>\n\n          <div\n            ref={boxRef}\n            role=\"meter\"\n            aria-label={title}\n            aria-valuemin={low}\n            aria-valuemax={range}\n            aria-valuenow={net}\n            aria-valuetext={`${new Intl.NumberFormat(locale, signed).format(net)}${unitText}: ${inflow.label} ${fmt(inflow.value)}, ${outflow.label} ${fmt(outflow.value)}`}\n            className=\"relative mt-5 @md:mt-6\"\n          >\n            <canvas ref={canvasRef} aria-hidden=\"true\" className=\"block w-full\" style={{ height: H }} />\n            <div aria-hidden=\"true\" className=\"relative mt-1.5 h-4 text-[11px] text-muted-foreground tabular-nums @md:text-[11.5px]\">\n              {width > 0 &&\n                marks.map((m) => (\n                  <span\n                    key={m}\n                    className=\"absolute top-0 -translate-x-1/2 whitespace-nowrap\"\n                    style={{ left: width / 2 + m * half * PITCH, transition: `left 300ms ${EASE}` }}\n                  >\n                    <NumberRoll value={m * range} format={format} locales={locale} duration={reduced ? 0 : 900} />\n                  </span>\n                ))}\n            </div>\n          </div>\n        </div>\n      </div>\n      {/* Colour probes for the canvas. */}\n      <span ref={(el) => void (probes.current[0] = el)} aria-hidden=\"true\" className=\"hidden\" style={{ color: inColor }} />\n      <span ref={(el) => void (probes.current[1] = el)} aria-hidden=\"true\" className=\"hidden\" style={{ color: outColor }} />\n      <span ref={(el) => void (probes.current[2] = el)} aria-hidden=\"true\" className=\"hidden text-foreground\" />\n      <span ref={(el) => void (probes.current[3] = el)} aria-hidden=\"true\" className=\"hidden text-background\" />\n    </div>\n  );\n}\n"},{"path":"registry/ui-interaction-motion.ts","type":"registry:component","content":"// Hairline UI · balance-meter · 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/balance-meter. MIT licensed: https://hairlineui.com/license#components","meta":{"license":"MIT"}}