{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "micro-bell-toggle",
  "type": "registry:component",
  "title": "Bell Toggle",
  "description": "A notifications bell that swings on a decaying spring with a lagging clapper. Turning it on rings it and pops a badge dot; turning it off settles it quietly.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "micro",
    "bell",
    "notifications",
    "toggle",
    "switch",
    "spring",
    "badge"
  ],
  "docs": "https://hyperblur.dev/effects/micro-bell-toggle",
  "files": [
    {
      "path": "registry/hyperblur/micro-bell-toggle.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/micro-bell-toggle.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface MicroBellToggleProps\n  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"onChange\" | \"children\" | \"role\"> {\n  checked?: boolean;\n  defaultChecked?: boolean;\n  size?: number;\n  accent?: string;\n  label?: string;\n  idle?: boolean;\n  onChange?: (checked: boolean) => void;\n}\n\nconst body =\n  \"M12 4.2c-3.4 0-5.6 2.5-5.6 5.8v2.6c0 1.5-.6 2.6-1.6 3.7-.4.5-.1 1.3.6 1.3h13.2c.7 0 1-.8.6-1.3-1-1.1-1.6-2.2-1.6-3.7V10c0-3.3-2.2-5.8-5.6-5.8z\";\n\nconst css = `\n.hb-ql9 {\n  position: relative;\n  display: inline-grid;\n  place-items: center;\n  width: var(--hb-ql9-s);\n  height: var(--hb-ql9-s);\n  margin: 0;\n  padding: 0;\n  box-sizing: border-box;\n  color: #6f6f6f;\n  background: #111111;\n  border: 1px solid #2a2a2a;\n  border-radius: 28%;\n  cursor: pointer;\n  -webkit-tap-highlight-color: transparent;\n  transition: border-color 0.3s ease, color 0.3s ease, background 0.3s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);\n  --hb-ql9-c: #2f7bff;\n  --hb-ql9-s: 48px;\n}\n.hb-ql9 *, .hb-ql9 *::before, .hb-ql9 *::after { box-sizing: border-box; }\n.hb-ql9:hover { border-color: #3a3a3a; }\n.hb-ql9:active { transform: scale(0.92); }\n.hb-ql9:focus-visible { outline: 2px solid var(--hb-ql9-c); outline-offset: 4px; }\n.hb-ql9:disabled { opacity: 0.45; cursor: not-allowed; }\n.hb-ql9[aria-checked=\"true\"] {\n  color: #f2f2f2;\n  border-color: color-mix(in srgb, var(--hb-ql9-c) 50%, #2a2a2a);\n  background: radial-gradient(circle at 50% 30%, color-mix(in srgb, var(--hb-ql9-c) 16%, #111111), #111111 70%);\n}\n.hb-ql9-v {\n  display: block;\n  width: 58%;\n  height: 58%;\n  overflow: visible;\n}\n.hb-ql9-a {\n  fill: currentColor;\n  transition: fill 0.3s ease;\n}\n.hb-ql9-w {\n  fill: none;\n  stroke: var(--hb-ql9-c);\n  stroke-width: 1.5;\n  stroke-linecap: round;\n  opacity: 0;\n}\n.hb-ql9-d {\n  position: absolute;\n  right: 20%;\n  top: 18%;\n  width: 28%;\n  height: 28%;\n  background: var(--hb-ql9-c);\n  border: 2px solid #111111;\n  border-radius: 50%;\n  box-shadow: 0 0 10px color-mix(in srgb, var(--hb-ql9-c) 80%, transparent);\n  transform: scale(0);\n  transition: transform 0.4s cubic-bezier(0.34, 1.8, 0.64, 1);\n}\n.hb-ql9[aria-checked=\"true\"] .hb-ql9-d { transform: scale(1); }\n.hb-ql9-g {\n  position: absolute;\n  right: 20%;\n  top: 18%;\n  width: 28%;\n  height: 28%;\n  border: 2px solid var(--hb-ql9-c);\n  border-radius: 50%;\n  opacity: 0;\n  pointer-events: none;\n  animation: hb-ql9-ping 0.8s cubic-bezier(0.2, 0.7, 0.3, 1) both;\n}\n@keyframes hb-ql9-ping {\n  0% { opacity: 0.9; transform: scale(1); }\n  100% { opacity: 0; transform: scale(3); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-ql9, .hb-ql9-a, .hb-ql9-d { transition: none; }\n  .hb-ql9-g { animation: none; }\n}\n`;\n\nexport function MicroBellToggle({\n  checked,\n  defaultChecked = true,\n  size = 48,\n  accent = \"#2f7bff\",\n  label = \"Notifications\",\n  idle = true,\n  disabled,\n  onChange,\n  className = \"\",\n  style,\n  onClick,\n  onPointerEnter,\n  onPointerLeave,\n  onFocus,\n  onBlur,\n  ...rest\n}: MicroBellToggleProps) {\n  const [inner, setInner] = React.useState(defaultChecked);\n  const on = checked ?? inner;\n  const [ping, setPing] = React.useState(0);\n  const rootRef = React.useRef<HTMLButtonElement>(null);\n  const bellRef = React.useRef<SVGGElement>(null);\n  const clapRef = React.useRef<SVGGElement>(null);\n  const leftRef = React.useRef<SVGPathElement>(null);\n  const rightRef = React.useRef<SVGPathElement>(null);\n  const state = React.useRef({\n    th: 0,\n    w: 0,\n    ph: 0,\n    pw: 0,\n    hover: false,\n    focus: false,\n    resumeAt: 0,\n    idleStart: -1,\n    cyc: -1,\n  });\n  const api = React.useRef({ wake: () => {}, reduced: false });\n  const latest = React.useRef({ on, idle });\n\n  React.useEffect(() => {\n    latest.current = { on, idle };\n    api.current.wake();\n  }, [on, idle]);\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const bell = bellRef.current;\n    const clap = clapRef.current;\n    const left = leftRef.current;\n    const right = rightRef.current;\n    if (!root || !bell || !clap || !left || !right) return;\n    const s = state.current;\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      bell.setAttribute(\"transform\", `rotate(${s.th.toFixed(2)} 12 2.6)`);\n      clap.setAttribute(\"transform\", `rotate(${s.ph.toFixed(2)} 12 10.5)`);\n      const amp = Math.min(1, Math.abs(s.th) / 14);\n      const op = (amp * 0.9).toFixed(2);\n      left.setAttribute(\"opacity\", op);\n      right.setAttribute(\"opacity\", op);\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 idleOn = cfg.idle && cfg.on && !s.hover && !s.focus && now >= s.resumeAt;\n      if (idleOn) {\n        if (s.idleStart < 0) s.idleStart = now;\n        const cyc = Math.floor((now - s.idleStart - 1200) / 4400);\n        if (cyc >= 0 && cyc !== s.cyc) {\n          s.cyc = cyc;\n          s.w += 460;\n        }\n      } else {\n        s.idleStart = -1;\n        s.cyc = -1;\n      }\n      let rem = dt;\n      while (rem > 0) {\n        const h = Math.min(rem, 1 / 120);\n        s.w += (-220 * s.th - 2.8 * s.w) * h;\n        s.th += s.w * h;\n        const clapTarget = Math.max(-42, Math.min(42, -s.th * 1.5));\n        s.pw += (300 * (clapTarget - s.ph) - 7 * s.pw) * h;\n        s.ph += s.pw * h;\n        rem -= h;\n      }\n      draw();\n      const resting =\n        Math.abs(s.th) < 0.02 && Math.abs(s.w) < 0.1 && Math.abs(s.ph) < 0.02 && Math.abs(s.pw) < 0.1;\n      if (resting && !idleOn) {\n        s.th = 0;\n        s.w = 0;\n        s.ph = 0;\n        s.pw = 0;\n        draw();\n        return;\n      }\n      raf = requestAnimationFrame(tick);\n    };\n\n    const wake = () => {\n      if (api.current.reduced) return;\n      if (!raf && visible) {\n        last = performance.now();\n        raf = requestAnimationFrame(tick);\n      }\n    };\n\n    api.current.wake = wake;\n    draw();\n    wake();\n\n    const io = new IntersectionObserver((entries) => {\n      visible = entries[entries.length - 1]?.isIntersecting ?? true;\n      if (visible) wake();\n      else {\n        cancelAnimationFrame(raf);\n        raf = 0;\n      }\n    });\n    io.observe(root);\n    const onMq = () => {\n      api.current.reduced = mq.matches;\n      if (mq.matches) {\n        cancelAnimationFrame(raf);\n        raf = 0;\n        s.th = 0;\n        s.w = 0;\n        s.ph = 0;\n        s.pw = 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  }, []);\n\n  function kick(power: number) {\n    if (api.current.reduced) return;\n    state.current.w += power;\n    api.current.wake();\n  }\n\n  const vars = {\n    \"--hb-ql9-c\": accent,\n    \"--hb-ql9-s\": `${size}px`,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-micro-bell-toggle\" precedence=\"default\">{css}</style>\n      <button\n        {...rest}\n        ref={rootRef}\n        type=\"button\"\n        role=\"switch\"\n        aria-checked={on}\n        aria-label={label}\n        disabled={disabled}\n        className={`hb-ql9 ${className}`}\n        style={vars}\n        onClick={(e) => {\n          onClick?.(e);\n          if (e.defaultPrevented) return;\n          const next = !on;\n          if (checked === undefined) setInner(next);\n          if (next) setPing((p) => p + 1);\n          state.current.resumeAt = performance.now() + 2600;\n          kick(next ? 620 : -170);\n          onChange?.(next);\n        }}\n        onPointerEnter={(e) => {\n          onPointerEnter?.(e);\n          state.current.hover = true;\n          if (e.pointerType === \"mouse\" && on) kick(240);\n        }}\n        onPointerLeave={(e) => {\n          onPointerLeave?.(e);\n          state.current.hover = false;\n          state.current.resumeAt = performance.now() + 1800;\n          api.current.wake();\n        }}\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() + 1800;\n          api.current.wake();\n        }}\n      >\n        <svg className=\"hb-ql9-v\" viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n          <path ref={leftRef} className=\"hb-ql9-w\" d=\"M3.2 9.6c.3-2 1.2-3.8 2.6-5.1\" opacity=\"0\" />\n          <path ref={rightRef} className=\"hb-ql9-w\" d=\"M20.8 9.6c-.3-2-1.2-3.8-2.6-5.1\" opacity=\"0\" />\n          <g ref={bellRef}>\n            <circle className=\"hb-ql9-a\" cx=\"12\" cy=\"2.9\" r=\"1.1\" />\n            <path className=\"hb-ql9-a\" d={body} />\n            <g ref={clapRef}>\n              <circle className=\"hb-ql9-a\" cx=\"12\" cy=\"20\" r=\"1.8\" />\n            </g>\n          </g>\n        </svg>\n        <span className=\"hb-ql9-d\" aria-hidden=\"true\" />\n        {ping > 0 ? <span key={ping} className=\"hb-ql9-g\" aria-hidden=\"true\" /> : null}\n      </button>\n    </>\n  );\n}\n"
    }
  ]
}