{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"stamp","type":"registry:component","title":"Stamp","description":"A definite “done” on any record, in ink: set it and the stamp lands with a press, the ink starts wet and dries into the grain, heavier where the pressure fell.","author":"Hairline UI","dependencies":[],"files":[{"path":"registry/stamp.tsx","type":"registry:component","content":"// Hairline UI · stamp · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n\"use client\";\n\nimport * as React from \"react\";\nimport { playSound } from \"./ui-sounds\";\n\n/* ─────────────────────────────────────────────────────────\n * STAMP: a definite \"done\" on any record, in ink\n *\n *   press     set on and the stamp comes down: the record gives a\n *             fraction at the moment of contact and the ink is\n *             left behind, a touch larger than it will dry\n *   wet       fresh ink is full and glossy, with a sheen across it\n *   dry       over about a second and a half it soaks in: it goes\n *             matte, the grain of the surface shows through as\n *             small voids, heavier on the side the pressure fell;\n *             no two stamps dry the same\n *   lift      unset on and the ink breaks up into the grain and is\n *             gone, the way a mark fades off paper\n *\n * Wrap anything: an invoice, a row, a card. The mark is drawn once\n * per word, colour and seed onto a small canvas over it, and the\n * frame loop runs only while it's pressing, drying or lifting.\n * ───────────────────────────────────────────────────────── */\n\nexport interface StampProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"children\"> {\n  children: React.ReactNode;\n  /** Stamped or not. */\n  on: boolean;\n  /** The word: \"Paid\", \"Approved\", \"Void\", \"Shipped\". */\n  mark: string;\n  /** A small second line: a date, a reference, who. */\n  detail?: string;\n  /** A framed rectangle, or a round seal with the detail running round its rim. */\n  shape?: \"rect\" | \"seal\";\n  /** Ink colour by meaning; or pass color for any CSS colour. */\n  tone?: \"success\" | \"danger\" | \"warning\" | \"primary\" | \"neutral\";\n  color?: string;\n  /** Where it lands on what it wraps. */\n  position?: \"center\" | \"top-right\" | \"bottom-right\";\n  /** Degrees; it lands a little crooked, like a hand stamp. */\n  rotate?: number;\n  /** 1 is a 30px word. */\n  size?: number;\n  /** Changes the grain, so two stamps on one page don't dry the same. Defaults to the word. */\n  seed?: string;\n  /** A soft knock as it lands, off by default. */\n  sound?: boolean;\n}\n\nconst FONT = 'ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", sans-serif';\nconst DRY_MS = 1500;\nconst LIFT_MS = 520;\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 inOut = (t: number) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2);\nconst outBack = (t: number) => 1 + 2.2 * (t - 1) ** 3 + 1.2 * (t - 1) ** 2;\n\ntype RGB = [number, number, number];\nlet probe: CanvasRenderingContext2D | null = null;\nfunction toRgb(color: string, fallback: RGB): RGB {\n  if (typeof document === \"undefined\" || !color) return fallback;\n  probe ??= document.createElement(\"canvas\").getContext(\"2d\", { willReadFrequently: true });\n  if (!probe) return fallback;\n  probe.clearRect(0, 0, 1, 1);\n  probe.fillStyle = \"#000\";\n  probe.fillStyle = color;\n  probe.fillRect(0, 0, 1, 1);\n  const [r, g, b, a] = probe.getImageData(0, 0, 1, 1).data;\n  return a === 0 ? fallback : [r, g, b];\n}\n\n/** A small seeded random: the same word dries the same way every time it's drawn. */\nfunction rng(seed: string) {\n  let h = 2166136261;\n  for (let i = 0; i < seed.length; i++) h = Math.imul(h ^ seed.charCodeAt(i), 16777619);\n  return () => {\n    h = Math.imul(h ^ (h >>> 15), 2246822507);\n    h = Math.imul(h ^ (h >>> 13), 3266489909);\n    h ^= h >>> 16;\n    return (h >>> 0) / 4294967296;\n  };\n}\n\n/** Smooth value noise on a grid of `cell` px, for the soak and the pressure. */\nfunction valueNoise(w: number, h: number, cell: number, rand: () => number) {\n  const gw = Math.ceil(w / cell) + 2;\n  const gh = Math.ceil(h / cell) + 2;\n  const g = new Float32Array(gw * gh).map(() => rand());\n  const out = new Float32Array(w * h);\n  for (let y = 0; y < h; y++) {\n    const fy = y / cell;\n    const y0 = Math.floor(fy);\n    const ty = fy - y0;\n    const sy = ty * ty * (3 - 2 * ty);\n    for (let x = 0; x < w; x++) {\n      const fx = x / cell;\n      const x0 = Math.floor(fx);\n      const tx = fx - x0;\n      const sx = tx * tx * (3 - 2 * tx);\n      const a = g[y0 * gw + x0];\n      const b = g[y0 * gw + x0 + 1];\n      const c = g[(y0 + 1) * gw + x0];\n      const d = g[(y0 + 1) * gw + x0 + 1];\n      out[y * w + x] = a + (b - a) * sx + (c - a) * sy + (a - b - c + d) * sx * sy;\n    }\n  }\n  return out;\n}\n\ntype Ink = { w: number; h: number; dpr: number; wet: HTMLCanvasElement; dry: HTMLCanvasElement; dryAlpha: Uint8ClampedArray; lift: Float32Array; color: RGB };\n\n/** Draws the mark once, then makes its wet and dry prints from it. */\nfunction inkFor(opts: { mark: string; detail?: string; shape: \"rect\" | \"seal\"; size: number; color: RGB; seed: string; dpr: number }): Ink {\n  const { mark, detail, shape, size, color, seed, dpr } = opts;\n  const word = mark.toUpperCase();\n  const small = (detail ?? \"\").toUpperCase();\n  const big = (shape === \"seal\" ? 24 : 30) * size;\n  const tiny = 10.5 * size;\n  const measure = document.createElement(\"canvas\").getContext(\"2d\")!;\n  const spaced = (text: string, px: number, weight: number, spacing: number) => {\n    measure.font = `${weight} ${px}px ${FONT}`;\n    let w = 0;\n    for (const ch of text) w += measure.measureText(ch).width + spacing;\n    return w - spacing;\n  };\n  const wordW = spaced(word, big, 800, big * 0.06);\n  const smallW = small ? spaced(small, tiny, 700, tiny * 0.14) : 0;\n  let W: number;\n  let H: number;\n  if (shape === \"seal\") {\n    // The word sits inside the inner ring (24px in from the rim) with room either side.\n    W = H = Math.ceil(Math.max(wordW + 78 * size, 136 * size));\n  } else {\n    W = Math.ceil(Math.max(wordW, smallW) + 44 * size);\n    H = Math.ceil(big * 1.05 + (small ? tiny + 10 * size : 0) + 30 * size);\n  }\n  const pw = Math.ceil(W * dpr);\n  const ph = Math.ceil(H * dpr);\n  const base = document.createElement(\"canvas\");\n  base.width = pw;\n  base.height = ph;\n  const ctx = base.getContext(\"2d\", { willReadFrequently: true })!;\n  ctx.scale(dpr, dpr);\n  ctx.fillStyle = ctx.strokeStyle = \"#000\";\n  const drawSpaced = (text: string, cx: number, y: number, px: number, weight: number, spacing: number) => {\n    ctx.font = `${weight} ${px}px ${FONT}`;\n    ctx.textBaseline = \"alphabetic\";\n    let x = cx - spaced(text, px, weight, spacing) / 2;\n    for (const ch of text) {\n      ctx.fillText(ch, x, y);\n      x += ctx.measureText(ch).width + spacing;\n    }\n  };\n  if (shape === \"seal\") {\n    const r = W / 2;\n    ctx.lineWidth = 3.2 * size;\n    ctx.beginPath();\n    ctx.arc(r, r, r - 2.4 * size, 0, Math.PI * 2);\n    ctx.stroke();\n    ctx.lineWidth = 1.2 * size;\n    ctx.beginPath();\n    ctx.arc(r, r, r - 8 * size, 0, Math.PI * 2);\n    ctx.stroke();\n    ctx.beginPath();\n    ctx.arc(r, r, r - 24 * size, 0, Math.PI * 2);\n    ctx.stroke();\n    // The detail runs round the rim, starting at the top.\n    if (small) {\n      const ring = `${small} · ${small} · `;\n      ctx.font = `700 ${tiny}px ${FONT}`;\n      const rr = r - 16 * size;\n      const total = Math.PI * 2;\n      const chars = [...ring];\n      const widths = chars.map((ch) => ctx.measureText(ch).width + tiny * 0.12);\n      const sum = widths.reduce((a, b) => a + b, 0);\n      let a = -Math.PI / 2 - (total * 0.5 * Math.min(1, sum / (rr * total)));\n      for (let i = 0; i < chars.length; i++) {\n        const step = (widths[i] / sum) * Math.min(total, sum / rr);\n        ctx.save();\n        ctx.translate(r + Math.cos(a + step / 2) * rr, r + Math.sin(a + step / 2) * rr);\n        ctx.rotate(a + step / 2 + Math.PI / 2);\n        ctx.textAlign = \"center\";\n        ctx.textBaseline = \"middle\";\n        ctx.fillText(chars[i], 0, 0);\n        ctx.restore();\n        a += step;\n      }\n    }\n    drawSpaced(word, r, r + big * 0.36, big, 800, big * 0.06);\n  } else {\n    const round = 7 * size;\n    const rrect = (inset: number, rad: number) => {\n      ctx.beginPath();\n      ctx.roundRect(inset, inset, W - inset * 2, H - inset * 2, rad);\n    };\n    ctx.lineWidth = 3.4 * size;\n    rrect(2 * size, round);\n    ctx.stroke();\n    ctx.lineWidth = 1.1 * size;\n    rrect(7.5 * size, round - 4 * size);\n    ctx.stroke();\n    const top = 15 * size;\n    drawSpaced(word, W / 2, top + big * 0.86, big, 800, big * 0.06);\n    if (small) {\n      const y = top + big * 1.05 + tiny + 3 * size;\n      drawSpaced(small, W / 2, y, tiny, 700, tiny * 0.14);\n    }\n  }\n\n  const src = ctx.getImageData(0, 0, pw, ph).data;\n  const rand = rng(seed);\n  const coarse = valueNoise(pw, ph, 9 * dpr, rand);\n  const fine = valueNoise(pw, ph, 2.2 * dpr, rand);\n  const lift = valueNoise(pw, ph, 3.5 * dpr, rand);\n  const tilt = rand() < 0.5 ? 1 : -1;\n  const dryA = new Uint8ClampedArray(pw * ph);\n  const wetData = new ImageData(pw, ph);\n  const dryData = new ImageData(pw, ph);\n  for (let i = 0; i < pw * ph; i++) {\n    const a = src[i * 4 + 3] / 255;\n    if (a === 0) continue;\n    const x = (i % pw) / pw;\n    const y = Math.floor(i / pw) / ph;\n    // More ink where the hand pressed harder: one side of the stamp, a little towards the bottom.\n    const pressure = 0.74 + 0.26 * (tilt > 0 ? 1 - x : x) * (0.75 + 0.25 * y) + (coarse[i] - 0.5) * 0.22;\n    // Dry: the surface's grain opens small voids, more where the pressure was light.\n    const grain = fine[i] * 0.6 + coarse[i] * 0.4;\n    const voids = clamp((grain - (0.62 - pressure * 0.32)) * 7, 0, 1);\n    const edge = a < 0.9 ? 0.55 + 0.45 * fine[i] : 1;\n    const dry = a * clamp(pressure, 0, 1) * (0.25 + 0.75 * voids) * edge;\n    const wet = a * clamp(0.9 + (coarse[i] - 0.5) * 0.12, 0, 1);\n    dryA[i] = Math.round(dry * 255);\n    for (const [data, alpha] of [\n      [wetData.data, wet],\n      [dryData.data, dry],\n    ] as const) {\n      data[i * 4] = color[0];\n      data[i * 4 + 1] = color[1];\n      data[i * 4 + 2] = color[2];\n      data[i * 4 + 3] = Math.round(alpha * 255);\n    }\n  }\n  const wetC = document.createElement(\"canvas\");\n  wetC.width = pw;\n  wetC.height = ph;\n  const wctx = wetC.getContext(\"2d\")!;\n  wctx.putImageData(wetData, 0, 0);\n  // Fresh ink sheen: a soft band of light across it.\n  wctx.globalCompositeOperation = \"source-atop\";\n  const sheen = wctx.createLinearGradient(0, 0, pw, ph);\n  sheen.addColorStop(0.2, \"rgba(255,255,255,0)\");\n  sheen.addColorStop(0.45, \"rgba(255,255,255,0.28)\");\n  sheen.addColorStop(0.6, \"rgba(255,255,255,0)\");\n  wctx.fillStyle = sheen;\n  wctx.fillRect(0, 0, pw, ph);\n  const dryC = document.createElement(\"canvas\");\n  dryC.width = pw;\n  dryC.height = ph;\n  dryC.getContext(\"2d\")!.putImageData(dryData, 0, 0);\n  return { w: W, h: H, dpr, wet: wetC, dry: dryC, dryAlpha: dryA, lift, color };\n}\n\nconst TONES: Record<NonNullable<StampProps[\"tone\"]>, string> = {\n  success: \"text-emerald-600 dark:text-emerald-400\",\n  danger: \"text-red-600 dark:text-red-400\",\n  warning: \"text-amber-600 dark:text-amber-400\",\n  primary: \"text-primary\",\n  neutral: \"text-foreground\",\n};\n\nexport function Stamp({\n  children,\n  on,\n  mark,\n  detail,\n  shape = \"rect\",\n  tone = \"success\",\n  color,\n  position = \"center\",\n  rotate = -9,\n  size = 1,\n  seed,\n  sound = false,\n  className = \"\",\n  ...props\n}: StampProps) {\n  const reduced = useReducedMotion();\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const probeRef = React.useRef<HTMLSpanElement>(null);\n  const bgRef = React.useRef<HTMLSpanElement>(null);\n  const state = React.useRef({ ink: null as Ink | null, phase: \"off\" as \"off\" | \"press\" | \"dry\" | \"on\" | \"lift\", t0: 0, frame: 0, dark: false, first: true });\n  const [box, setBox] = React.useState<{ w: number; h: number } | null>(null);\n  const [announce, setAnnounce] = React.useState(\"\");\n\n  const paint = React.useCallback((now: number) => {\n    const s = state.current;\n    const canvas = canvasRef.current;\n    const ink = s.ink;\n    const ctx = canvas?.getContext(\"2d\");\n    if (!canvas || !ctx || !ink) return false;\n    const pw = ink.wet.width;\n    const ph = ink.wet.height;\n    if (canvas.width !== pw || canvas.height !== ph) {\n      canvas.width = pw;\n      canvas.height = ph;\n    }\n    ctx.clearRect(0, 0, pw, ph);\n    const t = now - s.t0;\n    let busy = false;\n    if (s.phase === \"press\" || s.phase === \"dry\" || s.phase === \"on\") {\n      const wetness = s.phase === \"on\" ? 0 : 1 - inOut(clamp(t / DRY_MS, 0, 1));\n      if (wetness > 0) busy = true;\n      if (wetness < 1) {\n        ctx.globalAlpha = 1 - wetness;\n        ctx.drawImage(ink.dry, 0, 0);\n      }\n      if (wetness > 0) {\n        ctx.globalAlpha = wetness;\n        ctx.drawImage(ink.wet, 0, 0);\n      }\n      ctx.globalAlpha = 1;\n      // The press: it lands a touch large and settles; the record under it gives for a moment.\n      const k = clamp(t / 170, 0, 1);\n      const scale = s.phase === \"on\" ? 1 : 1.07 - 0.07 * outBack(k);\n      canvas.style.opacity = s.phase === \"on\" ? \"1\" : String(clamp(t / 40, 0, 1));\n      canvas.style.scale = String(scale);\n      const root = rootRef.current;\n      if (root) {\n        const give = s.phase === \"on\" ? 0 : Math.sin(Math.PI * clamp(t / 180, 0, 1)) * (1 - k * 0.5);\n        root.style.scale = give > 0.001 ? String(1 - 0.012 * give) : \"\";\n      }\n      if (t < 200) busy = true;\n      if (!busy && s.phase !== \"on\") s.phase = \"on\";\n    } else if (s.phase === \"lift\") {\n      // The ink breaks up into the grain, the thinnest parts first, and is gone.\n      const p = inOut(clamp(t / LIFT_MS, 0, 1));\n      const img = ctx.createImageData(pw, ph);\n      const d = img.data;\n      const [r, g, b] = ink.color;\n      for (let i = 0; i < pw * ph; i++) {\n        const a = ink.dryAlpha[i];\n        if (!a) continue;\n        const keep = ink.lift[i] * 0.7 + (a / 255) * 0.3;\n        if (keep < p) continue;\n        d[i * 4] = r;\n        d[i * 4 + 1] = g;\n        d[i * 4 + 2] = b;\n        d[i * 4 + 3] = a * clamp((keep - p) * 6, 0, 1) * (1 - p * 0.5);\n      }\n      ctx.putImageData(img, 0, 0);\n      canvas.style.scale = \"1\";\n      if (p < 1) busy = true;\n      else {\n        s.phase = \"off\";\n        canvas.style.opacity = \"0\";\n      }\n    } else {\n      canvas.style.opacity = \"0\";\n    }\n    return busy;\n  }, []);\n\n  const run = React.useCallback(() => {\n    const s = state.current;\n    if (s.frame) return;\n    const tick = (now: number) => {\n      s.frame = 0;\n      if (paint(now)) s.frame = requestAnimationFrame(tick);\n    };\n    s.frame = requestAnimationFrame(tick);\n  }, [paint]);\n\n  // Draw the ink for this word, colour and size; again when the theme changes.\n  React.useEffect(() => {\n    const s = state.current;\n    const build = () => {\n      const c = toRgb(probeRef.current ? getComputedStyle(probeRef.current).color : \"\", [5, 150, 105]);\n      const bg = toRgb(bgRef.current ? getComputedStyle(bgRef.current).color : \"\", [255, 255, 255]);\n      s.dark = (0.2126 * bg[0] + 0.7152 * bg[1] + 0.0722 * bg[2]) / 255 < 0.5;\n      s.ink = inkFor({ mark, detail, shape, size, color: c, seed: seed ?? `${mark}|${detail ?? \"\"}`, dpr: Math.min(3, window.devicePixelRatio || 1) });\n      setBox((was) => (was && was.w === s.ink!.w && was.h === s.ink!.h ? was : { w: s.ink!.w, h: s.ink!.h }));\n      paint(performance.now());\n    };\n    build();\n    const observer = new MutationObserver(build);\n    observer.observe(document.documentElement, { attributes: true, attributeFilter: [\"class\", \"style\", \"data-theme\"] });\n    const media = window.matchMedia(\"(prefers-color-scheme: dark)\");\n    media.addEventListener(\"change\", build);\n    return () => {\n      observer.disconnect();\n      media.removeEventListener(\"change\", build);\n    };\n  }, [mark, detail, shape, size, seed, tone, color, paint]);\n\n  // On and off: press and dry, or lift. Already on when it first shows: there, dry, no press.\n  React.useEffect(() => {\n    const s = state.current;\n    const now = performance.now();\n    const first = s.first;\n    s.first = false;\n    if (on) {\n      if (s.phase === \"on\" || s.phase === \"press\" || s.phase === \"dry\") return;\n      s.phase = first || reduced ? \"on\" : \"press\";\n      s.t0 = now;\n      if (!first) {\n        setAnnounce(`${mark}${detail ? `, ${detail}` : \"\"}`);\n        if (sound) playSound(\"drop\", 0.45);\n      }\n    } else {\n      if (s.phase === \"off\" || s.phase === \"lift\") return;\n      s.phase = reduced ? \"off\" : \"lift\";\n      s.t0 = now;\n      if (!first) setAnnounce(`${mark} removed`);\n    }\n    paint(now);\n    run();\n  }, [on, reduced, mark, detail, sound, paint, run]);\n\n  // The canvas mounts once the ink has a size; paint whatever phase it's in.\n  React.useEffect(() => {\n    paint(performance.now());\n    run();\n  }, [box, paint, run]);\n\n  React.useEffect(() => {\n    const s = state.current;\n    return () => {\n      cancelAnimationFrame(s.frame);\n      s.frame = 0;\n    };\n  }, []);\n\n  const place: React.CSSProperties =\n    position === \"top-right\"\n      ? { top: 12, right: 12 }\n      : position === \"bottom-right\"\n        ? { bottom: 12, right: 12 }\n        : { left: \"50%\", top: \"50%\", translate: \"-50% -50%\" };\n\n  return (\n    <div ref={rootRef} className={`relative ${className}`} {...props}>\n      <span ref={probeRef} hidden className={color ? undefined : TONES[tone]} style={color ? { color } : undefined} />\n      <span ref={bgRef} hidden className=\"text-background\" />\n      {children}\n      {box && (\n        <div aria-hidden className=\"pointer-events-none absolute z-10\" style={{ ...place, width: box.w, height: box.h, rotate: `${rotate}deg` }}>\n          <canvas\n            ref={canvasRef}\n            className=\"size-full mix-blend-multiply dark:mix-blend-normal\"\n            style={{ opacity: 0, transformOrigin: \"50% 50%\", willChange: \"scale, opacity\" }}\n          />\n        </div>\n      )}\n      {on && <span className=\"sr-only\">{`Stamped: ${mark}${detail ? `, ${detail}` : \"\"}`}</span>}\n      <span className=\"sr-only\" role=\"status\" aria-live=\"polite\">\n        {announce}\n      </span>\n    </div>\n  );\n}\n"},{"path":"registry/ui-sounds.ts","type":"registry:component","content":"// Hairline UI · stamp · 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/stamp. MIT licensed: https://hairlineui.com/license#components","meta":{"license":"MIT"}}