{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"slide-to-send","type":"registry:component","title":"Slide to send","description":"The confirm step of a payment: carry the thumb to the person you are paying and the money drains into their avatar.","author":"Hairline UI","dependencies":["lucide-react"],"files":[{"path":"registry/slide-to-send.tsx","type":"registry:component","content":"// Hairline UI · slide-to-send · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n\"use client\";\n\n/* ─────────────────────────────────────────────────────────\n * SLIDE TO SEND: the confirm step of a payment\n *\n * The control at the foot of a send-money or checkout sheet.\n * The person you are paying sits at the end of the track. You\n * carry the thumb to them and the track fills behind it; the\n * words under the fill turn white so they stay readable. Let go\n * early and it springs home. Let go against their photo and the\n * fill drains into it: its tail runs up the track and the money\n * is gone into their avatar, which gives a little as it takes\n * it. A badge on the avatar turns while your `onSend` runs and\n * becomes a check when it resolves; the label says \"Sent to\n * Priya\" and stays. If it throws, the money comes back out of\n * the avatar and slides home, and the reason takes the label.\n *\n * One line in your app: <SlideToSend amount={240} to={{ name,\n * avatar }} onSend={() => api.transfer(...)} />. Your transfer\n * call, your errors; nothing else to wire. Remount it (a new\n * `key`) to take another payment.\n * ───────────────────────────────────────────────────────── */\n\nimport * as React from \"react\";\nimport { ArrowRight } from \"lucide-react\";\nimport {\n  EASE_OUT,\n  EASE_THROW,\n  INTERACTION_FOCUS,\n  createSpring,\n  projectInertia,\n  releaseVelocity,\n  rubberBand,\n  samplePointer,\n  softenVelocity,\n  type PointerSample,\n  type Spring,\n} from \"./ui-interaction-motion\";\nimport { playSound } from \"./ui-sounds\";\n\nexport interface SlideRecipient {\n  /** Full name; the first name goes in the labels. */\n  name: string;\n  /** Photo URL. Without one, their initials. */\n  avatar?: string;\n}\n\nexport type SlideToSendStatus = \"idle\" | \"sending\" | \"sent\" | \"error\";\n\nexport interface SlideToSendProps {\n  /** The amount being sent, written in the label with `format`. */\n  amount: number;\n  /** Who it goes to, shown at the end of the track. */\n  to: SlideRecipient;\n  /** Your transfer. Resolve when it went through; throw (an Error's message is shown) to give the money back. */\n  onSend: () => unknown | Promise<unknown>;\n  format?: Intl.NumberFormatOptions;\n  locales?: string | string[];\n  /** The words. `slide` replaces the whole \"Slide to send $240.00\". */\n  labels?: Partial<Record<\"slide\" | \"sending\" | \"sent\" | \"failed\", string>>;\n  disabled?: boolean;\n  /** Soft synthesised sounds as it reaches, lands, and goes through or fails. */\n  sound?: boolean;\n  onStatusChange?: (status: SlideToSendStatus) => void;\n  className?: string;\n}\n\nconst USD: Intl.NumberFormatOptions = { style: \"currency\", currency: \"USD\" };\n// Geometry: a 56px track, 4px of room all round, a 48px thumb and a 48px avatar.\nconst PAD = 4;\nconst KNOB = 48;\nconst GAP = 4; // the thumb stops this far short of the avatar\nconst COMMIT_FROM = 0.6; // a throw only counts from past this share of the track\nconst MIN_PENDING = 560; // the badge turns at least this long, so \"sending\" is seen\nconst FOLLOW = { stiffness: 420, damping: 40 }; // home and the nudge: quick, no bounce\nconst HAND_OVER = { stiffness: 230, damping: 30 }; // the thumb into the avatar and back out\nconst DRAIN = { stiffness: 170, damping: 26 }; // the fill's tail running up after it\n\nconst clamp = (n: number, lo: number, hi: number) => (n < lo ? lo : n > hi ? hi : n);\nconst smooth = (t: number) => t * t * (3 - 2 * t);\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\n// A light that sweeps the way you slide. A mask, not a text clip.\nconst SHEEN =\n  \"[mask-image:linear-gradient(90deg,rgb(0_0_0/0.5)_35%,#000_50%,rgb(0_0_0/0.5)_65%)] [mask-size:200%_100%] animate-[ui-sheen_2s_linear_infinite] motion-reduce:animate-none motion-reduce:[mask-image:none]\";\n\nfunction buzz(ms: number) {\n  try {\n    navigator.vibrate?.(ms);\n  } catch {}\n}\n\ntype Phase = \"idle\" | \"handing\" | \"sending\" | \"sent\";\ntype Result = { ok: boolean; message?: string };\ntype Springs = { head: Spring; tail: Spring; take: Spring };\n\n// The order lines come in: a later one rises from below, an earlier one comes back down from above.\nconst LINES = [\"slide\", \"failed\", \"sending\", \"sent\"] as const;\ntype Line = (typeof LINES)[number];\n\nexport function SlideToSend({\n  amount,\n  to,\n  onSend,\n  format = USD,\n  locales,\n  labels,\n  disabled = false,\n  sound = false,\n  onStatusChange,\n  className = \"\",\n}: SlideToSendProps) {\n  const reduced = useReducedMotion();\n  const hydrated = useHydrated();\n  const money = new Intl.NumberFormat(locales ?? (hydrated ? undefined : \"en-US\"), format).format(amount);\n  const first = to.name.trim().split(/\\s+/)[0] || to.name;\n  const initials = to.name.trim().split(/\\s+/).slice(0, 2).map((part) => part[0]?.toUpperCase() ?? \"\").join(\"\");\n  const words = { sending: `Sending to ${first}`, sent: `Sent to ${first}`, failed: \"Couldn't send. Try again.\", ...labels };\n  const slideText = labels?.slide;\n\n  const hintId = React.useId();\n  const [phase, setPhase] = React.useState<Phase>(\"idle\");\n  const [message, setMessage] = React.useState<string | null>(null);\n\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const trackRef = React.useRef<HTMLDivElement>(null);\n  const thumbRef = React.useRef<HTMLButtonElement>(null);\n  const windowRef = React.useRef<HTMLDivElement>(null);\n  const barRef = React.useRef<HTMLDivElement>(null);\n  const inkRef = React.useRef<HTMLDivElement>(null);\n  const hintRef = React.useRef<HTMLSpanElement>(null);\n  const avatarRef = React.useRef<HTMLSpanElement>(null);\n\n  const width = React.useRef(0);\n  const run = React.useRef({ committing: false, caught: false, caughtAt: 0, result: null as Result | null, reach: false });\n  const drag = React.useRef<{ id: number; start: number; samples: PointerSample[] } | null>(null);\n  const timers = React.useRef(new Set<ReturnType<typeof setTimeout>>());\n  const paintRef = React.useRef<() => void>(() => {});\n  const latest = React.useRef({ onSend, sound, reduced, onStatusChange, failed: words.failed });\n  React.useLayoutEffect(() => {\n    latest.current = { onSend, sound, reduced, onStatusChange, failed: words.failed };\n  });\n\n  // Three springs draw everything: the thumb (the fill's head), the fill's tail, and the avatar's give.\n  // Made on first use, from an event or an effect, never while rendering.\n  const springsRef = React.useRef<Springs | null>(null);\n  const getSprings = React.useCallback(() => {\n    if (!springsRef.current) {\n      const paint = () => paintRef.current();\n      springsRef.current = {\n        head: createSpring(0, FOLLOW, paint, 0.05),\n        tail: createSpring(0, DRAIN, paint, 0.05),\n        take: createSpring(0, { stiffness: 560, damping: 16 }, paint, 0.0005),\n      };\n    }\n    return springsRef.current;\n  }, []);\n\n  const later = React.useCallback((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  React.useEffect(() => {\n    const all = timers.current;\n    return () => {\n      const springs = springsRef.current;\n      springs?.head.stop();\n      springs?.tail.stop();\n      springs?.take.stop();\n      springsRef.current = null;\n      all.forEach(clearTimeout);\n      all.clear();\n    };\n  }, []);\n\n  const finish = React.useCallback(() => {\n    const state = run.current;\n    const result = state.result;\n    if (!result) return;\n    const withSound = latest.current.sound;\n    if (result.ok) {\n      setPhase(\"sent\");\n      if (withSound) playSound(\"success\", 0.45);\n      buzz(12);\n      return;\n    }\n    // It didn't go: the money comes back out of their avatar and slides home, and the reason takes the label.\n    state.committing = false;\n    state.caught = false;\n    state.result = null;\n    setPhase(\"idle\");\n    setMessage(result.message || latest.current.failed);\n    const springs = getSprings();\n    springs.head.configure(HAND_OVER);\n    springs.head.set(0);\n    springs.tail.configure(DRAIN);\n    springs.tail.set(0);\n    avatarRef.current?.animate(\n      [{ translate: \"0 0\" }, { translate: \"-4px 0\" }, { translate: \"4px 0\" }, { translate: \"-3px 0\" }, { translate: \"2px 0\" }, { translate: \"0 0\" }],\n      { duration: latest.current.reduced ? 0 : 380, easing: \"ease-out\" },\n    );\n    if (withSound) playSound(\"error\", 0.45);\n    later(() => setMessage(null), 3600);\n  }, [later, getSprings]);\n\n  const settle = React.useCallback(() => {\n    const state = run.current;\n    if (!state.caught || !state.result) return;\n    later(finish, Math.max(0, state.caughtAt + MIN_PENDING - performance.now()));\n  }, [finish, later]);\n\n  React.useLayoutEffect(() => {\n    paintRef.current = () => {\n      const W = width.current;\n      const thumb = thumbRef.current, win = windowRef.current, bar = barRef.current, ink = inkRef.current, avatar = avatarRef.current;\n      if (!W || !thumb || !win || !bar || !ink || !avatar) return;\n      const springs = getSprings();\n      const inner = W - PAD * 2;\n      const max = Math.max(1, inner - KNOB * 2 - GAP); // the thumb against the avatar\n      const land = inner - KNOB; // the thumb right under the avatar\n      const h = springs.head.get();\n      const t = Math.max(0, Math.min(springs.tail.get(), h)); // the tail never passes the head\n      const p = clamp(h / max, 0, 1);\n      const k = clamp((h - max) / (land - max), 0, 1); // how far it has gone into the avatar\n      const gone = 1 - smooth(clamp((k - 0.35) / 0.65, 0, 1));\n      thumb.style.transform = `translate3d(${h.toFixed(2)}px,0,0) scale(${(1 - 0.35 * k).toFixed(4)})`;\n      thumb.style.opacity = gone.toFixed(3);\n      // The fill is a pill whose right end is the thumb and whose left end is the tail: a window that\n      // moves with the tail, a bar inside it that moves with the head, and the white words inside the\n      // bar held still on the track. Three transforms, nothing re-laid out.\n      const end = Math.min(h, land) + KNOB - inner;\n      win.style.transform = `translate3d(${t.toFixed(2)}px,0,0)`;\n      // Once the tail is under the avatar there is nothing left to see.\n      win.style.opacity = clamp((land - t) / 8, 0, 1).toFixed(3);\n      bar.style.transform = `translate3d(${(end - t).toFixed(2)}px,0,0)`;\n      ink.style.transform = `translate3d(${(-end).toFixed(2)}px,0,0)`;\n      // The grey words ahead of the thumb step back as it comes, so only the white ones on the fill are read.\n      if (hintRef.current) hintRef.current.style.opacity = (1 - smooth(clamp(p / 0.55, 0, 1))).toFixed(3);\n      // In reach: the avatar leans in to take it.\n      const reach = smooth(clamp((p - 0.7) / 0.3, 0, 1)) * (1 - k);\n      avatar.style.transform = `scale(${(1 + 0.06 * reach + springs.take.get()).toFixed(4)})`;\n\n      const state = run.current;\n      if (state.committing && !state.caught && k > 0.75) {\n        state.caught = true;\n        state.caughtAt = performance.now();\n        if (!latest.current.reduced) springs.take.push(1.6);\n        if (latest.current.sound) playSound(\"drop\", 0.4);\n        buzz(10);\n        if (thumb === document.activeElement) rootRef.current?.focus({ preventScroll: true });\n        setPhase(\"sending\");\n        settle();\n      }\n    };\n    paintRef.current();\n  });\n\n  // The track's width, for the travel and the landing spot.\n  React.useLayoutEffect(() => {\n    const track = trackRef.current;\n    if (!track) return;\n    const measure = () => {\n      width.current = track.clientWidth;\n      paintRef.current();\n    };\n    measure();\n    const observer = new ResizeObserver(measure);\n    observer.observe(track);\n    return () => observer.disconnect();\n  }, []);\n\n  const commit = (velocity: number) => {\n    const state = run.current;\n    if (state.committing) return;\n    const inner = width.current - PAD * 2;\n    state.committing = true;\n    state.caught = false;\n    state.result = null;\n    setMessage(null);\n    setPhase(\"handing\");\n    // The transfer starts the moment you let go; the badge turns once the money is in their hands.\n    new Promise((resolve) => resolve(latest.current.onSend())).then(\n      () => {\n        state.result = { ok: true };\n        settle();\n      },\n      (error: unknown) => {\n        state.result = { ok: false, message: error instanceof Error ? error.message : undefined };\n        settle();\n      },\n    );\n    const springs = getSprings();\n    if (latest.current.reduced) {\n      springs.head.jump(inner - KNOB);\n      springs.tail.jump(inner - KNOB);\n      return;\n    }\n    springs.head.configure(HAND_OVER);\n    springs.head.push(Math.max(0, velocity));\n    springs.head.set(inner - KNOB);\n    springs.tail.configure(DRAIN);\n    springs.tail.set(inner - KNOB);\n  };\n\n  const idle = phase === \"idle\" && !disabled;\n\n  const onPointerDown = (event: React.PointerEvent<HTMLButtonElement>) => {\n    if (!idle || run.current.committing || event.button !== 0 || !event.isPrimary) return;\n    event.currentTarget.setPointerCapture(event.pointerId);\n    const springs = getSprings();\n    springs.head.stop();\n    springs.head.configure(FOLLOW);\n    springs.tail.jump(0);\n    drag.current = { id: event.pointerId, start: event.clientX - springs.head.get(), samples: [] };\n    samplePointer(drag.current.samples, event.clientX, event.timeStamp);\n    setMessage(null);\n  };\n\n  const onPointerMove = (event: React.PointerEvent<HTMLButtonElement>) => {\n    const current = drag.current;\n    if (!current || current.id !== event.pointerId) return;\n    const inner = width.current - PAD * 2;\n    const max = Math.max(1, inner - KNOB * 2 - GAP);\n    const land = inner - KNOB;\n    const raw = event.clientX - current.start;\n    // Free along the track and on under the avatar; past the start it gives only a few pixels.\n    const value = raw < 0 ? rubberBand(raw, 6) : raw > land ? land + rubberBand(raw - land, 40) : raw;\n    samplePointer(current.samples, event.clientX, event.timeStamp);\n    getSprings().head.jump(value);\n    const state = run.current;\n    if (!state.reach && value >= max * 0.985) {\n      state.reach = true;\n      if (latest.current.sound) playSound(\"tick\", 0.4);\n      buzz(6);\n    } else if (state.reach && value < max * 0.9) state.reach = false;\n  };\n\n  const release = (event: React.PointerEvent<HTMLButtonElement>) => {\n    const current = drag.current;\n    if (!current || current.id !== event.pointerId) return;\n    drag.current = null;\n    run.current.reach = false;\n    const max = Math.max(1, width.current - PAD * 2 - KNOB * 2 - GAP);\n    const x = getSprings().head.get();\n    const velocity = event.type === \"pointerup\" ? releaseVelocity(current.samples, event.timeStamp) : 0; // px per ms\n    if (event.type === \"pointerup\" && (x >= max * 0.97 || (x >= max * COMMIT_FROM && projectInertia(x, velocity) >= max * 0.97))) {\n      commit(velocity * 1000);\n      return;\n    }\n    // Let go early: home, keeping the speed it was let go with, softened so it doesn't slam into the start.\n    if (latest.current.reduced) {\n      getSprings().head.jump(0);\n      return;\n    }\n    getSprings().head.push(softenVelocity(velocity * 1000, x));\n    getSprings().head.set(0);\n  };\n\n  const onKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {\n    if (event.key === \"Escape\" && drag.current) {\n      drag.current = null;\n      getSprings().head.set(0);\n      return;\n    }\n    if ((event.key === \"Enter\" || event.key === \" \") && idle && !event.repeat) {\n      event.preventDefault();\n      commit(0);\n    }\n  };\n\n  // A tap on the track instead of the thumb: the thumb hops toward the avatar and back, showing the way.\n  const nudge = (event: React.PointerEvent<HTMLDivElement>) => {\n    if (!idle || run.current.committing || latest.current.reduced) return;\n    if (thumbRef.current?.contains(event.target as Node)) return;\n    const head = getSprings().head;\n    head.configure(FOLLOW);\n    head.push(560);\n    head.set(0);\n  };\n\n  const status: SlideToSendStatus = phase === \"sending\" || phase === \"handing\" ? \"sending\" : phase === \"sent\" ? \"sent\" : message ? \"error\" : \"idle\";\n  React.useEffect(() => {\n    latest.current.onStatusChange?.(status);\n  }, [status]);\n\n  const line: Line = phase === \"sent\" ? \"sent\" : phase === \"sending\" || phase === \"handing\" ? \"sending\" : message ? \"failed\" : \"slide\";\n  const announce = phase === \"sending\" ? words.sending : phase === \"sent\" ? `${words.sent}, ${money}` : (message ?? \"\");\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  // A line that is showing; the others wait below (later states) or above (earlier ones), blurred.\n  const lineStyle = (name: Line): React.CSSProperties => {\n    const on = name === line;\n    const offset = LINES.indexOf(name) < LINES.indexOf(line) ? -6 : 6;\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  const slideWords = slideText ?? (\n    <>\n      Slide to send <span className=\"font-semibold tabular-nums\">{money}</span>\n    </>\n  );\n  const badge = phase === \"sending\" || phase === \"sent\";\n  const sent = phase === \"sent\";\n\n  return (\n    <div\n      ref={rootRef}\n      tabIndex={-1}\n      role=\"group\"\n      aria-label={`Send ${money} to ${to.name}`}\n      className={`w-full outline-none ${disabled ? \"opacity-50\" : \"\"} ${className}`}\n    >\n      <div\n        ref={trackRef}\n        onPointerDown={nudge}\n        className=\"relative h-14 w-full min-w-[248px] rounded-full bg-background shadow-[inset_0_0_0_1px_var(--border)]\"\n      >\n        {/* The words, under the fill. The slide line sits between the thumb and the avatar; the others take the whole track left of the avatar. */}\n        <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 text-[14px] font-medium tracking-[-0.01em]\">\n          <span className=\"absolute inset-y-0 flex items-center justify-center\" style={{ left: PAD + KNOB, right: PAD + KNOB, ...lineStyle(\"slide\") }}>\n            <span ref={hintRef} className=\"min-w-0\">\n              <span className={`block truncate px-3 text-foreground ${SHEEN}`}>{slideWords}</span>\n            </span>\n          </span>\n          <span className=\"absolute inset-y-0 flex items-center justify-center\" style={{ left: PAD + KNOB, right: PAD + KNOB, ...lineStyle(\"failed\") }}>\n            <span className=\"truncate px-3 text-red-600 dark:text-red-400\">{message ?? words.failed}</span>\n          </span>\n          <span className=\"absolute inset-y-0 flex items-center justify-center\" style={{ left: PAD, right: PAD + KNOB, ...lineStyle(\"sending\") }}>\n            <span className={`truncate px-4 text-foreground ${SHEEN}`}>{words.sending}</span>\n          </span>\n          <span className=\"absolute inset-y-0 flex items-center justify-center\" style={{ left: PAD, right: PAD + KNOB, ...lineStyle(\"sent\") }}>\n            <span className=\"truncate px-4 text-foreground\">{words.sent}</span>\n          </span>\n        </div>\n\n        {/* The fill: a window that follows the tail, a bar inside that follows the thumb, the words in white inside the bar. */}\n        <div ref={windowRef} aria-hidden=\"true\" className=\"pointer-events-none absolute inset-1 overflow-clip rounded-full will-change-transform\">\n          <div ref={barRef} className=\"absolute inset-0 overflow-clip rounded-full bg-primary will-change-transform\" style={{ transform: \"translate3d(-100%,0,0)\" }}>\n            <div ref={inkRef} className=\"absolute inset-0 text-[14px] font-medium tracking-[-0.01em] text-primary-foreground will-change-transform\">\n              <span className=\"absolute inset-y-0 flex items-center justify-center\" style={{ left: KNOB, right: KNOB, opacity: line === \"slide\" ? 1 : 0 }}>\n                <span className=\"truncate px-3\">{slideWords}</span>\n              </span>\n            </div>\n          </div>\n        </div>\n\n        <button\n          ref={thumbRef}\n          type=\"button\"\n          disabled={disabled}\n          tabIndex={idle ? undefined : -1}\n          aria-disabled={!idle || undefined}\n          aria-label={`Slide to send ${money} to ${to.name}`}\n          aria-describedby={hintId}\n          onPointerDown={onPointerDown}\n          onPointerMove={onPointerMove}\n          onPointerUp={release}\n          onPointerCancel={release}\n          onLostPointerCapture={release}\n          onKeyDown={onKeyDown}\n          onClick={(event) => event.preventDefault()}\n          className={`absolute left-1 top-1 z-[1] flex size-12 cursor-grab touch-none select-none items-center justify-center rounded-full bg-primary text-primary-foreground will-change-transform active:cursor-grabbing disabled:cursor-default aria-disabled:cursor-default ${INTERACTION_FOCUS}`}\n        >\n          <ArrowRight aria-hidden=\"true\" className=\"size-[18px]\" strokeWidth={2.25} />\n        </button>\n\n        {/* The person. Above the thumb, so the money goes in under them. */}\n        <span ref={avatarRef} aria-hidden=\"true\" className=\"absolute right-1 top-1 z-[2] flex size-12\">\n          {to.avatar ? (\n            // eslint-disable-next-line @next/next/no-img-element\n            <img src={to.avatar} alt=\"\" draggable={false} className=\"size-12 select-none rounded-full bg-muted object-cover\" />\n          ) : (\n            <span className=\"flex size-12 items-center justify-center rounded-full bg-muted text-[14px] font-semibold text-foreground\">{initials}</span>\n          )}\n          <span className=\"pointer-events-none absolute inset-0 rounded-full shadow-[inset_0_0_0_1px_rgb(0_0_0/0.06)] dark:shadow-[inset_0_0_0_1px_rgb(255_255_255/0.08)]\" />\n          {/* The badge: turns while it sends, becomes a check when it went through. */}\n          <span\n            className={`absolute bottom-0 right-0 flex size-[18px] items-center justify-center rounded-full ring-2 ring-background ${sent ? \"bg-emerald-500\" : \"bg-background\"}`}\n            style={{\n              opacity: badge ? 1 : 0,\n              transform: badge ? \"none\" : \"scale(0.4)\",\n              transition: reduced ? \"none\" : `opacity 200ms ${EASE_OUT}, transform 420ms ${EASE_THROW}, background-color 240ms ${EASE_OUT}`,\n            }}\n          >\n            <svg\n              viewBox=\"0 0 18 18\"\n              className={`absolute inset-0 size-[18px] ${phase === \"sending\" && !reduced ? \"animate-spin\" : \"\"}`}\n              style={{ opacity: sent ? 0 : 1, filter: sent ? \"blur(2px)\" : \"blur(0px)\", transition: reduced ? \"none\" : `opacity 200ms ${EASE_OUT}, filter 200ms ${EASE_OUT}` }}\n            >\n              <circle cx=\"9\" cy=\"9\" r=\"6.5\" fill=\"none\" className=\"stroke-border\" strokeWidth=\"2\" />\n              <circle cx=\"9\" cy=\"9\" r=\"6.5\" fill=\"none\" stroke=\"var(--primary)\" strokeWidth=\"2\" strokeLinecap=\"round\" pathLength={1} strokeDasharray=\"0.3 1\" />\n            </svg>\n            <svg viewBox=\"0 0 12 12\" className=\"relative size-2.5 text-white\">\n              <path\n                d=\"m2.5 6.2 2.3 2.3 4.7-4.9\"\n                fill=\"none\"\n                stroke=\"currentColor\"\n                strokeWidth=\"1.9\"\n                strokeLinecap=\"round\"\n                strokeLinejoin=\"round\"\n                pathLength={1}\n                style={{ strokeDasharray: 1, strokeDashoffset: sent ? 0 : 1, transition: reduced ? \"none\" : `stroke-dashoffset 320ms ease-out 140ms` }}\n              />\n            </svg>\n          </span>\n        </span>\n      </div>\n      <span id={hintId} className=\"sr-only\">\n        Drag to {to.name}, or press Enter, to send.\n      </span>\n      <span role=\"status\" className=\"sr-only\">\n        {announce}\n      </span>\n    </div>\n  );\n}\n"},{"path":"registry/ui-interaction-motion.ts","type":"registry:component","content":"// Hairline UI · slide-to-send · 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 · slide-to-send · 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-sheen":{"from":{"mask-position":"150% 0"},"to":{"mask-position":"-50% 0"}}},"docs":"Docs and live preview: https://hairlineui.com/ui/slide-to-send. MIT licensed: https://hairlineui.com/license#components","meta":{"license":"MIT"}}