{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "micro-swipe-toast",
  "type": "registry:component",
  "title": "Swipe Toast",
  "description": "A toast you flick sideways to dismiss. It resists with a rubber band, flies off past a threshold and carries an undo chip. Escape and the arrow keys dismiss it too.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "micro",
    "toast",
    "swipe",
    "dismiss",
    "undo",
    "gesture",
    "micro"
  ],
  "docs": "https://hyperblur.dev/effects/micro-swipe-toast",
  "files": [
    {
      "path": "registry/hyperblur/micro-swipe-toast.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/micro-swipe-toast.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface MicroSwipeToastProps\n  extends Omit<\n    React.HTMLAttributes<HTMLDivElement>,\n    \"title\" | \"children\" | \"onPointerDown\" | \"onPointerMove\" | \"onPointerUp\" | \"onPointerCancel\"\n  > {\n  title?: React.ReactNode;\n  description?: React.ReactNode;\n  undoLabel?: string;\n  open?: boolean;\n  defaultOpen?: boolean;\n  duration?: number;\n  accent?: string;\n  idle?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  onUndo?: () => void;\n  onDismiss?: (direction: \"left\" | \"right\" | \"undo\" | \"keyboard\" | \"timeout\") => void;\n}\n\nconst css = `\n.hb-ql3 {\n  position: relative;\n  display: flex;\n  align-items: center;\n  gap: 12px;\n  width: 100%;\n  min-height: 56px;\n  padding: 10px 10px 10px 12px;\n  overflow: hidden;\n  box-sizing: border-box;\n  font-family: inherit;\n  color: #ededed;\n  background: #171717;\n  border: 1px solid #2c2c2c;\n  border-radius: 16px;\n  box-shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.04);\n  cursor: grab;\n  touch-action: pan-y;\n  user-select: none;\n  -webkit-user-select: none;\n  -webkit-tap-highlight-color: transparent;\n  will-change: transform, opacity;\n  --hb-ql3-c: #2f7bff;\n}\n.hb-ql3 *, .hb-ql3 *::before, .hb-ql3 *::after { box-sizing: border-box; }\n.hb-ql3:active { cursor: grabbing; }\n.hb-ql3:focus-visible { outline: 2px solid var(--hb-ql3-c); outline-offset: 3px; }\n.hb-ql3-i {\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: 30px;\n  height: 30px;\n  color: #fff;\n  background: var(--hb-ql3-c);\n  border-radius: 50%;\n  box-shadow: 0 0 16px -2px color-mix(in srgb, var(--hb-ql3-c) 70%, transparent);\n}\n.hb-ql3-i svg { width: 16px; height: 16px; }\n.hb-ql3-x { min-width: 0; flex: 1; line-height: 1.3; }\n.hb-ql3-t {\n  margin: 0;\n  overflow: hidden;\n  font-size: 0.92em;\n  font-weight: 600;\n  text-overflow: ellipsis;\n  white-space: nowrap;\n}\n.hb-ql3-d {\n  margin: 2px 0 0;\n  overflow: hidden;\n  font-size: 0.78em;\n  color: #8f8f8f;\n  text-overflow: ellipsis;\n  white-space: nowrap;\n}\n.hb-ql3-u {\n  flex: none;\n  margin: 0;\n  padding: 0.45em 0.95em;\n  font: inherit;\n  font-size: 0.82em;\n  font-weight: 600;\n  color: #7fb3ff;\n  background: color-mix(in srgb, var(--hb-ql3-c) 14%, transparent);\n  border: 1px solid color-mix(in srgb, var(--hb-ql3-c) 45%, transparent);\n  border-radius: 999px;\n  cursor: pointer;\n  transition: background 0.2s ease, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);\n}\n.hb-ql3-u:hover { background: color-mix(in srgb, var(--hb-ql3-c) 26%, transparent); }\n.hb-ql3-u:active { transform: scale(0.94); }\n.hb-ql3-u:focus-visible { outline: 2px solid var(--hb-ql3-c); outline-offset: 2px; }\n.hb-ql3-b {\n  position: absolute;\n  left: 0;\n  right: 0;\n  bottom: 0;\n  height: 2px;\n  background: var(--hb-ql3-c);\n  opacity: 0.8;\n  transform-origin: left center;\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-ql3-u { transition: none; }\n}\n`;\n\ntype Leave = { mode: \"fly\" | \"fade\"; dir: number; reason: \"left\" | \"right\" | \"undo\" | \"keyboard\" | \"timeout\" };\n\nexport function MicroSwipeToast({\n  title = \"Conversation archived\",\n  description,\n  undoLabel = \"Undo\",\n  open,\n  defaultOpen = true,\n  duration = 0,\n  accent = \"#2f7bff\",\n  idle = true,\n  onOpenChange,\n  onUndo,\n  onDismiss,\n  className = \"\",\n  style,\n  onKeyDown,\n  onFocus,\n  onBlur,\n  onPointerEnter,\n  onPointerLeave,\n  ...rest\n}: MicroSwipeToastProps) {\n  const [inner, setInner] = React.useState(defaultOpen);\n  const isOpen = open ?? inner;\n  const elRef = React.useRef<HTMLDivElement>(null);\n  const barRef = React.useRef<HTMLDivElement>(null);\n  const state = React.useRef({\n    x: 0,\n    v: 0,\n    drag: false,\n    startX: 0,\n    base: 0,\n    lastX: 0,\n    lastT: 0,\n    vel: 0,\n    hover: false,\n    focus: false,\n    resumeAt: 0,\n    idleStart: -1,\n    cyc: -1,\n    life: 0,\n    leave: null as Leave | null,\n    fade: 1,\n  });\n  const api = React.useRef({ wake: () => {}, draw: () => {}, reduced: false });\n  const latest = React.useRef({ idle, duration, onOpenChange, onDismiss, open });\n\n  React.useEffect(() => {\n    latest.current = { idle, duration, onOpenChange, onDismiss, open };\n  }, [idle, duration, onOpenChange, onDismiss, open]);\n\n  const finish = React.useCallback((reason: Leave[\"reason\"]) => {\n    const s = state.current;\n    s.leave = null;\n    s.x = 0;\n    s.v = 0;\n    s.fade = 1;\n    s.life = 0;\n    s.drag = false;\n    if (latest.current.open === undefined) setInner(false);\n    latest.current.onOpenChange?.(false);\n    latest.current.onDismiss?.(reason);\n  }, []);\n\n  React.useEffect(() => {\n    const el = elRef.current;\n    if (!isOpen || !el) return;\n    const bar = barRef.current;\n    const s = state.current;\n    s.x = 0;\n    s.v = 0;\n    s.fade = 1;\n    s.life = 0;\n    s.leave = null;\n    const mq = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    api.current.reduced = mq.matches;\n    let raf = 0;\n    let last = 0;\n    let visible = true;\n\n    const draw = () => {\n      const w = el.clientWidth || 1;\n      const op = Math.max(0, Math.min(1, s.fade * (1 - Math.abs(s.x) / (w * 1.1))));\n      el.style.transform = `translate3d(${s.x.toFixed(2)}px,0,0) rotate(${(s.x / w * 4).toFixed(3)}deg)`;\n      el.style.opacity = op.toFixed(3);\n    };\n\n    const tick = (now: number) => {\n      raf = 0;\n      if (!visible) return;\n      const dt = Math.min(0.05, Math.max(0.001, (now - last) / 1000));\n      last = now;\n      const cfg = latest.current;\n      const w = el.clientWidth || 1;\n      const reduced = api.current.reduced;\n      const idleOn =\n        cfg.idle && !reduced && !s.hover && !s.focus && !s.drag && !s.leave && now >= s.resumeAt;\n      if (idleOn) {\n        if (s.idleStart < 0) s.idleStart = now;\n        const cyc = Math.floor((now - s.idleStart - 1000) / 3800);\n        if (cyc >= 0 && cyc !== s.cyc) {\n          s.cyc = cyc;\n          s.v += cyc % 2 === 0 ? 520 : -520;\n        }\n      } else {\n        s.idleStart = -1;\n        s.cyc = -1;\n      }\n      if (cfg.duration > 0 && !s.hover && !s.focus && !s.drag && !s.leave) {\n        s.life += dt * 1000;\n        if (bar) bar.style.transform = `scaleX(${Math.max(0, 1 - s.life / cfg.duration).toFixed(4)})`;\n        if (s.life >= cfg.duration) s.leave = { mode: \"fly\", dir: 1, reason: \"timeout\" };\n      }\n      if (!s.drag) {\n        let rem = dt;\n        while (rem > 0) {\n          const h = Math.min(rem, 1 / 120);\n          if (s.leave && s.leave.mode === \"fly\") {\n            const target = s.leave.dir * (w + 48);\n            s.v += (140 * (target - s.x) - 22 * s.v) * h;\n          } else if (!s.leave) {\n            s.v += (-230 * s.x - 15 * s.v) * h;\n          } else {\n            s.v = 0;\n          }\n          s.x += s.v * h;\n          rem -= h;\n        }\n        if (s.leave) {\n          if (s.leave.mode === \"fade\") s.fade = Math.max(0, s.fade - dt / 0.22);\n          const done = s.leave.mode === \"fly\" ? Math.abs(s.x) > w + 8 : s.fade <= 0;\n          if (done) {\n            const reason = s.leave.reason;\n            draw();\n            finish(reason);\n            return;\n          }\n        } else if (Math.abs(s.x) < 0.01 && Math.abs(s.v) < 0.01) {\n          s.x = 0;\n          s.v = 0;\n        }\n      }\n      draw();\n      raf = requestAnimationFrame(tick);\n    };\n\n    const wake = () => {\n      if (api.current.reduced) {\n        draw();\n        return;\n      }\n      if (!raf && visible) {\n        last = performance.now();\n        raf = requestAnimationFrame(tick);\n      }\n    };\n\n    api.current.wake = wake;\n    api.current.draw = draw;\n    draw();\n    wake();\n\n    const io = new IntersectionObserver((entries) => {\n      visible = (entries[entries.length - 1]?.isIntersecting ?? true) || !!s.leave;\n      if (visible) wake();\n      else {\n        cancelAnimationFrame(raf);\n        raf = 0;\n      }\n    });\n    io.observe(el.parentElement ?? el);\n    const onMq = () => {\n      api.current.reduced = mq.matches;\n      if (mq.matches) {\n        cancelAnimationFrame(raf);\n        raf = 0;\n        s.x = 0;\n        s.v = 0;\n        draw();\n      } else wake();\n    };\n    mq.addEventListener(\"change\", onMq);\n\n    return () => {\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      mq.removeEventListener(\"change\", onMq);\n    };\n  }, [isOpen, finish]);\n\n  function leave(next: Leave) {\n    const s = state.current;\n    if (s.leave) return;\n    if (api.current.reduced) {\n      finish(next.reason);\n      return;\n    }\n    s.leave = next;\n    s.drag = false;\n    api.current.wake();\n  }\n\n  if (!isOpen) {\n    return <style href=\"hb-micro-swipe-toast\" precedence=\"default\">{css}</style>;\n  }\n\n  const vars = { \"--hb-ql3-c\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-micro-swipe-toast\" precedence=\"default\">{css}</style>\n      <div\n        role=\"status\"\n        aria-live=\"polite\"\n        aria-keyshortcuts=\"Escape\"\n        tabIndex={0}\n        {...rest}\n        ref={elRef}\n        className={`hb-ql3 ${className}`}\n        style={vars}\n        onFocus={(e) => {\n          onFocus?.(e);\n          state.current.focus = true;\n        }}\n        onBlur={(e) => {\n          onBlur?.(e);\n          state.current.focus = false;\n          state.current.resumeAt = performance.now() + 1500;\n        }}\n        onPointerEnter={(e) => {\n          onPointerEnter?.(e);\n          state.current.hover = true;\n        }}\n        onPointerLeave={(e) => {\n          onPointerLeave?.(e);\n          state.current.hover = false;\n          state.current.resumeAt = performance.now() + 1500;\n        }}\n        onKeyDown={(e) => {\n          onKeyDown?.(e);\n          if (e.defaultPrevented) return;\n          if (e.key === \"Escape\" || e.key === \"ArrowRight\") {\n            e.preventDefault();\n            leave({ mode: \"fly\", dir: 1, reason: \"keyboard\" });\n          } else if (e.key === \"ArrowLeft\") {\n            e.preventDefault();\n            leave({ mode: \"fly\", dir: -1, reason: \"keyboard\" });\n          }\n        }}\n        onPointerDown={(e) => {\n          if (e.button !== 0 || (e.target as HTMLElement).closest(\"button\")) return;\n          const s = state.current;\n          if (s.leave) return;\n          e.currentTarget.setPointerCapture(e.pointerId);\n          s.drag = true;\n          s.startX = e.clientX;\n          s.lastX = e.clientX;\n          s.lastT = e.timeStamp;\n          s.vel = 0;\n          const cap = 150;\n          const sign = s.x < 0 ? -1 : 1;\n          const base = Math.min(0.99, Math.abs(s.x) / cap);\n          s.v = 0;\n          s.base = sign * -cap * Math.log(1 - base);\n          api.current.wake();\n        }}\n        onPointerMove={(e) => {\n          const s = state.current;\n          if (!s.drag) return;\n          const cap = 150;\n          const raw = s.base + (e.clientX - s.startX);\n          const mag = cap * (1 - Math.exp(-Math.abs(raw) / cap));\n          s.x = raw < 0 ? -mag : mag;\n          const dt = Math.max(1, e.timeStamp - s.lastT);\n          s.vel = Math.max(-3, Math.min(3, s.vel * 0.6 + ((e.clientX - s.lastX) / dt) * 0.4));\n          s.lastX = e.clientX;\n          s.lastT = e.timeStamp;\n          api.current.draw();\n        }}\n        onPointerUp={(e) => {\n          const s = state.current;\n          if (!s.drag) return;\n          if (e.currentTarget.hasPointerCapture(e.pointerId)) e.currentTarget.releasePointerCapture(e.pointerId);\n          s.drag = false;\n          const w = e.currentTarget.clientWidth;\n          const thresh = Math.min(72, w * 0.25);\n          const dir = s.x < 0 ? -1 : 1;\n          const flick = Math.abs(s.vel) > 0.55 && Math.sign(s.vel) === dir;\n          if (Math.abs(s.x) > thresh || flick) {\n            s.v = s.vel * 1000;\n            leave({ mode: \"fly\", dir, reason: dir < 0 ? \"left\" : \"right\" });\n          } else {\n            s.v = s.vel * 1000;\n            s.resumeAt = performance.now() + 2000;\n            if (api.current.reduced) {\n              s.x = 0;\n              api.current.draw();\n            } else api.current.wake();\n          }\n        }}\n        onPointerCancel={() => {\n          state.current.drag = false;\n          api.current.wake();\n        }}\n      >\n        <span className=\"hb-ql3-i\" aria-hidden=\"true\">\n          <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n            <path d=\"M5 12.5l4.5 4.5L19 7.5\" />\n          </svg>\n        </span>\n        <div className=\"hb-ql3-x\">\n          <p className=\"hb-ql3-t\">{title}</p>\n          {description ? <p className=\"hb-ql3-d\">{description}</p> : null}\n        </div>\n        <button\n          type=\"button\"\n          className=\"hb-ql3-u\"\n          onClick={() => {\n            onUndo?.();\n            leave({ mode: \"fade\", dir: 0, reason: \"undo\" });\n          }}\n        >\n          {undoLabel}\n        </button>\n        {duration > 0 ? <div ref={barRef} className=\"hb-ql3-b\" aria-hidden=\"true\" /> : null}\n      </div>\n    </>\n  );\n}\n"
    }
  ]
}