{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "slider-range-dual",
  "type": "registry:component",
  "title": "Dual Range Slider",
  "description": "A two thumb range slider with a filled track, value bubbles, a minimum gap, pointer dragging and full keyboard control.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "micro",
    "slider",
    "range",
    "dual",
    "filter",
    "price",
    "form"
  ],
  "docs": "https://hyperblur.dev/effects/slider-range-dual",
  "files": [
    {
      "path": "registry/hyperblur/slider-range-dual.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/slider-range-dual.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface SliderRangeDualProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"defaultValue\" | \"onChange\"> {\n  min?: number;\n  max?: number;\n  step?: number;\n  value?: [number, number];\n  defaultValue?: [number, number];\n  onValueChange?: (value: [number, number]) => void;\n  minGap?: number;\n  formatValue?: (value: number) => string;\n  bubbles?: \"always\" | \"active\" | \"none\";\n  label?: string;\n  name?: string;\n  disabled?: boolean;\n  accent?: string;\n}\n\nconst css = `\n.hb-qn8 {\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  padding: 0 11px;\n  font: inherit;\n  color: #ededed;\n  user-select: none;\n  -webkit-user-select: none;\n}\n.hb-qn8 *, .hb-qn8 *::before, .hb-qn8 *::after { box-sizing: border-box; }\n.hb-qn8[data-bubbles=\"always\"], .hb-qn8[data-bubbles=\"active\"] { padding-top: 34px; }\n.hb-qn8[data-disabled=\"true\"] { opacity: 0.45; pointer-events: none; }\n.hb-qn8-hit {\n  position: relative;\n  height: 22px;\n  cursor: pointer;\n  touch-action: none;\n}\n.hb-qn8-rail {\n  position: absolute;\n  top: 50%;\n  right: -11px;\n  left: -11px;\n  height: 6px;\n  border-radius: 6px;\n  background: #262626;\n  transform: translateY(-50%);\n}\n.hb-qn8-fill {\n  position: absolute;\n  top: 50%;\n  height: 6px;\n  border-radius: 6px;\n  background: var(--hb-qn8-a);\n  box-shadow: 0 0 14px -2px var(--hb-qn8-a);\n  transform: translateY(-50%);\n}\n.hb-qn8-thumb {\n  position: absolute;\n  top: 50%;\n  z-index: 1;\n  width: 22px;\n  height: 22px;\n  margin: 0;\n  border-radius: 50%;\n  background: #fff;\n  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(0, 0, 0, 0.2);\n  outline: 0;\n  cursor: grab;\n  transform: translate(-50%, -50%);\n  transition: scale 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;\n}\n.hb-qn8-thumb::after {\n  content: \"\";\n  position: absolute;\n  inset: 6px;\n  border-radius: 50%;\n  background: var(--hb-qn8-a);\n}\n.hb-qn8-thumb:hover { scale: 1.08; }\n.hb-qn8-thumb:focus-visible { box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5), 0 0 0 4px color-mix(in srgb, var(--hb-qn8-a) 45%, transparent); }\n.hb-qn8-thumb[data-active=\"true\"] { z-index: 2; scale: 1.14; cursor: grabbing; }\n.hb-qn8-bub {\n  position: absolute;\n  bottom: calc(100% + 9px);\n  left: 50%;\n  padding: 4px 8px;\n  border: 1px solid #2f2f2f;\n  border-radius: 8px;\n  background: #1a1a1a;\n  box-shadow: 0 6px 16px -6px rgba(0, 0, 0, 0.7);\n  font-size: 12px;\n  font-weight: 600;\n  line-height: 1.2;\n  color: #ededed;\n  font-variant-numeric: tabular-nums;\n  white-space: nowrap;\n  pointer-events: none;\n  opacity: 1;\n  transform: translateX(-50%) translateY(0);\n  transition: opacity 0.18s ease, transform 0.18s ease;\n}\n.hb-qn8-thumb[data-which=\"min\"] .hb-qn8-bub { transform: translateX(-62%) translateY(0); }\n.hb-qn8-thumb[data-which=\"max\"] .hb-qn8-bub { transform: translateX(-38%) translateY(0); }\n.hb-qn8-bub::after {\n  content: \"\";\n  position: absolute;\n  top: 100%;\n  left: 50%;\n  width: 7px;\n  height: 7px;\n  margin: -4px 0 0 -3.5px;\n  border-right: 1px solid #2f2f2f;\n  border-bottom: 1px solid #2f2f2f;\n  background: #1a1a1a;\n  transform: rotate(45deg);\n}\n.hb-qn8-thumb[data-which=\"min\"] .hb-qn8-bub::after { left: 62%; }\n.hb-qn8-thumb[data-which=\"max\"] .hb-qn8-bub::after { left: 38%; }\n.hb-qn8[data-bubbles=\"active\"] .hb-qn8-bub { opacity: 0; transform: translateX(-50%) translateY(4px); }\n.hb-qn8[data-bubbles=\"active\"] .hb-qn8-thumb[data-which=\"min\"] .hb-qn8-bub { transform: translateX(-62%) translateY(4px); }\n.hb-qn8[data-bubbles=\"active\"] .hb-qn8-thumb[data-which=\"max\"] .hb-qn8-bub { transform: translateX(-38%) translateY(4px); }\n.hb-qn8[data-bubbles=\"active\"] .hb-qn8-thumb:hover .hb-qn8-bub,\n.hb-qn8[data-bubbles=\"active\"] .hb-qn8-thumb:focus-visible .hb-qn8-bub,\n.hb-qn8[data-bubbles=\"active\"] .hb-qn8-thumb[data-active=\"true\"] .hb-qn8-bub { opacity: 1; }\n.hb-qn8[data-bubbles=\"active\"] .hb-qn8-thumb[data-which=\"min\"]:hover .hb-qn8-bub,\n.hb-qn8[data-bubbles=\"active\"] .hb-qn8-thumb[data-which=\"min\"]:focus-visible .hb-qn8-bub,\n.hb-qn8[data-bubbles=\"active\"] .hb-qn8-thumb[data-which=\"min\"][data-active=\"true\"] .hb-qn8-bub { transform: translateX(-62%) translateY(0); }\n.hb-qn8[data-bubbles=\"active\"] .hb-qn8-thumb[data-which=\"max\"]:hover .hb-qn8-bub,\n.hb-qn8[data-bubbles=\"active\"] .hb-qn8-thumb[data-which=\"max\"]:focus-visible .hb-qn8-bub,\n.hb-qn8[data-bubbles=\"active\"] .hb-qn8-thumb[data-which=\"max\"][data-active=\"true\"] .hb-qn8-bub { transform: translateX(-38%) translateY(0); }\n@media (prefers-reduced-motion: reduce) {\n  .hb-qn8-thumb, .hb-qn8-bub { transition: none; }\n}\n`;\n\nfunction clamp(n: number, lo: number, hi: number) {\n  return Math.min(hi, Math.max(lo, n));\n}\n\nexport function SliderRangeDual({\n  min = 0,\n  max = 100,\n  step = 1,\n  value,\n  defaultValue = [25, 75],\n  onValueChange,\n  minGap = 0,\n  formatValue,\n  bubbles = \"always\",\n  label = \"Range\",\n  name,\n  disabled = false,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: SliderRangeDualProps) {\n  const controlled = value !== undefined;\n  const [inner, setInner] = React.useState<[number, number]>(defaultValue);\n  const current = controlled ? value : inner;\n  const [lo, hi] = current;\n  const valueRef = React.useRef<[number, number]>(current);\n  const hitRef = React.useRef<HTMLDivElement>(null);\n  const thumbs = React.useRef<(HTMLDivElement | null)[]>([null, null]);\n  const dragging = React.useRef<0 | 1 | null>(null);\n  const [active, setActive] = React.useState<0 | 1 | null>(null);\n\n  React.useEffect(() => {\n    valueRef.current = current;\n  });\n\n  const span = Math.max(max - min, Number.EPSILON);\n  const pct = (n: number) => ((clamp(n, min, max) - min) / span) * 100;\n  const show = (n: number) => (formatValue ? formatValue(n) : String(n));\n  const decimals = (String(step).split(\".\")[1] ?? \"\").length;\n\n  function snap(raw: number) {\n    const stepped = Math.round((raw - min) / step) * step + min;\n    return clamp(Number(stepped.toFixed(decimals)), min, max);\n  }\n\n  function setThumb(index: 0 | 1, raw: number) {\n    const [a, b] = valueRef.current;\n    const nv = snap(raw);\n    const next: [number, number] =\n      index === 0 ? [clamp(nv, min, Math.max(min, b - minGap)), b] : [a, clamp(nv, Math.min(max, a + minGap), max)];\n    if (next[0] === a && next[1] === b) return;\n    valueRef.current = next;\n    if (!controlled) setInner(next);\n    onValueChange?.(next);\n  }\n\n  function fromPointer(clientX: number) {\n    const rect = hitRef.current?.getBoundingClientRect();\n    if (!rect || rect.width === 0) return min;\n    return min + clamp((clientX - rect.left) / rect.width, 0, 1) * (max - min);\n  }\n\n  function grab(index: 0 | 1, e: React.PointerEvent<HTMLDivElement>) {\n    dragging.current = index;\n    setActive(index);\n    const el = thumbs.current[index];\n    el?.setPointerCapture(e.pointerId);\n    el?.focus({ preventScroll: true });\n  }\n\n  function onTrackDown(e: React.PointerEvent<HTMLDivElement>) {\n    if (disabled || e.button !== 0) return;\n    if ((e.target as HTMLElement).closest(\"[data-hb-qn8-thumb]\")) return;\n    const raw = fromPointer(e.clientX);\n    const [a, b] = valueRef.current;\n    const index: 0 | 1 = Math.abs(raw - a) < Math.abs(raw - b) || (a === b && raw < a) ? 0 : 1;\n    setThumb(index, raw);\n    grab(index, e);\n  }\n\n  function onThumbDown(index: 0 | 1, e: React.PointerEvent<HTMLDivElement>) {\n    if (disabled || e.button !== 0) return;\n    e.preventDefault();\n    grab(index, e);\n  }\n\n  function onThumbMove(index: 0 | 1, e: React.PointerEvent<HTMLDivElement>) {\n    if (dragging.current !== index) return;\n    setThumb(index, fromPointer(e.clientX));\n  }\n\n  function release() {\n    dragging.current = null;\n    setActive(null);\n  }\n\n  function onThumbKey(index: 0 | 1, e: React.KeyboardEvent<HTMLDivElement>) {\n    const now = valueRef.current[index];\n    let next: number | null = null;\n    if (e.key === \"ArrowRight\" || e.key === \"ArrowUp\") next = now + step;\n    else if (e.key === \"ArrowLeft\" || e.key === \"ArrowDown\") next = now - step;\n    else if (e.key === \"PageUp\") next = now + step * 10;\n    else if (e.key === \"PageDown\") next = now - step * 10;\n    else if (e.key === \"Home\") next = min;\n    else if (e.key === \"End\") next = max;\n    if (next === null) return;\n    e.preventDefault();\n    setThumb(index, next);\n  }\n\n  const vars = { \"--hb-qn8-a\": accent, ...style } as React.CSSProperties;\n  return (\n    <>\n      <style href=\"hb-slider-range-dual\" precedence=\"default\">{css}</style>\n      <div\n        className={`hb-qn8 ${className}`}\n        style={vars}\n        data-bubbles={bubbles}\n        data-disabled={disabled}\n        {...rest}\n      >\n        <div ref={hitRef} className=\"hb-qn8-hit\" onPointerDown={onTrackDown}>\n          <div className=\"hb-qn8-rail\" />\n          <div className=\"hb-qn8-fill\" style={{ left: `${pct(lo).toFixed(3)}%`, width: `${(pct(hi) - pct(lo)).toFixed(3)}%` }} />\n          {([0, 1] as const).map((index) => (\n            <div\n              key={index}\n              ref={(el) => {\n                thumbs.current[index] = el;\n              }}\n              className=\"hb-qn8-thumb\"\n              style={{ left: `${pct(current[index]).toFixed(3)}%` }}\n              role=\"slider\"\n              tabIndex={disabled ? -1 : 0}\n              aria-orientation=\"horizontal\"\n              aria-valuemin={index === 0 ? min : Math.min(max, lo + minGap)}\n              aria-valuemax={index === 0 ? Math.max(min, hi - minGap) : max}\n              aria-valuenow={current[index]}\n              aria-valuetext={show(current[index])}\n              aria-label={`${label} ${index === 0 ? \"minimum\" : \"maximum\"}`}\n              aria-disabled={disabled || undefined}\n              data-hb-qn8-thumb=\"\"\n              data-which={index === 0 ? \"min\" : \"max\"}\n              data-active={active === index}\n              onPointerDown={(e) => onThumbDown(index, e)}\n              onPointerMove={(e) => onThumbMove(index, e)}\n              onPointerUp={release}\n              onPointerCancel={release}\n              onLostPointerCapture={release}\n              onKeyDown={(e) => onThumbKey(index, e)}\n            >\n              {bubbles !== \"none\" ? <span className=\"hb-qn8-bub\">{show(current[index])}</span> : null}\n            </div>\n          ))}\n        </div>\n        {name ? (\n          <>\n            <input type=\"hidden\" name={`${name}-min`} value={lo} />\n            <input type=\"hidden\" name={`${name}-max`} value={hi} />\n          </>\n        ) : null}\n      </div>\n    </>\n  );\n}\n"
    }
  ]
}