{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"merge-button","type":"registry:component","title":"Merge button","description":"Merge a pull request and see it go in: the button carries a small branch graph, and pressing it draws what your merge strategy really does to main.","author":"Hairline UI","dependencies":[],"registryDependencies":["https://hairlineui.com/r/text-morph.json?as=dependency"],"files":[{"path":"registry/merge-button.tsx","type":"registry:component","content":"// Hairline UI · merge-button · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n\"use client\";\n\nimport * as React from \"react\";\nimport { TextMorph } from \"./text-morph\";\nimport { INTERACTION_FOCUS, INTERACTION_PRESS } from \"./ui-interaction-motion\";\nimport { playSound } from \"./ui-sounds\";\n\n/* ─────────────────────────────────────────────────────────\n * MERGE BUTTON: merge a pull request and see it go in\n *\n *   ready      the button carries a small graph: main along the\n *              bottom, your branch forking off it with its commits\n *   merging    while your onMerge runs, a pulse runs along the\n *              branch, the way checks run\n *   merged     each strategy draws what really happens:\n *                merge   the branch bends down into main and a\n *                        merge commit lands where they meet\n *                squash  the commits slide together into one, and\n *                        that one drops onto main\n *                rebase  each commit lifts off the branch and lands\n *                        on main in turn, the branch fades\n *   conflict   if onMerge throws, the branch dips towards main and\n *              the lines cross with a red mark and a shake; press\n *              again to retry\n *\n * One SVG, moved by a short frame loop that runs only while\n * something changes.\n * ───────────────────────────────────────────────────────── */\n\nexport type MergeStrategy = \"merge\" | \"squash\" | \"rebase\";\ntype Phase = \"idle\" | \"pending\" | \"done\" | \"error\";\n\nexport interface MergeButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"onClick\" | \"children\"> {\n  /** Your merge call. Throw or reject to show a conflict (or any failure) with the reason in the label. */\n  onMerge: () => Promise<unknown> | void;\n  strategy?: MergeStrategy;\n  /** How many commits to draw on the branch, 1 to 4. */\n  commits?: number;\n  /** Already merged: shows the merged state, still. */\n  merged?: boolean;\n  labels?: Partial<Record<Phase, string>>;\n  /** A soft click as it lands, off by default. */\n  sound?: boolean;\n}\n\nconst LABELS: Record<MergeStrategy, Record<Phase, string>> = {\n  merge: { idle: \"Merge pull request\", pending: \"Merging\", done: \"Merged\", error: \"Resolve conflicts\" },\n  squash: { idle: \"Squash and merge\", pending: \"Squashing\", done: \"Squashed and merged\", error: \"Resolve conflicts\" },\n  rebase: { idle: \"Rebase and merge\", pending: \"Rebasing\", done: \"Rebased and merged\", error: \"Resolve conflicts\" },\n};\n\n// The graph, in its own units (viewBox 92 × 32).\nconst MAIN_Y = 24;\nconst BRANCH_Y = 9;\nconst FORK = 9;\nconst HEAD = 62;\nconst JOIN = 78;\nconst END = 90;\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 = () => React.useSyncExternalStore(subscribeReduced, () => window.matchMedia(reducedQuery).matches, () => false);\n\nconst clamp = (v: number, a: number, b: number) => (v < a ? a : v > b ? b : v);\nconst seg = (t: number, a: number, b: number) => clamp((t - a) / (b - a), 0, 1);\nconst inOut = (t: number) => (t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2);\nconst out = (t: number) => 1 - (1 - t) ** 3;\nconst back = (t: number) => 1 + 2.4 * (t - 1) ** 3 + 1.4 * (t - 1) ** 2;\n\n/** Where commit i of n sits on the branch. */\nconst commitX = (i: number, n: number) => (n === 1 ? HEAD : 30 + ((HEAD - 30) * i) / (n - 1));\n/** Where rebased commit i of n lands on main. */\nconst replayX = (i: number, n: number) => JOIN - 12 * (n - 1 - i) * (n > 3 ? 0.75 : 1);\n\nexport function MergeButton({ onMerge, strategy = \"merge\", commits = 3, merged = false, labels, sound = false, className = \"\", disabled, ...props }: MergeButtonProps) {\n  const reduced = useReducedMotion();\n  const n = clamp(Math.round(commits), 1, 4);\n  const [phase, setPhase] = React.useState<Phase>(merged ? \"done\" : \"idle\");\n  const [message, setMessage] = React.useState<string | null>(null);\n  const text = { ...LABELS[strategy], ...labels };\n  const label = phase === \"error\" && message ? message : text[phase];\n\n  const svgRef = React.useRef<SVGSVGElement>(null);\n  const timeline = React.useRef({ phase: phase as Phase, t0: 0, frame: 0, from: phase as Phase });\n\n  /** Writes the graph for the current phase and time; returns whether it's still moving. */\n  const draw = React.useCallback(\n    (now: number) => {\n      const svg = svgRef.current;\n      if (!svg) return false;\n      const tl = timeline.current;\n      const t = reduced ? 1e6 : now - tl.t0;\n      const q = <T extends Element>(sel: string) => svg.querySelector<T>(sel);\n      const all = (sel: string) => Array.from(svg.querySelectorAll<SVGElement>(sel));\n      const branch = q<SVGPathElement>(\"[data-branch]\")!;\n      const bend = q<SVGPathElement>(\"[data-bend]\")!;\n      const join = q<SVGGElement>(\"[data-join]\")!;\n      const extend = q<SVGPathElement>(\"[data-extend]\")!;\n      const pulse = q<SVGPathElement>(\"[data-pulse]\")!;\n      const cross = q<SVGGElement>(\"[data-cross]\")!;\n      const dots = all(\"[data-commit]\") as SVGGElement[];\n      let busy = false;\n      const show = (el: SVGElement, o: number) => el.setAttribute(\"opacity\", String(clamp(o, 0, 1)));\n      const at = (el: SVGElement, x: number, y: number, s = 1) => el.setAttribute(\"transform\", `translate(${x} ${y}) scale(${s})`);\n\n      // Defaults: the ready graph, brightening back from the dimmed checks if they just ended.\n      const lit = tl.from === \"pending\" && tl.phase !== \"pending\" ? out(seg(t, 0, 220)) : 1;\n      branch.style.strokeDashoffset = \"0\";\n      show(branch, 0.4 + 0.6 * lit);\n      show(bend, 0);\n      show(join, 0);\n      show(extend, 0);\n      show(pulse, 0);\n      show(cross, 0);\n      svg.style.translate = \"\";\n      dots.forEach((d, i) => {\n        show(d, 0.7 + 0.3 * lit);\n        at(d, commitX(i, n), BRANCH_Y);\n      });\n\n      if (tl.phase === \"pending\") {\n        // Checks running: the branch dims, a bright dash travels it from the fork, and each commit lights as it passes.\n        busy = true;\n        const ease = reduced ? 1 : out(seg(now - tl.t0, 0, 240));\n        show(branch, 1 - 0.6 * ease);\n        const k = ((now - tl.t0) % 1300) / 1300;\n        const p = -0.16 + 1.3 * k;\n        show(pulse, ease * (1 - seg(k, 0.85, 1)));\n        pulse.style.strokeDashoffset = String(-p);\n        const total = branch.getTotalLength();\n        const curve = total - (HEAD - FORK - 17);\n        dots.forEach((d, i) => {\n          const pos = (curve + commitX(i, n) - FORK - 17) / total;\n          show(d, 1 - ease * (p + 0.12 >= pos ? 0.1 : 0.5));\n        });\n      } else if (tl.phase === \"error\") {\n        // The branch dips towards main, the lines cross, a red mark, a shake.\n        const dip = out(seg(t, 0, 260)) * (1 - 0.6 * out(seg(t, 260, 520)));\n        show(bend, dip);\n        bend.style.strokeDashoffset = String(1 - dip * 0.55);\n        show(cross, back(seg(t, 160, 420)));\n        at(cross, JOIN - 6, (BRANCH_Y + MAIN_Y) / 2 + 1, Math.max(0.01, back(seg(t, 160, 420))));\n        const shake = seg(t, 160, 560);\n        svg.style.translate = shake > 0 && shake < 1 ? `${Math.sin(shake * Math.PI * 6) * 2.4 * (1 - shake)}px 0` : \"\";\n        busy = t < 600;\n      } else if (tl.phase === \"done\") {\n        busy = t < 1300;\n        if (strategy === \"merge\") {\n          // The branch bends down into main; the merge commit lands where they meet; main runs on.\n          const k = inOut(seg(t, 80, 520));\n          show(bend, 1);\n          bend.style.strokeDashoffset = String(1 - k);\n          const pop = seg(t, 440, 720);\n          show(join, pop > 0 ? 1 : 0);\n          at(join, JOIN, MAIN_Y, Math.max(0.01, back(pop)));\n          show(extend, 1);\n          extend.style.strokeDashoffset = String(1 - out(seg(t, 560, 900)));\n        } else if (strategy === \"squash\") {\n          // The commits slide together into the head, then that one commit drops onto main.\n          const gather = inOut(seg(t, 0, 380));\n          const drop = seg(t, 360, 820);\n          dots.forEach((d, i) => {\n            const x = commitX(i, n) + (HEAD - commitX(i, n)) * gather;\n            if (i < n - 1) {\n              show(d, (0.7 + 0.3 * lit) * (1 - seg(t, 260, 400)));\n              at(d, x, BRANCH_Y);\n            } else {\n              const e = inOut(drop);\n              const dx = HEAD + (JOIN - HEAD) * e;\n              const dy = BRANCH_Y + (MAIN_Y - BRANCH_Y) * e - Math.sin(Math.PI * e) * 5;\n              const squashed = 1 + 0.25 * gather * (1 - e) - (drop > 0.92 ? 0.12 * Math.sin(Math.PI * seg(t, 780, 900)) : 0);\n              at(d, dx, dy, squashed);\n            }\n          });\n          // The branch it leaves behind draws back to the fork.\n          branch.style.strokeDashoffset = String(-out(seg(t, 420, 900)));\n          show(branch, (0.4 + 0.6 * lit) * (1 - seg(t, 700, 950)));\n          show(extend, 1);\n          extend.style.strokeDashoffset = String(1 - out(seg(t, 760, 1100)));\n        } else {\n          // Rebase: each commit lifts off the branch and lands on main in turn; the branch fades.\n          dots.forEach((d, i) => {\n            const k = inOut(seg(t, 80 + i * 150, 480 + i * 150));\n            const x0 = commitX(i, n);\n            const x1 = replayX(i, n);\n            const x = x0 + (x1 - x0) * k;\n            const y = BRANCH_Y + (MAIN_Y - BRANCH_Y) * k - Math.sin(Math.PI * k) * 6;\n            at(d, x, y);\n          });\n          show(branch, (0.4 + 0.6 * lit) * (1 - seg(t, 300, 300 + n * 150 + 300)));\n          show(extend, 1);\n          extend.style.strokeDashoffset = String(1 - out(seg(t, 200, 520 + n * 150)));\n          busy = t < 700 + n * 150;\n        }\n      }\n      return busy;\n    },\n    [n, strategy, reduced],\n  );\n\n  const run = React.useCallback(() => {\n    const tl = timeline.current;\n    cancelAnimationFrame(tl.frame);\n    const tick = (now: number) => {\n      tl.frame = 0;\n      if (draw(now)) tl.frame = requestAnimationFrame(tick);\n    };\n    tl.frame = requestAnimationFrame(tick);\n  }, [draw]);\n\n  const go = React.useCallback(\n    (next: Phase) => {\n      const tl = timeline.current;\n      tl.from = tl.phase;\n      tl.phase = next;\n      tl.t0 = performance.now();\n      setPhase(next);\n      run();\n    },\n    [run],\n  );\n\n  React.useEffect(() => {\n    draw(performance.now());\n    const tl = timeline.current;\n    return () => {\n      cancelAnimationFrame(tl.frame);\n      tl.frame = 0;\n    };\n  }, [draw]);\n\n  const busy = phase === \"pending\";\n  const finished = phase === \"done\";\n  const click = async () => {\n    if (busy || finished || disabled) return;\n    setMessage(null);\n    go(\"pending\");\n    try {\n      await onMerge();\n      go(\"done\");\n      if (sound) playSound(\"success\", 0.35);\n    } catch (err) {\n      setMessage(err instanceof Error && err.message ? err.message : null);\n      go(\"error\");\n      if (sound) playSound(\"error\", 0.35);\n    }\n  };\n\n  const bendPath = `M ${HEAD} ${BRANCH_Y} C ${HEAD + 9} ${BRANCH_Y}, ${JOIN - 4} ${MAIN_Y}, ${JOIN} ${MAIN_Y}`;\n\n  return (\n    <>\n    <button\n      type=\"button\"\n      onClick={click}\n      aria-disabled={busy || finished || disabled || undefined}\n      aria-busy={busy || undefined}\n      className={`group inline-flex h-11 cursor-pointer items-center gap-2.5 rounded-full pl-2.5 pr-5 text-[13.5px] font-medium aria-disabled:cursor-default ${\n        phase === \"error\" ? \"bg-background text-foreground shadow-[inset_0_0_0_1px_var(--border)]\" : \"bg-primary text-primary-foreground\"\n      } transition-[background-color,color,box-shadow] duration-300 ${INTERACTION_PRESS} ${INTERACTION_FOCUS} ${className}`}\n      {...props}\n    >\n      <svg\n        ref={svgRef}\n        viewBox=\"0 0 92 32\"\n        width={92}\n        height={32}\n        aria-hidden\n        className=\"shrink-0 overflow-visible\"\n        fill=\"none\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n      >\n        {/* main, and where it runs on to once something lands */}\n        <path d={`M 2 ${MAIN_Y} H ${JOIN - 6}`} stroke=\"currentColor\" strokeOpacity={0.55} strokeWidth={2} />\n        <path data-extend d={`M ${JOIN - 14} ${MAIN_Y} H ${END}`} pathLength={1} strokeDasharray=\"1 1\" stroke=\"currentColor\" strokeWidth={2} opacity={0} />\n        {/* the branch, forking off main */}\n        <path\n          data-branch\n          d={`M ${FORK} ${MAIN_Y} C ${FORK + 9} ${MAIN_Y}, ${FORK + 8} ${BRANCH_Y}, ${FORK + 17} ${BRANCH_Y} H ${HEAD}`}\n          pathLength={1}\n          strokeDasharray=\"1 1\"\n          stroke=\"currentColor\"\n          strokeWidth={2}\n        />\n        <path data-bend d={bendPath} pathLength={1} strokeDasharray=\"1 1\" stroke=\"currentColor\" strokeWidth={2} opacity={0} />\n        {/* checks running along the branch */}\n        <path\n          data-pulse\n          d={`M ${FORK} ${MAIN_Y} C ${FORK + 9} ${MAIN_Y}, ${FORK + 8} ${BRANCH_Y}, ${FORK + 17} ${BRANCH_Y} H ${HEAD}`}\n          pathLength={1}\n          strokeDasharray=\"0.16 2\"\n          stroke=\"currentColor\"\n          strokeWidth={2.6}\n          opacity={0}\n        />\n        {/* the fork point on main */}\n        <circle cx={FORK} cy={MAIN_Y} r={2.4} fill=\"currentColor\" fillOpacity={0.55} />\n        {/* commits: a ring with a filled centre */}\n        {Array.from({ length: n }, (_, i) => (\n          <g key={i} data-commit transform={`translate(${commitX(i, n)} ${BRANCH_Y})`}>\n            <circle r={3.6} fill=\"currentColor\" />\n            <circle r={1.5} className={phase === \"error\" ? \"fill-background\" : \"fill-primary\"} />\n          </g>\n        ))}\n        {/* the merge commit */}\n        <g data-join opacity={0} transform={`translate(${JOIN} ${MAIN_Y})`}>\n          <circle r={5} fill=\"currentColor\" />\n          <circle r={2.1} className=\"fill-primary\" />\n        </g>\n        {/* a conflict */}\n        <g data-cross opacity={0} transform={`translate(${JOIN - 6} ${(BRANCH_Y + MAIN_Y) / 2})`}>\n          <circle r={5.4} className=\"fill-red-600 dark:fill-red-500\" />\n          <path d=\"M -2 -2 L 2 2 M 2 -2 L -2 2\" stroke=\"white\" strokeWidth={1.6} />\n        </g>\n      </svg>\n      <span className={phase === \"error\" ? \"text-red-600 dark:text-red-400\" : undefined}>\n        <TextMorph>{label}</TextMorph>\n      </span>\n    </button>\n    <span className=\"sr-only\" role=\"status\" aria-live=\"polite\">\n      {phase === \"done\" ? text.done : phase === \"error\" ? label : \"\"}\n    </span>\n    </>\n  );\n}\n"},{"path":"registry/ui-interaction-motion.ts","type":"registry:component","content":"// Hairline UI · merge-button · 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"},{"path":"registry/ui-sounds.ts","type":"registry:component","content":"// Hairline UI · merge-button · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n/* ─────────────────────────────────────────────────────────\n * UI SOUNDS: small interface sounds, made in code\n *\n * No files and nothing to license: every sound is built from a\n * tone or a burst of noise with the Web Audio API the moment it\n * plays. They're short and quiet, made to sit under an interface,\n * and components only play them when you pass `sound`.\n *\n *   fold     paper creasing: two short crisp bursts\n *   unfold   paper opening: a soft rising sweep\n *   drop     something small landing: a low, soft knock\n *   tick     a light click\n *   pop      a quick bright blip\n *   success  two soft rising notes\n *   error    two low falling notes\n *\n * Browsers only start audio after the visitor has pressed\n * something on the page, so a sound before that stays silent.\n * ───────────────────────────────────────────────────────── */\n\nexport type UiSound = \"fold\" | \"unfold\" | \"drop\" | \"tick\" | \"pop\" | \"success\" | \"error\";\n\nlet context: AudioContext | null = null;\nlet noise: AudioBuffer | null = null;\n\nfunction audio() {\n  if (typeof window === \"undefined\") return null;\n  if (!context) {\n    const Ctx = window.AudioContext ?? (window as unknown as { webkitAudioContext?: typeof AudioContext }).webkitAudioContext;\n    if (!Ctx) return null;\n    context = new Ctx();\n  }\n  if (context.state === \"suspended\") void context.resume().catch(() => {});\n  return context;\n}\n\nfunction noiseBuffer(ctx: AudioContext) {\n  if (noise && noise.sampleRate === ctx.sampleRate) return noise;\n  noise = ctx.createBuffer(1, Math.floor(ctx.sampleRate * 0.5), ctx.sampleRate);\n  const data = noise.getChannelData(0);\n  for (let i = 0; i < data.length; i++) data[i] = Math.random() * 2 - 1;\n  return noise;\n}\n\n/** A burst of filtered noise. */\nfunction burst(ctx: AudioContext, out: AudioNode, at: number, length: number, { type = \"bandpass\", from = 2000, to = from, q = 0.9, level = 0.5 }: { type?: BiquadFilterType; from?: number; to?: number; q?: number; level?: number }) {\n  const src = ctx.createBufferSource();\n  src.buffer = noiseBuffer(ctx);\n  const filter = ctx.createBiquadFilter();\n  filter.type = type;\n  filter.Q.value = q;\n  filter.frequency.setValueAtTime(from, at);\n  filter.frequency.exponentialRampToValueAtTime(Math.max(40, to), at + length);\n  const gain = ctx.createGain();\n  gain.gain.setValueAtTime(0.0001, at);\n  gain.gain.exponentialRampToValueAtTime(level, at + Math.min(0.012, length / 3));\n  gain.gain.exponentialRampToValueAtTime(0.0001, at + length);\n  src.connect(filter).connect(gain).connect(out);\n  src.start(at, Math.random() * 0.3, length + 0.02);\n}\n\n/** A tone that glides from one pitch to another. */\nfunction tone(ctx: AudioContext, out: AudioNode, at: number, length: number, { type = \"sine\", from, to = from, level = 0.4 }: { type?: OscillatorType; from: number; to?: number; level?: number }) {\n  const osc = ctx.createOscillator();\n  osc.type = type;\n  osc.frequency.setValueAtTime(from, at);\n  osc.frequency.exponentialRampToValueAtTime(Math.max(20, to), at + length);\n  const gain = ctx.createGain();\n  gain.gain.setValueAtTime(0.0001, at);\n  gain.gain.exponentialRampToValueAtTime(level, at + 0.006);\n  gain.gain.exponentialRampToValueAtTime(0.0001, at + length);\n  osc.connect(gain).connect(out);\n  osc.start(at);\n  osc.stop(at + length + 0.02);\n}\n\n/** Plays one sound. `volume` is 0 to 1; the default sits quietly under an interface. */\nexport function playSound(name: UiSound, volume = 0.5) {\n  const ctx = audio();\n  if (!ctx) return;\n  const out = ctx.createGain();\n  out.gain.value = Math.max(0, Math.min(1, volume)) * 0.5;\n  out.connect(ctx.destination);\n  const t = ctx.currentTime + 0.005;\n  switch (name) {\n    case \"fold\":\n      burst(ctx, out, t, 0.05, { type: \"highpass\", from: 2600, q: 0.7, level: 0.45 });\n      burst(ctx, out, t + 0.07, 0.07, { type: \"bandpass\", from: 3200, to: 1800, q: 1.2, level: 0.35 });\n      break;\n    case \"unfold\":\n      burst(ctx, out, t, 0.16, { type: \"bandpass\", from: 900, to: 2800, q: 0.8, level: 0.3 });\n      break;\n    case \"drop\":\n      tone(ctx, out, t, 0.12, { from: 180, to: 70, level: 0.55 });\n      burst(ctx, out, t, 0.03, { type: \"lowpass\", from: 1200, q: 0.5, level: 0.2 });\n      break;\n    case \"tick\":\n      tone(ctx, out, t, 0.025, { type: \"triangle\", from: 1900, to: 1500, level: 0.25 });\n      break;\n    case \"pop\":\n      tone(ctx, out, t, 0.06, { from: 620, to: 980, level: 0.3 });\n      break;\n    case \"success\":\n      tone(ctx, out, t, 0.11, { from: 660, level: 0.22 });\n      tone(ctx, out, t + 0.09, 0.16, { from: 990, level: 0.22 });\n      break;\n    case \"error\":\n      tone(ctx, out, t, 0.12, { type: \"triangle\", from: 330, level: 0.25 });\n      tone(ctx, out, t + 0.1, 0.18, { type: \"triangle\", from: 247, level: 0.25 });\n      break;\n  }\n  window.setTimeout(() => out.disconnect(), 600);\n}\n"}],"css":{},"docs":"Docs and live preview: https://hairlineui.com/ui/merge-button. MIT licensed: https://hairlineui.com/license#components","meta":{"license":"MIT"}}