{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "vintage-eq",
  "title": "Vintage EQ",
  "author": "Visant Labs <visantsupply@gmail.com>",
  "description": "Banco de faders com curva desenhada.",
  "registryDependencies": [
    "@visant/vintage-theme",
    "utils",
    "@visant/sfx-bus"
  ],
  "files": [
    {
      "path": "registry/vintage/ui/vintage-eq.tsx",
      "content": "\"use client\";\n\nimport { useState, useEffect, useCallback, useRef } from \"react\";\nimport { cn } from \"@/lib/utils\";\nimport { playSfx } from \"@/lib/sfx-bus\";\n\ninterface VintageEQProps {\n  labels?: string[];\n  title?: string;\n  values?: number[];\n  accent?: string;\n  onChange?: (values: number[]) => void;\n  className?: string;\n}\n\nexport function VintageEQ({\n  labels = [\"63Hz\", \"125Hz\", \"250Hz\", \"500Hz\", \"1kHz\", \"2kHz\"],\n  title = \"GRAPHIC EQ\",\n  values: initialValues,\n  accent,\n  onChange,\n  className,\n}: VintageEQProps) {\n  const [values, setValues] = useState(\n    initialValues ?? labels.map(() => 5)\n  );\n  const [draggingIndex, setDraggingIndex] = useState<number | null>(null);\n  const [hoverIndex, setHoverIndex] = useState<number | null>(null);\n\n  /*\n   * Um caminho só pra mudar uma banda — ponteiro, roda e teclado passam aqui.\n   *\n   * O próximo estado sai do ref, FORA de um updater de `setValues`: o\n   * `onChange` do pai morava dentro do updater, que o React chama durante o\n   * render (e duas vezes em modo estrito), e o pai ganhava `setState` no meio\n   * do render do EQ.\n   */\n  const valuesRef = useRef(values);\n  valuesRef.current = values;\n  const onChangeRef = useRef(onChange);\n  onChangeRef.current = onChange;\n  const definir = useCallback((index: number, v: number) => {\n    const next = [...valuesRef.current];\n    next[index] = Math.max(0, Math.min(10, v));\n    // Estalo a cada 1/20 do curso da banda. `definir` só é chamado pela mão.\n    if (Math.round(next[index] * 2) !== Math.round(valuesRef.current[index] * 2)) {\n      playSfx(\"detent\");\n    }\n    valuesRef.current = next;\n    setValues(next);\n    onChangeRef.current?.(next);\n  }, []);\n\n  const updateValue = useCallback(\n    (index: number, clientY: number, fine: boolean) => {\n      const slider = document.getElementById(`vintage-eq-slider-${index}`);\n      if (!slider) return;\n      const rect = slider.getBoundingClientRect();\n      const pct = 1 - Math.max(0, Math.min(1, (clientY - rect.top) / rect.height));\n      const raw = pct * 10;\n      definir(index, fine ? Math.round(raw * 100) / 100 : Math.round(raw * 10) / 10);\n    },\n    [definir]\n  );\n\n  /* Teclado: o fader era só do mouse. Seta = 0,1 (Shift = 0,02, o fino da\n     roda), Page = 1, Home/End = limites. */\n  const handleKeyDown = (index: number, e: React.KeyboardEvent) => {\n    const passo = e.shiftKey ? 0.02 : 0.1;\n    const atual = valuesRef.current[index];\n    let v: number | null = null;\n    if (e.key === \"ArrowUp\" || e.key === \"ArrowRight\") v = atual + passo;\n    else if (e.key === \"ArrowDown\" || e.key === \"ArrowLeft\") v = atual - passo;\n    else if (e.key === \"PageUp\") v = atual + 1;\n    else if (e.key === \"PageDown\") v = atual - 1;\n    else if (e.key === \"Home\") v = 0;\n    else if (e.key === \"End\") v = 10;\n    if (v === null) return;\n    e.preventDefault();\n    e.stopPropagation();\n    definir(index, Math.round(v * 100) / 100);\n  };\n\n  useEffect(() => {\n    if (draggingIndex === null) return;\n    const onMove = (e: PointerEvent) =>\n      updateValue(draggingIndex, e.clientY, e.shiftKey);\n    const onUp = () => setDraggingIndex(null);\n    document.addEventListener(\"pointermove\", onMove);\n    document.addEventListener(\"pointerup\", onUp);\n    document.addEventListener(\"pointercancel\", onUp);\n    return () => {\n      document.removeEventListener(\"pointermove\", onMove);\n      document.removeEventListener(\"pointerup\", onUp);\n      document.removeEventListener(\"pointercancel\", onUp);\n    };\n  }, [draggingIndex, updateValue]);\n\n  const handleWheel = (index: number, e: React.WheelEvent) => {\n    e.stopPropagation();\n    const step = e.shiftKey ? 0.02 : 0.1;\n    const dir = e.deltaY < 0 ? 1 : -1;\n    definir(index, valuesRef.current[index] + dir * step);\n  };\n\n  const handleDoubleClick = (index: number) => definir(index, 5);\n\n  const gravado = \"var(--vintage-engrave)\";\n  const cor = accent || \"var(--vintage-light)\";\n\n  return (\n    <div\n      className={cn(\n        \"inline-flex flex-col items-center gap-3 rounded-[var(--r-control,10px)] px-5 pt-3 pb-4\",\n        className\n      )}\n      style={{\n        // O painel do kit: chapa escura, luz de cima, sombra que fecha embaixo.\n        background: \"linear-gradient(180deg, var(--vintage-surface-3), var(--vintage-surface-2))\",\n        border: \"1px solid var(--vintage-surface-1)\",\n        boxShadow:\n          \"var(--vintage-panel-shadow)\",\n      }}\n    >\n      <h3\n        className=\"font-vintage-mono text-[10px] font-semibold uppercase tracking-[0.18em]\"\n        style={{ color: \"var(--vintage-text-muted)\", textShadow: gravado }}\n      >\n        {title}\n      </h3>\n      <div className=\"flex items-end gap-3\">\n        {labels.map((label, index) => {\n          const isActive = draggingIndex === index || hoverIndex === index;\n          return (\n            <div\n              key={index}\n              className=\"flex flex-col items-center gap-2\"\n              onMouseEnter={() => setHoverIndex(index)}\n              onMouseLeave={() => setHoverIndex(null)}\n            >\n              <span\n                className=\"font-vintage-mono text-[10px] tabular-nums leading-none\"\n                style={{\n                  color: isActive ? \"var(--vintage-value)\" : \"var(--vintage-text-muted)\",\n                  transition: \"color var(--dur-fast,160ms) var(--ease-out,ease)\",\n                }}\n              >\n                {values[index].toFixed(1)}\n              </span>\n\n              <div\n                id={`vintage-eq-slider-${index}`}\n                className=\"relative h-[168px] w-8 pointer-coarse:after:absolute pointer-coarse:after:-inset-x-1.5 pointer-coarse:after:inset-y-0 select-none rounded-[4px] outline-none focus-visible:[box-shadow:var(--focus,0_0_0_2px_var(--vintage-value))]\"\n                style={{ cursor: draggingIndex === index ? \"grabbing\" : \"grab\", touchAction: \"pan-x\" }}\n                tabIndex={0}\n                role=\"slider\"\n                aria-label={label}\n                aria-orientation=\"vertical\"\n                aria-valuemin={0}\n                aria-valuemax={10}\n                aria-valuenow={Number(values[index].toFixed(2))}\n                aria-valuetext={values[index].toFixed(1)}\n                onKeyDown={(e) => handleKeyDown(index, e)}\n                onPointerDown={(e) => {\n                  setDraggingIndex(index);\n                  updateValue(index, e.clientY, e.shiftKey);\n                }}\n                onWheel={(e) => handleWheel(index, e)}\n                onDoubleClick={() => handleDoubleClick(index)}\n                title={`${label}: ${values[index].toFixed(1)}\\narraste · shift = fino · roda · duplo clique = centro`}\n              >\n                {/* Régua serigrafada dos dois lados do rasgo; o 0 dB é maior. */}\n                <div className=\"pointer-events-none absolute inset-y-[7px] inset-x-0 flex flex-col justify-between\">\n                  {Array.from({ length: 11 }, (_, i) => (\n                    <div key={i} className=\"flex justify-between\">\n                      {[0, 1].map((lado) => (\n                        <span\n                          key={lado}\n                          className=\"block h-px\"\n                          style={{\n                            width: i === 5 ? 8 : i % 5 === 0 ? 6 : 4,\n                            background: \"var(--vintage-text-muted)\",\n                            opacity: i === 5 ? 0.8 : 0.4,\n                          }}\n                        />\n                      ))}\n                    </div>\n                  ))}\n                </div>\n\n                {/* O rasgo na chapa. */}\n                <div\n                  className=\"absolute inset-y-0 left-1/2 w-[6px] -translate-x-1/2 rounded-full\"\n                  style={{\n                    background: \"var(--vintage-surface-1)\",\n                    boxShadow: \"inset 0 1px 2px rgba(0,0,0,0.9), 0 1px 0 var(--vintage-lip)\",\n                  }}\n                />\n\n                {/* Capa do fader: metal escovado, frisos, sombra pra baixo. */}\n                <div\n                  className=\"absolute left-1/2 h-[14px] w-[26px] -translate-x-1/2 rounded-[3px] pointer-events-none\"\n                  style={{\n                    bottom: `calc(${(values[index] / 10) * 100}% - 7px)`,\n                    background:\n                      \"linear-gradient(180deg, var(--vintage-metal-channel-light) 0%, var(--vintage-metal-mid) 48%, var(--vintage-metal-light) 52%, var(--vintage-metal-channel-dark) 100%)\",\n                    boxShadow: isActive\n                      ? `inset 0 1px 0 rgba(255,255,255,0.6), 0 0 0 1px var(--vintage-edge), 0 3px 4px rgba(0,0,0,0.55), 0 0 8px color-mix(in srgb, ${cor} 35%, transparent)`\n                      : \"inset 0 1px 0 rgba(255,255,255,0.6), 0 0 0 1px var(--vintage-edge), 0 3px 4px rgba(0,0,0,0.55)\",\n                    transition: \"box-shadow var(--dur-fast,160ms) var(--ease-out,ease)\",\n                  }}\n                >\n                  <div\n                    className=\"absolute inset-x-[4px] top-1/2 h-[2px] -translate-y-1/2\"\n                    style={{ background: \"rgba(0,0,0,0.6)\" }}\n                  />\n                </div>\n              </div>\n\n              <span\n                className=\"font-vintage-mono text-[9px] font-semibold tracking-[0.08em] leading-none\"\n                style={{ color: \"var(--vintage-text-muted)\", textShadow: gravado }}\n              >\n                {label}\n              </span>\n            </div>\n          );\n        })}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "uso": {
      "quando": "Equalizador gráfico de bandas fixas em app de áudio, cada banda um fader com a curva desenhada",
      "evite": "Precisa de sino, Q e frequência livre por banda: use vintage-parametric-eq"
    }
  },
  "categories": [
    "controles",
    "audio",
    "eq",
    "faders",
    "grafico"
  ],
  "type": "registry:ui"
}