{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"stage-timeline","type":"registry:component","title":"Stage timeline","description":"A session as stages over time on dark lacquer, with a dot-matrix clock that turns to the time under your finger as you scrub.","author":"Hairline UI","dependencies":[],"registryDependencies":["https://hairlineui.com/r/text-morph.json?as=dependency"],"files":[{"path":"registry/stage-timeline.tsx","type":"registry:component","content":"// Hairline UI · stage-timeline · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n\"use client\";\n\nimport * as React from \"react\";\nimport { lacquer, type LacquerTone } from \"./lacquer\";\nimport { TextMorph } from \"./text-morph\";\nimport { EASE_OUT, useInteractionReducedMotion } from \"./ui-interaction-motion\";\n\n/* ─────────────────────────────────────────────────────────\n * STAGE TIMELINE: a session as stages over time\n *\n *   steps    each stretch of the session is a short plateau at\n *            its intensity, in its stage's colour, joined by a\n *            fine stepped line, with a bead on each\n *   clock    a dot-matrix readout shows how long the session\n *            ran; point into the timeline and its dots change\n *            over to the time under your finger, column by\n *            column, and back when you let go\n *   scrub    a lime cursor follows the pointer; the stretch under\n *            it thickens and its bead grows, and the corner names\n *            the time and the stage in that stage's colour\n *\n * An object with its own dark lacquer finish: the same on a light\n * page or a dark one.\n *\n * Reduced motion: dots and cursor change in place.\n * ───────────────────────────────────────────────────────── */\n\nexport interface TimelineStage {\n  id: string;\n  label: string;\n  /** Any CSS colour. */\n  color: string;\n}\n\nexport interface TimelinePoint {\n  /** Shown on the clock and in the corner: \"22:25\". */\n  time: string;\n  /** A stage id. */\n  stage: string;\n  /** How high the stretch sits, 0 to 100. */\n  value: number;\n  /** Read out with it: \"−11 LUFS\", \"58 bpm\". */\n  detail?: string;\n}\n\nexport interface StageTimelineProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\"> {\n  points: TimelinePoint[];\n  stages: TimelineStage[];\n  /** How long it ran, on the clock at rest: \"3:48\". Digits, \":\" and \".\" */\n  total: string;\n  /** Beside the clock at rest: \"h · 21:10 to 00:58\". */\n  caption?: string;\n  title?: string;\n  icon?: React.ReactNode;\n  /** Times under the timeline; by default the first, middle and last. */\n  ticks?: string[];\n  /** The lacquer: a named tone or any CSS colour. */\n  tone?: LacquerTone | (string & {});\n  /** The cursor. */\n  accent?: string;\n}\n\n// 5 × 7 dot glyphs, one string per row.\nconst GLYPHS: Record<string, string[]> = {\n  \"0\": [\"01110\", \"10001\", \"10011\", \"10101\", \"11001\", \"10001\", \"01110\"],\n  \"1\": [\"00100\", \"01100\", \"00100\", \"00100\", \"00100\", \"00100\", \"01110\"],\n  \"2\": [\"01110\", \"10001\", \"00001\", \"00010\", \"00100\", \"01000\", \"11111\"],\n  \"3\": [\"11110\", \"00001\", \"00001\", \"01110\", \"00001\", \"00001\", \"11110\"],\n  \"4\": [\"10010\", \"10010\", \"10010\", \"11111\", \"00010\", \"00010\", \"00010\"],\n  \"5\": [\"11111\", \"10000\", \"11110\", \"00001\", \"00001\", \"10001\", \"01110\"],\n  \"6\": [\"00110\", \"01000\", \"10000\", \"11110\", \"10001\", \"10001\", \"01110\"],\n  \"7\": [\"11111\", \"00001\", \"00010\", \"00100\", \"01000\", \"01000\", \"01000\"],\n  \"8\": [\"01110\", \"10001\", \"10001\", \"01110\", \"10001\", \"10001\", \"01110\"],\n  \"9\": [\"01110\", \"10001\", \"10001\", \"01111\", \"00001\", \"00010\", \"01100\"],\n  \":\": [\"00000\", \"00000\", \"00100\", \"00000\", \"00100\", \"00000\", \"00000\"],\n  \".\": [\"00000\", \"00000\", \"00000\", \"00000\", \"00000\", \"00000\", \"00100\"],\n  \" \": [\"00000\", \"00000\", \"00000\", \"00000\", \"00000\", \"00000\", \"00000\"],\n};\n\n/** A dot-matrix readout of a fixed number of cells; a change lights and dims dots column by column, left to right. */\nfunction DotClock({ text, cells, reduced }: { text: string; cells: number; reduced: boolean }) {\n  const padded = text.padStart(cells, \" \").slice(-cells);\n  return (\n    <span aria-hidden className=\"inline-flex items-center gap-[5px]\">\n      {Array.from(padded).map((ch, c) => {\n        const rows = GLYPHS[ch] ?? GLYPHS[\" \"];\n        return (\n          <span key={c} className=\"grid grid-cols-[repeat(5,3px)] gap-[2px]\">\n            {rows.flatMap((row, r) =>\n              Array.from(row).map((bit, x) => (\n                <span\n                  key={`${r}-${x}`}\n                  className=\"block size-[3px] rounded-full\"\n                  style={{\n                    background: bit === \"1\" ? \"rgb(255 255 255 / 0.96)\" : \"rgb(255 255 255 / 0.09)\",\n                    transition: reduced ? \"none\" : `background-color 200ms ease-out ${(c * 5 + x) * 9}ms`,\n                  }}\n                />\n              )),\n            )}\n          </span>\n        );\n      })}\n    </span>\n  );\n}\n\nexport function StageTimeline({\n  points,\n  stages,\n  total,\n  caption,\n  title = \"Session\",\n  icon,\n  ticks,\n  tone = \"midnight\",\n  accent = \"#dcfc4e\",\n  className = \"\",\n  style,\n  ...props\n}: StageTimelineProps) {\n  const reduced = useInteractionReducedMotion();\n  const gradient = React.useId();\n  const box = React.useRef<HTMLDivElement>(null);\n  const [width, setWidth] = React.useState(0);\n  const [index, setIndex] = React.useState(() => points.reduce((best, p, i) => (p.value > points[best].value ? i : best), 0));\n  const [cursor, setCursor] = React.useState<number | null>(null);\n  const [active, setActive] = React.useState(false);\n  const [dragging, setDragging] = React.useState(false);\n  const color = (id: string) => stages.find((s) => s.id === id)?.color ?? \"#fff\";\n  const stageOf = (id: string) => stages.find((s) => s.id === id)?.label ?? id;\n\n  React.useLayoutEffect(() => {\n    const el = box.current;\n    if (!el) return;\n    const measure = () => setWidth((w) => (w === el.offsetWidth ? w : el.offsetWidth));\n    measure();\n    const ro = new ResizeObserver(measure);\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n\n  const H = 72;\n  const padX = 6;\n  const padY = 10;\n  const n = points.length;\n  const step = n ? (width - padX * 2) / n : 0;\n  const segs = points.map((p, i) => {\n    const x1 = padX + i * step + 3;\n    const x2 = padX + (i + 1) * step - 3;\n    return { x1, x2, cx: (x1 + x2) / 2, y: H - padY - (Math.max(0, Math.min(100, p.value)) / 100) * (H - padY * 2), p };\n  });\n  let path = \"\";\n  segs.forEach((s, i) => {\n    if (i === 0) path = `M ${s.x1.toFixed(1)} ${s.y.toFixed(1)} L ${s.x2.toFixed(1)} ${s.y.toFixed(1)}`;\n    else {\n      const prev = segs[i - 1];\n      const mid = ((prev.x2 + s.x1) / 2).toFixed(1);\n      path += ` L ${mid} ${prev.y.toFixed(1)} L ${mid} ${s.y.toFixed(1)} L ${s.x1.toFixed(1)} ${s.y.toFixed(1)} L ${s.x2.toFixed(1)} ${s.y.toFixed(1)}`;\n    }\n  });\n\n  const current = segs[index];\n  const point = points[index];\n  const cursorX = cursor ?? current?.cx ?? 0;\n  const cells = Math.max(total.length, ...points.map((p) => p.time.length));\n  const tickLabels = ticks ?? (n ? [points[0].time, points[Math.floor((n - 1) / 2)].time, points[n - 1].time] : []);\n\n  const fromPointer = (clientX: number) => {\n    const el = box.current;\n    if (!el || !n) return;\n    const r = el.getBoundingClientRect();\n    const x = Math.max(padX, Math.min(r.width - padX, clientX - r.left));\n    setCursor(x);\n    setIndex(Math.max(0, Math.min(n - 1, Math.floor((x - padX) / step))));\n  };\n\n  const live = active || dragging;\n\n  return (\n    <div className={`relative flex w-full flex-col overflow-clip rounded-[22px] px-5 py-4 select-none ${className}`} style={{ ...lacquer(tone), ...style }} {...props}>\n      <div className=\"flex items-center justify-between gap-2\">\n        <div className=\"flex items-center gap-1.5 text-[11.5px] font-medium text-white/85\">\n          {icon}\n          <span>{title}</span>\n        </div>\n        {point && (\n          <div className=\"font-mono text-[11.5px] font-medium tabular-nums transition-colors duration-300\" style={{ color: color(point.stage) }}>\n            <TextMorph>{`${point.time} · ${stageOf(point.stage)}`}</TextMorph>\n          </div>\n        )}\n      </div>\n\n      <div className=\"mt-3 flex flex-wrap items-end gap-x-2.5 gap-y-1.5\">\n        <DotClock text={live && point ? point.time : total} cells={cells} reduced={reduced} />\n        <span className=\"whitespace-nowrap pb-px text-[12px] tabular-nums text-white/70\">\n          <TextMorph>{live && point ? `${stageOf(point.stage)}${point.detail ? ` · ${point.detail}` : \"\"}` : (caption ?? \"\")}</TextMorph>\n        </span>\n      </div>\n\n      <div className=\"mt-3\">\n        <div\n          ref={box}\n          role=\"slider\"\n          tabIndex={0}\n          aria-label={`${title} timeline`}\n          aria-valuemin={0}\n          aria-valuemax={Math.max(0, n - 1)}\n          aria-valuenow={index}\n          aria-valuetext={point ? `${point.time}, ${stageOf(point.stage)}${point.detail ? `, ${point.detail}` : \"\"}` : undefined}\n          onPointerEnter={(e) => e.pointerType === \"mouse\" && setActive(true)}\n          onPointerMove={(e) => (e.pointerType === \"mouse\" || dragging) && fromPointer(e.clientX)}\n          onPointerLeave={(e) => {\n            if (e.pointerType !== \"mouse\" || dragging) return;\n            setActive(false);\n            setCursor(null);\n          }}\n          onPointerDown={(e) => {\n            e.currentTarget.setPointerCapture(e.pointerId);\n            setDragging(true);\n            fromPointer(e.clientX);\n          }}\n          onPointerUp={() => {\n            setDragging(false);\n            setCursor(null);\n          }}\n          onPointerCancel={() => {\n            setDragging(false);\n            setCursor(null);\n          }}\n          onFocus={() => setActive(true)}\n          onBlur={() => setActive(false)}\n          onKeyDown={(e) => {\n            const to = { ArrowRight: index + 1, ArrowUp: index + 1, ArrowLeft: index - 1, ArrowDown: index - 1, Home: 0, End: n - 1 }[e.key];\n            if (to === undefined) return;\n            e.preventDefault();\n            setCursor(null);\n            setIndex(Math.max(0, Math.min(n - 1, to)));\n          }}\n          className=\"relative h-[72px] w-full cursor-ew-resize touch-none rounded-lg outline-none focus-visible:ring-1 focus-visible:ring-white/50\"\n        >\n          {width > 0 && (\n            <svg aria-hidden width={width} height={H} viewBox={`0 0 ${width} ${H}`} className=\"absolute inset-0 overflow-visible\">\n              <defs>\n                <linearGradient id={gradient} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n                  <stop offset=\"0%\" stopColor={accent} stopOpacity=\"0.15\" />\n                  <stop offset=\"50%\" stopColor={accent} stopOpacity=\"0.95\" />\n                  <stop offset=\"100%\" stopColor={accent} stopOpacity=\"0.2\" />\n                </linearGradient>\n              </defs>\n              <path d={path} fill=\"none\" stroke=\"rgb(255 255 255 / 0.3)\" strokeWidth=\"1.2\" strokeLinejoin=\"round\" />\n              {segs.map((s, i) => {\n                const on = i === index;\n                const c = color(s.p.stage);\n                return (\n                  <g key={`${s.p.time}-${i}`}>\n                    <line x1={s.x1} y1={s.y} x2={s.x2} y2={s.y} stroke={c} strokeWidth={on ? 2.6 : 1.7} strokeLinecap=\"round\" opacity={on ? 1 : 0.7} style={{ transition: \"stroke-width 200ms ease-out, opacity 200ms\" }} />\n                    <circle cx={s.cx} cy={s.y} r={on ? 9 : 2.8} fill={c} opacity={on ? 0.24 : 0} style={{ transition: `r 260ms ${EASE_OUT}, opacity 200ms` }} />\n                    <circle cx={s.cx} cy={s.y} r={on ? 4.2 : 2.8} fill={c} opacity={on ? 1 : 0.88} style={{ transition: `r 260ms ${EASE_OUT}` }} />\n                  </g>\n                );\n              })}\n              <g style={{ transform: `translateX(${cursorX}px)`, transition: cursor === null && !reduced ? `transform 260ms ${EASE_OUT}` : \"none\" }}>\n                <line x1={0} y1={2} x2={0} y2={H - 2} stroke={`url(#${CSS.escape(gradient)})`} strokeWidth=\"1.5\" />\n                <circle cx={0} cy={current?.y ?? 0} r={2.5} fill={accent} style={{ transition: reduced ? \"none\" : `cy 200ms ${EASE_OUT}` }} />\n              </g>\n            </svg>\n          )}\n        </div>\n        <div className=\"mt-1 flex items-center justify-between font-mono text-[10px] tabular-nums text-white/55\">\n          {tickLabels.map((t, i) => (\n            <span key={`${t}-${i}`}>{t}</span>\n          ))}\n        </div>\n      </div>\n      <span className=\"sr-only\">\n        {title}: {total}\n        {caption ? ` ${caption}` : \"\"}\n      </span>\n    </div>\n  );\n}\n"},{"path":"registry/lacquer.ts","type":"registry:component","content":"// Hairline UI · stage-timeline · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n/* ─────────────────────────────────────────────────────────\n * LACQUER: the dark surface of Pillar chart, Stage timeline and\n * Track player\n *\n * These cards are objects with their own finish, like a device\n * screen or a lacquered box: always dark, the same on a light page\n * or a dark one. The colour pools in from two corners over a near\n * black, with a fine light along the top edge and a dark one along\n * the bottom; no drop shadow.\n *\n * Named tones are mixed here into plain rgba() so every browser\n * paints them (Safari dropped color-mix() inside these gradients);\n * a solid near-black sits under the gradients either way, so the\n * card can never come out light.\n * ───────────────────────────────────────────────────────── */\n\nimport type * as React from \"react\";\n\nexport type LacquerTone = \"cobalt\" | \"ember\" | \"rose\" | \"emerald\" | \"midnight\" | \"violet\";\n\nexport const LACQUER: Record<LacquerTone, string> = {\n  cobalt: \"#3462eb\",\n  ember: \"#ce3e1a\",\n  rose: \"#d0306c\",\n  emerald: \"#0f9f74\",\n  midnight: \"#3a4fd6\",\n  violet: \"#7e22f5\",\n};\n\n/** Any named tone or CSS colour, as the colour the lacquer is mixed from. */\nexport const toneColor = (tone: LacquerTone | (string & {})) => (tone in LACQUER ? LACQUER[tone as LacquerTone] : tone);\n\nconst BASE = \"#060609\";\n\ntype Rgb = [number, number, number];\nconst hex = (h: string): Rgb | null => {\n  const m = /^#([0-9a-f]{6})$/i.exec(h.trim());\n  return m ? [parseInt(m[1].slice(0, 2), 16), parseInt(m[1].slice(2, 4), 16), parseInt(m[1].slice(4, 6), 16)] : null;\n};\nconst rgba = ([r, g, b]: Rgb, a = 1) => `rgba(${Math.round(r)}, ${Math.round(g)}, ${Math.round(b)}, ${a})`;\nconst blend = (a: Rgb, b: Rgb, t: number): Rgb => [a[0] * t + b[0] * (1 - t), a[1] * t + b[1] * (1 - t), a[2] * t + b[2] * (1 - t)];\n\n/**\n * A tone mixed with another colour: `share` of the tone (0 to 1). Plain rgba() for hex colours (named tones included);\n * anything else (oklch(), a theme variable) falls back to color-mix(), which needs a browser that paints it.\n */\nexport function mixTone(tone: LacquerTone | (string & {}), share: number, other: \"transparent\" | (string & {}) = \"transparent\") {\n  const t = hex(toneColor(tone));\n  const o = other === \"transparent\" ? null : hex(other);\n  if (t && other === \"transparent\") return rgba(t, share);\n  if (t && o) return rgba(blend(t, o, share));\n  return `color-mix(in oklab, ${toneColor(tone)} ${Math.round(share * 100)}%, ${other})`;\n}\n\n/** The lacquer as inline styles: background, the lit top edge and a hairline border. Text on it is white. */\nexport function lacquer(tone: LacquerTone | (string & {})): React.CSSProperties {\n  const m = (share: number, over: \"transparent\" | (string & {}) = \"transparent\") => mixTone(tone, share, over);\n  return {\n    background: [\n      `radial-gradient(88% 78% at 10% 8%, ${m(0.74)} 0%, ${m(0.32)} 46%, transparent 76%)`,\n      `radial-gradient(82% 76% at 92% 96%, ${m(0.6)} 0%, ${m(0.26)} 52%, transparent 80%)`,\n      `linear-gradient(150deg, ${m(0.34, BASE)} 0%, ${m(0.09, BASE)} 52%, ${m(0.28, BASE)} 100%)`,\n    ].join(\", \"),\n    // Set after the shorthand, so a gradient a browser can't paint still leaves the card dark.\n    backgroundColor: BASE,\n    boxShadow: \"inset 0 1px 0 rgb(255 255 255 / 0.26), inset 0 -1px 0 rgb(0 0 0 / 0.35)\",\n    border: \"1px solid rgb(255 255 255 / 0.14)\",\n    color: \"#fff\",\n    colorScheme: \"dark\",\n  };\n}\n"},{"path":"registry/ui-interaction-motion.ts","type":"registry:component","content":"// Hairline UI · stage-timeline · 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/stage-timeline. MIT licensed: https://hairlineui.com/license#components","meta":{"license":"MIT"}}