{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"pay-button","type":"registry:component","title":"Pay button","description":"The button at the end of a checkout, through the whole wait: the card being charged, a line of light while it pays, and a receipt that slides out from under it.","author":"Hairline UI","dependencies":["lucide-react"],"registryDependencies":["https://hairlineui.com/r/number-roll.json?as=dependency"],"files":[{"path":"registry/pay-button.tsx","type":"registry:component","content":"// Hairline UI · pay-button · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n\"use client\";\n\n/* ─────────────────────────────────────────────────────────\n * PAY BUTTON: the wait between tapping Pay and knowing\n *\n *   pay       \"Pay $48.00\"; the amount rolls when the total\n *             changes, so a coupon or a quantity reads at once\n *   paying    the label turns into the card being charged\n *             (\"Paying with Visa •• 4242\") and a line of light\n *             runs round the button while your onPay runs\n *   paid      the line closes into a ring, the button turns\n *             green with a check, and a receipt slides out from\n *             under it: the reference (with Copy), the card and\n *             the time\n *   declined  the button shakes once and says \"Try again\"; the\n *             reason slides out of the same slot. Pressing again\n *             tucks it back in and tries again\n *\n * One line in your app: <PayButton amount={48} method={{ brand,\n * last4 }} onPay={() => api.pay(...)} />. Resolve with\n * { reference } to show it on the receipt; throw an Error to\n * say why not. It stays paid until it is remounted.\n * ───────────────────────────────────────────────────────── */\n\nimport * as React from \"react\";\nimport { Check, Copy, RotateCcw } from \"lucide-react\";\nimport { NumberRoll } from \"./number-roll\";\nimport { EASE_OUT, INTERACTION_FOCUS, INTERACTION_PRESS } from \"./ui-interaction-motion\";\nimport { playSound } from \"./ui-sounds\";\n\nexport interface PayMethod {\n  /** \"Visa\", \"Mastercard\", \"Amex\", \"Apple Pay\"… */\n  brand: string;\n  /** The card's last four digits, if it has them. */\n  last4?: string;\n}\n\nexport type PayButtonStatus = \"idle\" | \"paying\" | \"paid\" | \"error\";\n\nexport interface PayButtonProps {\n  /** The total, written on the button with `format`. It rolls when it changes. */\n  amount: number;\n  /** The card or wallet being charged, shown while paying and on the receipt. */\n  method?: PayMethod;\n  /** Your payment. Resolve (with `{ reference }` to show it) when it went through; throw an Error to say why not. */\n  onPay: () => unknown | Promise<unknown>;\n  format?: Intl.NumberFormatOptions;\n  locales?: string | string[];\n  /** The words. `pay` replaces the whole \"Pay $48.00\". */\n  labels?: Partial<Record<\"pay\" | \"paying\" | \"paid\" | \"retry\" | \"failed\", string>>;\n  disabled?: boolean;\n  /** Soft synthesised sounds when it goes through or fails. */\n  sound?: boolean;\n  onStatusChange?: (status: PayButtonStatus) => void;\n  className?: string;\n}\n\nconst USD: Intl.NumberFormatOptions = { style: \"currency\", currency: \"USD\" };\nconst MIN_PENDING = 700; // the line goes round at least this long, so \"paying\" is seen\nconst LAP = 1400; // one lap of the line, ms\nconst TUCK = 14; // how far the receipt's top sits behind the button\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);\nconst subscribeNothing = () => () => {};\nconst useHydrated = () => React.useSyncExternalStore(subscribeNothing, () => true, () => false);\n\ntype Phase = \"idle\" | \"paying\" | \"paid\" | \"failed\";\ntype Note = { kind: \"receipt\"; reference?: string; at: Date } | { kind: \"error\"; message: string };\n\n// The order lines come in: a later one rises from below, an earlier one comes back down from above.\nconst LINES = [\"pay\", \"retry\", \"paying\", \"paid\"] as const;\ntype Line = (typeof LINES)[number];\n\nconst referenceOf = (result: unknown) => {\n  if (result && typeof result === \"object\" && \"reference\" in result) {\n    const ref = (result as { reference?: unknown }).reference;\n    if (typeof ref === \"string\" || typeof ref === \"number\") return String(ref);\n  }\n  return undefined;\n};\n\n/** A small card, drawn in the button's own colour. */\nfunction CardGlyph() {\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 22 16\" className=\"size-[22px] h-4 shrink-0\">\n      <rect x=\"0.75\" y=\"0.75\" width=\"20.5\" height=\"14.5\" rx=\"3\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" />\n      <path d=\"M1 5.25h20\" stroke=\"currentColor\" strokeWidth=\"1.5\" />\n      <rect x=\"3.5\" y=\"9.5\" width=\"5\" height=\"2.5\" rx=\"1\" fill=\"currentColor\" />\n    </svg>\n  );\n}\n\nexport function PayButton({\n  amount,\n  method,\n  onPay,\n  format = USD,\n  locales,\n  labels,\n  disabled = false,\n  sound = false,\n  onStatusChange,\n  className = \"\",\n}: PayButtonProps) {\n  const reduced = useReducedMotion();\n  const hydrated = useHydrated();\n  const locale = locales ?? (hydrated ? undefined : \"en-US\");\n  const money = new Intl.NumberFormat(locale, format).format(amount);\n  const card = method ? `${method.brand}${method.last4 ? ` •• ${method.last4}` : \"\"}` : \"\";\n  const cardSpoken = method ? `${method.brand}${method.last4 ? ` ending ${method.last4}` : \"\"}` : \"\";\n  const words = {\n    paying: method ? \"Paying with\" : \"Paying…\",\n    paid: \"Paid\",\n    retry: \"Try again\",\n    failed: \"The payment didn't go through.\",\n    ...labels,\n  };\n\n  const [phase, setPhase] = React.useState<Phase>(\"idle\");\n  const [note, setNote] = React.useState<Note | null>(null);\n  const [copied, setCopied] = React.useState(false);\n\n  const buttonRef = React.useRef<HTMLButtonElement>(null);\n  const headRef = React.useRef<SVGRectElement>(null);\n  const tailRef = React.useRef<SVGRectElement>(null);\n  const ringRef = React.useRef<SVGRectElement>(null);\n  const timers = React.useRef(new Set<ReturnType<typeof setTimeout>>());\n  const busy = React.useRef(false);\n  const latest = React.useRef({ onPay, sound, onStatusChange, failed: words.failed });\n  React.useLayoutEffect(() => {\n    latest.current = { onPay, sound, onStatusChange, failed: words.failed };\n  });\n\n  React.useEffect(() => {\n    const pending = timers.current;\n    return () => {\n      for (const id of pending) clearTimeout(id);\n      pending.clear();\n    };\n  }, []);\n  const later = (fn: () => void, ms: number) => {\n    const id = setTimeout(() => {\n      timers.current.delete(id);\n      fn();\n    }, ms);\n    timers.current.add(id);\n  };\n\n  const pay = async (event: React.MouseEvent<HTMLButtonElement>) => {\n    if (busy.current || phase === \"paid\" || disabled) return;\n    busy.current = true;\n    const started = event.timeStamp;\n    setPhase(\"paying\");\n    let outcome: Note;\n    try {\n      const result = await latest.current.onPay();\n      outcome = { kind: \"receipt\", reference: referenceOf(result), at: new Date() };\n    } catch (error) {\n      outcome = { kind: \"error\", message: error instanceof Error && error.message ? error.message : latest.current.failed };\n    }\n    later(() => {\n      busy.current = false;\n      setNote(outcome);\n      setPhase(outcome.kind === \"receipt\" ? \"paid\" : \"failed\");\n      if (latest.current.sound) playSound(outcome.kind === \"receipt\" ? \"success\" : \"error\", 0.4);\n    }, Math.max(0, started + MIN_PENDING - performance.now()));\n  };\n\n  // The line of light: a bright head and a faint tail, lapping the button while it pays.\n  React.useEffect(() => {\n    if (phase !== \"paying\" || reduced) return;\n    const timing: KeyframeAnimationOptions = { duration: LAP, iterations: Infinity, easing: \"linear\" };\n    const head = headRef.current?.animate([{ strokeDashoffset: 0 }, { strokeDashoffset: -100 }], timing);\n    const tail = tailRef.current?.animate([{ strokeDashoffset: 20 }, { strokeDashoffset: -80 }], timing);\n    return () => {\n      head?.cancel();\n      tail?.cancel();\n    };\n  }, [phase, reduced]);\n\n  // Paid: the line closes into a whole ring, which lets go of the button. Declined: one shake.\n  React.useEffect(() => {\n    if (reduced) return;\n    if (phase === \"paid\") {\n      const ring = ringRef.current?.animate(\n        [\n          { strokeDashoffset: 1, opacity: 1, transform: \"scale(1)\" },\n          { strokeDashoffset: 0, opacity: 1, transform: \"scale(1)\", offset: 0.45 },\n          { strokeDashoffset: 0, opacity: 0, transform: \"scale(1.04)\" },\n        ],\n        { duration: 1100, easing: EASE_OUT, fill: \"backwards\" },\n      );\n      return () => ring?.cancel();\n    }\n    if (phase === \"failed\") {\n      const shake = buttonRef.current?.animate(\n        [\n          { transform: \"translateX(0)\" },\n          { transform: \"translateX(-5px)\" },\n          { transform: \"translateX(4px)\" },\n          { transform: \"translateX(-2px)\" },\n          { transform: \"translateX(0)\" },\n        ],\n        { duration: 380, easing: \"ease-out\" },\n      );\n      return () => shake?.cancel();\n    }\n  }, [phase, reduced]);\n\n  const status: PayButtonStatus = phase === \"failed\" ? \"error\" : phase;\n  React.useEffect(() => {\n    latest.current.onStatusChange?.(status);\n  }, [status]);\n\n  const copy = () => {\n    if (note?.kind !== \"receipt\" || !note.reference) return;\n    try {\n      void navigator.clipboard?.writeText(note.reference).catch(() => {});\n    } catch {}\n    setCopied(true);\n    later(() => setCopied(false), 1600);\n  };\n\n  const line: Line = phase === \"paid\" ? \"paid\" : phase === \"paying\" ? \"paying\" : phase === \"failed\" ? \"retry\" : \"pay\";\n  const fade = (ms: number, delay = 0) => (reduced ? \"none\" : `opacity ${ms}ms ${EASE_OUT} ${delay}ms, transform ${ms + 120}ms ${EASE_OUT} ${delay}ms, filter ${ms}ms ${EASE_OUT} ${delay}ms`);\n  const lineStyle = (name: Line): React.CSSProperties => {\n    const on = name === line;\n    const offset = LINES.indexOf(name) < LINES.indexOf(line) ? -8 : 8;\n    return {\n      opacity: on ? 1 : 0,\n      transform: on ? \"none\" : `translate3d(0,${offset}px,0)`,\n      filter: on ? \"blur(0px)\" : \"blur(4px)\",\n      transition: on ? fade(300, 90) : fade(160),\n    };\n  };\n\n  const paid = phase === \"paid\";\n  const open = phase === \"paid\" || phase === \"failed\";\n  const slide = reduced ? \"none\" : open ? `520ms ${EASE_OUT} 160ms` : `300ms ${EASE_OUT}`;\n  const time =\n    note?.kind === \"receipt\" ? new Intl.DateTimeFormat(locale, { hour: \"numeric\", minute: \"2-digit\" }).format(note.at) : \"\";\n  const announce =\n    phase === \"paying\"\n      ? `Paying ${money}${cardSpoken ? ` with ${cardSpoken}` : \"\"}`\n      : phase === \"paid\"\n        ? `Paid ${money}.${note?.kind === \"receipt\" && note.reference ? ` Reference ${note.reference}.` : \"\"}`\n        : phase === \"failed\" && note?.kind === \"error\"\n          ? note.message\n          : \"\";\n  const label = (name: Line) => `absolute inset-0 flex items-center justify-center gap-2 px-5 ${name === line ? \"\" : \"pointer-events-none\"}`;\n\n  return (\n    <div role=\"group\" aria-label={`Pay ${money}`} className={`w-full min-w-[248px] ${className}`}>\n      <div className=\"relative\">\n        {/* The line of light, 4px outside the button, and the ring it closes into. */}\n        <svg\n          aria-hidden=\"true\"\n          className=\"pointer-events-none absolute -left-1 -top-1 h-[calc(100%+8px)] w-[calc(100%+8px)] overflow-visible\"\n          style={{ opacity: phase === \"paying\" ? 1 : 0, transition: reduced ? \"none\" : `opacity 220ms ${EASE_OUT}` }}\n        >\n          <rect\n            ref={tailRef}\n            width=\"100%\"\n            height=\"100%\"\n            rx=\"28\"\n            fill=\"none\"\n            stroke=\"var(--primary)\"\n            strokeOpacity={reduced ? 0.35 : 0.28}\n            strokeWidth=\"2\"\n            pathLength={100}\n            strokeDasharray={reduced ? \"100 0\" : \"28 72\"}\n            strokeDashoffset={20}\n          />\n          {!reduced ? (\n            <rect ref={headRef} width=\"100%\" height=\"100%\" rx=\"28\" fill=\"none\" stroke=\"var(--primary)\" strokeWidth=\"2\" strokeLinecap=\"round\" pathLength={100} strokeDasharray=\"8 92\" />\n          ) : null}\n        </svg>\n        <svg aria-hidden=\"true\" className=\"pointer-events-none absolute -left-1 -top-1 h-[calc(100%+8px)] w-[calc(100%+8px)] overflow-visible\">\n          <rect\n            ref={ringRef}\n            width=\"100%\"\n            height=\"100%\"\n            rx=\"28\"\n            fill=\"none\"\n            className=\"stroke-emerald-500\"\n            strokeWidth=\"2\"\n            pathLength={1}\n            strokeDasharray=\"1 1\"\n            style={{ opacity: 0, transformOrigin: \"center\", transformBox: \"fill-box\" }}\n          />\n        </svg>\n\n        <button\n          ref={buttonRef}\n          type=\"button\"\n          disabled={disabled}\n          aria-disabled={phase === \"paying\" || paid || undefined}\n          aria-label={paid ? `Paid ${money}` : phase === \"failed\" ? `${words.retry}: pay ${money}` : `Pay ${money}`}\n          onClick={pay}\n          className={`relative z-[1] block h-12 w-full cursor-pointer select-none overflow-clip rounded-full text-[15px] font-medium tracking-[-0.01em] disabled:cursor-default disabled:opacity-50 aria-disabled:cursor-default aria-disabled:active:scale-100 ${INTERACTION_PRESS} ${INTERACTION_FOCUS} ${\n            paid ? \"bg-emerald-600 text-white\" : \"bg-primary text-primary-foreground\"\n          }`}\n        >\n          <span aria-hidden=\"true\" className={label(\"pay\")} style={lineStyle(\"pay\")}>\n            {labels?.pay ?? (\n              <span className=\"truncate\">\n                Pay <NumberRoll value={amount} format={format} locales={locales} className=\"tabular-nums\" />\n              </span>\n            )}\n          </span>\n          <span aria-hidden=\"true\" className={label(\"retry\")} style={lineStyle(\"retry\")}>\n            <RotateCcw className=\"size-4 shrink-0\" strokeWidth={2.25} />\n            <span className=\"truncate\">{words.retry}</span>\n          </span>\n          <span aria-hidden=\"true\" className={label(\"paying\")} style={lineStyle(\"paying\")}>\n            {method ? <CardGlyph /> : null}\n            <span className=\"truncate\">\n              <span className=\"opacity-75\">{words.paying}</span>\n              {card ? <span> {card}</span> : null}\n            </span>\n          </span>\n          <span aria-hidden=\"true\" className={label(\"paid\")} style={lineStyle(\"paid\")}>\n            <svg viewBox=\"0 0 16 16\" className=\"size-4 shrink-0\">\n              <path\n                d=\"m3.2 8.4 3 3 6.6-6.8\"\n                fill=\"none\"\n                stroke=\"currentColor\"\n                strokeWidth=\"2.2\"\n                strokeLinecap=\"round\"\n                strokeLinejoin=\"round\"\n                pathLength={1}\n                style={{ strokeDasharray: 1, strokeDashoffset: paid ? 0 : 1, transition: reduced ? \"none\" : `stroke-dashoffset 340ms ease-out 200ms` }}\n              />\n            </svg>\n            <span className=\"truncate\">\n              {words.paid} <span className=\"tabular-nums\">{money}</span>\n            </span>\n          </span>\n        </button>\n      </div>\n\n      {/* The slot under the button: the receipt, or the reason it was declined. Its top stays tucked behind the button. */}\n      <div\n        className=\"grid\"\n        inert={!open}\n        style={{ gridTemplateRows: open ? \"1fr\" : \"0fr\", marginTop: open ? -TUCK : 0, transition: slide === \"none\" ? \"none\" : `grid-template-rows ${slide}, margin-top ${slide}` }}\n      >\n        <div className=\"min-h-0 overflow-clip px-3\">\n          <div\n            className=\"rounded-b-[16px] bg-background px-3.5 pb-3 text-[13px] shadow-[inset_0_0_0_1px_var(--border)]\"\n            style={{ paddingTop: TUCK + 10, transform: open ? \"none\" : \"translate3d(0,-100%,0)\", transition: slide === \"none\" ? \"none\" : `transform ${slide}` }}\n          >\n            {note?.kind === \"receipt\" ? (\n              <dl className=\"grid gap-1.5\">\n                {note.reference ? (\n                  <div className=\"flex h-6 items-center justify-between gap-3\">\n                    <dt className=\"text-muted-foreground\">Reference</dt>\n                    <dd className=\"flex min-w-0 items-center gap-1\">\n                      <span className=\"truncate font-mono text-[12.5px] text-foreground\">{note.reference}</span>\n                      <button\n                        type=\"button\"\n                        onClick={copy}\n                        aria-label={copied ? \"Copied\" : \"Copy reference\"}\n                        className={`relative -mr-1.5 flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-full text-muted-foreground hover:bg-accent hover:text-foreground ${INTERACTION_PRESS} ${INTERACTION_FOCUS}`}\n                      >\n                        <Copy\n                          aria-hidden=\"true\"\n                          className=\"absolute size-3.5\"\n                          style={{\n                            opacity: copied ? 0 : 1,\n                            transform: copied ? \"scale(0.6)\" : \"none\",\n                            filter: copied ? \"blur(3px)\" : \"blur(0px)\",\n                            transition: reduced ? \"none\" : `opacity 200ms ${EASE_OUT}, transform 260ms ${EASE_OUT}, filter 200ms ${EASE_OUT}`,\n                          }}\n                        />\n                        <Check\n                          aria-hidden=\"true\"\n                          className=\"absolute size-3.5 text-emerald-600 dark:text-emerald-400\"\n                          strokeWidth={2.5}\n                          style={{\n                            opacity: copied ? 1 : 0,\n                            transform: copied ? \"none\" : \"scale(0.6)\",\n                            filter: copied ? \"blur(0px)\" : \"blur(3px)\",\n                            transition: reduced ? \"none\" : `opacity 200ms ${EASE_OUT}, transform 260ms ${EASE_OUT}, filter 200ms ${EASE_OUT}`,\n                          }}\n                        />\n                      </button>\n                    </dd>\n                  </div>\n                ) : null}\n                <div className=\"flex h-6 items-center justify-between gap-3\">\n                  <dt className=\"text-muted-foreground\">{card ? \"Charged to\" : \"Paid at\"}</dt>\n                  <dd className=\"truncate tabular-nums text-foreground\">{card ? `${card} · ${time}` : time}</dd>\n                </div>\n              </dl>\n            ) : note?.kind === \"error\" ? (\n              <p className=\"flex min-h-6 items-center gap-2 text-red-600 dark:text-red-400\">\n                <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" className=\"size-4 shrink-0\">\n                  <circle cx=\"8\" cy=\"8\" r=\"6.5\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" />\n                  <path d=\"M8 4.75v3.75M8 11.1v.15\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" />\n                </svg>\n                <span className=\"min-w-0\">{note.message}</span>\n              </p>\n            ) : null}\n          </div>\n        </div>\n      </div>\n\n      <span role=\"status\" className=\"sr-only\">\n        {announce}\n      </span>\n    </div>\n  );\n}\n\nexport default PayButton;\n"},{"path":"registry/ui-interaction-motion.ts","type":"registry:component","content":"// Hairline UI · pay-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 · pay-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":{"@keyframes ui-col-in":{"from":{"max-width":"0","opacity":"0"},"to":{"max-width":"1em","opacity":"1"}},"@keyframes ui-col-out":{"from":{"max-width":"1em","opacity":"1"},"to":{"max-width":"0","opacity":"0"}}},"docs":"Docs and live preview: https://hairlineui.com/ui/pay-button. MIT licensed: https://hairlineui.com/license#components","meta":{"license":"MIT"}}