{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "micro-wake-slider",
  "type": "registry:component",
  "title": "Wake Slider",
  "description": "A slider whose thumb drags a stretching wake of liquid behind it and sends out ripples where it comes to rest. Arrow keys, Home, End and Page keys all work.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "micro",
    "slider",
    "range",
    "wake",
    "liquid",
    "drag",
    "form"
  ],
  "docs": "https://hyperblur.dev/effects/micro-wake-slider",
  "files": [
    {
      "path": "registry/hyperblur/micro-wake-slider.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/micro-wake-slider.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface MicroWakeSliderProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\"> {\n  value?: number;\n  defaultValue?: number;\n  min?: number;\n  max?: number;\n  step?: number;\n  label?: string;\n  showValue?: boolean;\n  unit?: string;\n  accent?: string;\n  disabled?: boolean;\n  idle?: boolean;\n  onChange?: (value: number) => void;\n}\n\nconst R = 12;\n\nconst css = `\n.hb-ql6 {\n  display: flex;\n  align-items: center;\n  gap: 14px;\n  width: 100%;\n  box-sizing: border-box;\n  font-family: inherit;\n  color: #ededed;\n  --hb-ql6-c: #2f7bff;\n}\n.hb-ql6 *, .hb-ql6 *::before, .hb-ql6 *::after { box-sizing: border-box; }\n.hb-ql6-n {\n  flex: none;\n  font-size: 0.82em;\n  font-weight: 500;\n  color: #a1a1a1;\n}\n.hb-ql6-t {\n  position: relative;\n  flex: 1;\n  min-width: 0;\n  height: 44px;\n  cursor: pointer;\n  touch-action: none;\n  user-select: none;\n  -webkit-user-select: none;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-ql6[data-disabled=\"true\"] .hb-ql6-t { cursor: not-allowed; opacity: 0.45; }\n.hb-ql6-r {\n  position: absolute;\n  left: ${R}px;\n  right: ${R}px;\n  top: 50%;\n  height: 6px;\n  margin-top: -3px;\n  background: #262626;\n  border-radius: 999px;\n}\n.hb-ql6-f {\n  position: absolute;\n  left: ${R}px;\n  top: 50%;\n  height: 6px;\n  margin-top: -3px;\n  background: linear-gradient(90deg, color-mix(in srgb, var(--hb-ql6-c) 55%, #000), var(--hb-ql6-c));\n  border-radius: 999px;\n}\n.hb-ql6-s {\n  position: absolute;\n  inset: 0;\n  width: 100%;\n  height: 100%;\n  overflow: visible;\n  pointer-events: none;\n}\n.hb-ql6-w { fill: var(--hb-ql6-c); }\n.hb-ql6-k {\n  position: absolute;\n  left: 0;\n  top: 50%;\n  width: ${R * 2}px;\n  height: ${R * 2}px;\n  margin-top: -${R}px;\n  background: linear-gradient(180deg, #ffffff, #dcdcdc);\n  border-radius: 50%;\n  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5), 0 0 0 3px color-mix(in srgb, var(--hb-ql6-c) 40%, transparent);\n  outline: 0;\n  will-change: transform;\n}\n.hb-ql6-k::after {\n  content: \"\";\n  position: absolute;\n  inset: 6px;\n  background: var(--hb-ql6-c);\n  border-radius: 50%;\n  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);\n}\n.hb-ql6-t[data-drag=\"true\"] .hb-ql6-k::after { transform: scale(1.35); }\n.hb-ql6-k:focus-visible { box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5), 0 0 0 3px #0a0a0a, 0 0 0 5px var(--hb-ql6-c); }\n.hb-ql6-h {\n  position: absolute;\n  left: 0;\n  top: 50%;\n  width: 0;\n  height: 0;\n  pointer-events: none;\n}\n.hb-ql6-g {\n  position: absolute;\n  left: -${R}px;\n  top: -${R}px;\n  width: ${R * 2}px;\n  height: ${R * 2}px;\n  border: 2px solid var(--hb-ql6-c);\n  border-radius: 50%;\n  opacity: 0;\n  animation: hb-ql6-ring 0.9s cubic-bezier(0.2, 0.7, 0.3, 1) both;\n}\n.hb-ql6-g:nth-child(2) { animation-delay: 0.14s; }\n.hb-ql6-o {\n  flex: none;\n  min-width: 3.2ch;\n  font-size: 0.95em;\n  font-weight: 600;\n  text-align: right;\n  font-variant-numeric: tabular-nums;\n}\n@keyframes hb-ql6-ring {\n  0% { opacity: 0.85; transform: scale(0.8); }\n  100% { opacity: 0; transform: scale(3.4); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-ql6-g { animation: none; }\n  .hb-ql6-k::after { transition: none; }\n}\n`;\n\nfunction decimals(step: number) {\n  const t = String(step);\n  const i = t.indexOf(\".\");\n  return i < 0 ? 0 : t.length - i - 1;\n}\n\nexport function MicroWakeSlider({\n  value,\n  defaultValue = 40,\n  min = 0,\n  max = 100,\n  step = 1,\n  label,\n  showValue = true,\n  unit = \"\",\n  accent = \"#2f7bff\",\n  disabled = false,\n  idle = true,\n  onChange,\n  className = \"\",\n  style,\n  onPointerEnter,\n  onPointerLeave,\n  ...rest\n}: MicroWakeSliderProps) {\n  const [inner, setInner] = React.useState(defaultValue);\n  const val = value ?? inner;\n  const trackRef = React.useRef<HTMLDivElement>(null);\n  const thumbRef = React.useRef<HTMLDivElement>(null);\n  const hostRef = React.useRef<HTMLDivElement>(null);\n  const fillRef = React.useRef<HTMLDivElement>(null);\n  const neckRef = React.useRef<SVGPathElement>(null);\n  const capRef = React.useRef<SVGCircleElement>(null);\n  const dropRef = React.useRef<SVGCircleElement>(null);\n  const outRef = React.useRef<HTMLSpanElement>(null);\n  const [ripple, setRipple] = React.useState({ id: 0, x: 0 });\n  const state = React.useRef({\n    dx: -1,\n    wx: 0,\n    w2: 0,\n    v: 0,\n    vw: 0,\n    v2: 0,\n    drag: false,\n    px: 0,\n    hover: false,\n    focus: false,\n    resumeAt: 0,\n    acc: 0,\n    moving: false,\n  });\n  const valRef = React.useRef(val);\n  const api = React.useRef({ wake: () => {}, reduced: false });\n  const latest = React.useRef({ min, max, step, idle, unit, value, onChange });\n\n  React.useEffect(() => {\n    valRef.current = val;\n    latest.current = { min, max, step, idle, unit, value, onChange };\n    api.current.wake();\n  }, [val, min, max, step, idle, unit, value, onChange]);\n\n  React.useEffect(() => {\n    const track = trackRef.current;\n    const thumb = thumbRef.current;\n    const host = hostRef.current;\n    const fill = fillRef.current;\n    const neck = neckRef.current;\n    const cap = capRef.current;\n    const drop = dropRef.current;\n    if (!track || !thumb || !host || !fill || !neck || !cap || !drop) 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 frac = (v: number) => {\n      const c = latest.current;\n      return c.max === c.min ? 0 : Math.max(0, Math.min(1, (v - c.min) / (c.max - c.min)));\n    };\n\n    const snap = (f: number) => {\n      const c = latest.current;\n      const raw = c.min + f * (c.max - c.min);\n      const n = Math.round((raw - c.min) / c.step) * c.step + c.min;\n      return Number(Math.max(c.min, Math.min(c.max, n)).toFixed(decimals(c.step)));\n    };\n\n    const draw = (idleOn: boolean) => {\n      const w = track.clientWidth;\n      const cy = track.clientHeight / 2;\n      const c = latest.current;\n      thumb.style.transform = `translate3d(${(s.dx - R).toFixed(2)}px,0,0)`;\n      host.style.transform = `translate3d(${s.dx.toFixed(2)}px,0,0)`;\n      fill.style.width = `${Math.max(0, s.dx - R).toFixed(2)}px`;\n      const sep = s.dx - s.wx;\n      const r1 = Math.max(0, Math.min(9, 3 + Math.abs(sep) * 0.2));\n      const r0 = 9;\n      const rm = Math.min(r0, r1) * 0.55;\n      if (Math.abs(sep) < 1.5) {\n        neck.setAttribute(\"d\", \"\");\n        cap.setAttribute(\"r\", \"0\");\n      } else {\n        const mid = (s.dx + s.wx) / 2;\n        neck.setAttribute(\n          \"d\",\n          `M ${s.dx.toFixed(1)} ${(cy - r0).toFixed(1)} Q ${mid.toFixed(1)} ${(cy - rm).toFixed(1)} ${s.wx.toFixed(1)} ${(cy - r1).toFixed(1)} L ${s.wx.toFixed(1)} ${(cy + r1).toFixed(1)} Q ${mid.toFixed(1)} ${(cy + rm).toFixed(1)} ${s.dx.toFixed(1)} ${(cy + r0).toFixed(1)} Z`,\n        );\n        cap.setAttribute(\"cx\", s.wx.toFixed(1));\n        cap.setAttribute(\"cy\", cy.toFixed(1));\n        cap.setAttribute(\"r\", r1.toFixed(2));\n      }\n      const sep2 = s.wx - s.w2;\n      const r2 = Math.abs(sep2) < 2 ? 0 : Math.min(5, 1.5 + Math.abs(sep2) * 0.14);\n      drop.setAttribute(\"cx\", s.w2.toFixed(1));\n      drop.setAttribute(\"cy\", cy.toFixed(1));\n      drop.setAttribute(\"r\", r2.toFixed(2));\n      const shown = idleOn ? snap((s.dx - R) / Math.max(1, w - 2 * R)) : valRef.current;\n      const text = `${shown.toFixed(decimals(c.step))}${c.unit}`;\n      const out = outRef.current;\n      if (out && out.textContent !== text) out.textContent = text;\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 w = track.clientWidth;\n      const span = Math.max(1, w - 2 * R);\n      const c = latest.current;\n      const home = R + span * frac(valRef.current);\n      if (s.dx < 0) {\n        s.dx = home;\n        s.wx = home;\n        s.w2 = home;\n      }\n      const idleOn = c.idle && !s.hover && !s.focus && !s.drag && now >= s.resumeAt;\n      const desired = s.drag\n        ? Math.max(R, Math.min(w - R, s.px))\n        : idleOn\n          ? R + span * (0.5 + 0.38 * Math.sin(now * 0.0013))\n          : home;\n      let rem = dt;\n      while (rem > 0) {\n        const h = Math.min(rem, 1 / 120);\n        s.v += (520 * (desired - s.dx) - 32 * s.v) * h;\n        s.dx += s.v * h;\n        s.vw += (110 * (s.dx - s.wx) - 11 * s.vw) * h;\n        s.wx += s.vw * h;\n        s.v2 += (55 * (s.wx - s.w2) - 7 * s.v2) * h;\n        s.w2 += s.v2 * h;\n        rem -= h;\n      }\n      const moving = Math.abs(s.v) > 6 || Math.abs(desired - s.dx) > 0.5 || Math.abs(s.wx - s.dx) > 1.5;\n      if (moving) s.acc += Math.abs(s.v) * dt;\n      if (s.moving && !moving && s.acc > 10) {\n        s.acc = 0;\n        setRipple((r) => ({ id: r.id + 1, x: s.dx }));\n      }\n      s.moving = moving;\n      draw(idleOn);\n      raf = requestAnimationFrame(tick);\n    };\n\n    const placeNow = () => {\n      const w = track.clientWidth;\n      const span = Math.max(1, w - 2 * R);\n      const home = R + span * frac(valRef.current);\n      s.dx = home;\n      s.wx = home;\n      s.w2 = home;\n      s.v = 0;\n      s.vw = 0;\n      s.v2 = 0;\n      draw(false);\n    };\n\n    const wake = () => {\n      if (api.current.reduced) {\n        if (s.drag) {\n          const w = track.clientWidth;\n          s.dx = Math.max(R, Math.min(w - R, s.px));\n          s.wx = s.dx;\n          s.w2 = s.dx;\n          draw(false);\n        } else placeNow();\n        return;\n      }\n      if (!raf && visible) {\n        last = performance.now();\n        raf = requestAnimationFrame(tick);\n      }\n    };\n\n    api.current.wake = wake;\n    placeNow();\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(track);\n    const ro = new ResizeObserver(() => {\n      if (api.current.reduced) placeNow();\n    });\n    ro.observe(track);\n    const onMq = () => {\n      api.current.reduced = mq.matches;\n      if (mq.matches) {\n        cancelAnimationFrame(raf);\n        raf = 0;\n        placeNow();\n      } else wake();\n    };\n    mq.addEventListener(\"change\", onMq);\n\n    return () => {\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      ro.disconnect();\n      mq.removeEventListener(\"change\", onMq);\n    };\n  }, []);\n\n  function emit(next: number) {\n    if (next === valRef.current) return;\n    valRef.current = next;\n    if (latest.current.value === undefined) setInner(next);\n    latest.current.onChange?.(next);\n  }\n\n  function fromPointer(clientX: number) {\n    const track = trackRef.current;\n    if (!track) return;\n    const rect = track.getBoundingClientRect();\n    const s = state.current;\n    s.px = clientX - rect.left;\n    const span = Math.max(1, rect.width - 2 * R);\n    const f = Math.max(0, Math.min(1, (s.px - R) / span));\n    const c = latest.current;\n    const raw = c.min + f * (c.max - c.min);\n    const n = Math.round((raw - c.min) / c.step) * c.step + c.min;\n    emit(Number(Math.max(c.min, Math.min(c.max, n)).toFixed(decimals(c.step))));\n  }\n\n  function nudge(delta: number) {\n    const c = latest.current;\n    const n = Math.max(c.min, Math.min(c.max, valRef.current + delta));\n    emit(Number(n.toFixed(decimals(c.step))));\n    state.current.resumeAt = performance.now() + 2000;\n    api.current.wake();\n  }\n\n  const vars = { \"--hb-ql6-c\": accent, ...style } as React.CSSProperties;\n  const text = `${val.toFixed(decimals(step))}${unit}`;\n\n  return (\n    <>\n      <style href=\"hb-micro-wake-slider\" precedence=\"default\">{css}</style>\n      <div\n        {...rest}\n        className={`hb-ql6 ${className}`}\n        style={vars}\n        data-disabled={disabled}\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      >\n        {label ? <span className=\"hb-ql6-n\">{label}</span> : null}\n        <div\n          ref={trackRef}\n          className=\"hb-ql6-t\"\n          data-drag=\"false\"\n          onPointerDown={(e) => {\n            if (e.button !== 0 || disabled) return;\n            e.currentTarget.setPointerCapture(e.pointerId);\n            e.currentTarget.dataset.drag = \"true\";\n            state.current.drag = true;\n            fromPointer(e.clientX);\n            thumbRef.current?.focus({ preventScroll: true });\n            api.current.wake();\n          }}\n          onPointerMove={(e) => {\n            if (!state.current.drag) return;\n            fromPointer(e.clientX);\n            api.current.wake();\n          }}\n          onPointerUp={(e) => {\n            if (!state.current.drag) return;\n            if (e.currentTarget.hasPointerCapture(e.pointerId)) e.currentTarget.releasePointerCapture(e.pointerId);\n            e.currentTarget.dataset.drag = \"false\";\n            state.current.drag = false;\n            state.current.resumeAt = performance.now() + 2200;\n            api.current.wake();\n          }}\n          onPointerCancel={(e) => {\n            e.currentTarget.dataset.drag = \"false\";\n            state.current.drag = false;\n            api.current.wake();\n          }}\n        >\n          <div className=\"hb-ql6-r\" />\n          <div ref={fillRef} className=\"hb-ql6-f\" />\n          <svg className=\"hb-ql6-s\" aria-hidden=\"true\">\n            <circle ref={dropRef} className=\"hb-ql6-w\" r=\"0\" opacity=\"0.7\" />\n            <path ref={neckRef} className=\"hb-ql6-w\" d=\"\" />\n            <circle ref={capRef} className=\"hb-ql6-w\" r=\"0\" />\n          </svg>\n          <div ref={hostRef} className=\"hb-ql6-h\" aria-hidden=\"true\">\n            {ripple.id > 0 ? (\n              <div key={ripple.id}>\n                <span className=\"hb-ql6-g\" />\n                <span className=\"hb-ql6-g\" />\n              </div>\n            ) : null}\n          </div>\n          <div\n            ref={thumbRef}\n            className=\"hb-ql6-k\"\n            role=\"slider\"\n            tabIndex={disabled ? -1 : 0}\n            aria-label={label ?? \"Value\"}\n            aria-valuemin={min}\n            aria-valuemax={max}\n            aria-valuenow={val}\n            aria-valuetext={text}\n            aria-disabled={disabled || undefined}\n            aria-orientation=\"horizontal\"\n            onFocus={() => {\n              state.current.focus = true;\n            }}\n            onBlur={() => {\n              state.current.focus = false;\n              state.current.resumeAt = performance.now() + 1500;\n            }}\n            onKeyDown={(e) => {\n              if (disabled) return;\n              const big = step * 10;\n              let delta = 0;\n              if (e.key === \"ArrowRight\" || e.key === \"ArrowUp\") delta = step;\n              else if (e.key === \"ArrowLeft\" || e.key === \"ArrowDown\") delta = -step;\n              else if (e.key === \"PageUp\") delta = big;\n              else if (e.key === \"PageDown\") delta = -big;\n              else if (e.key === \"Home\") delta = min - valRef.current;\n              else if (e.key === \"End\") delta = max - valRef.current;\n              else return;\n              e.preventDefault();\n              nudge(delta);\n            }}\n          />\n        </div>\n        {showValue ? (\n          <output className=\"hb-ql6-o\" aria-hidden=\"true\">\n            <span ref={outRef}>{text}</span>\n          </output>\n        ) : null}\n      </div>\n    </>\n  );\n}\n"
    }
  ]
}