{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bar-visualizer",
  "title": "Bar Visualizer",
  "description": "Frequency-band bars with idle, loading and mirrored modes.",
  "dependencies": [
    "solid-js@^1.9.15"
  ],
  "registryDependencies": [
    "@audiocn-solid/core",
    "@audiocn-solid/use-audio-config",
    "@audiocn-solid/use-frame-source",
    "@audiocn-solid/use-reduced-motion",
    "@audiocn-solid/use-visibility"
  ],
  "files": [
    {
      "path": "components/ui/bar-visualizer.tsx",
      "content": "import { For, createMemo } from \"solid-js\";\n\nimport { useAudioConfig } from \"@/hooks/use-audio-config\";\nimport { useFrameSource } from \"@/hooks/use-frame-source\";\nimport { useReducedMotion } from \"@/hooks/use-reduced-motion\";\nimport { useVisibility } from \"@/hooks/use-visibility\";\nimport { createBarLevels } from \"@/lib/audio/bar-levels\";\nimport type { BarIdle } from \"@/lib/audio/bar-levels\";\nimport { createFrameTask, createPainterClock } from \"@/lib/audio/frame-loop\";\nimport type { FrameSource, Orientation, VisualFrame } from \"@/lib/audio/types\";\nimport { createCompatEffect } from \"@/lib/solid/effect\";\nimport type { DivDOMProps } from \"@/lib/solid/jsx-types\";\nimport { omitProps } from \"@/lib/solid/props\";\nimport { setRefValue } from \"@/lib/solid/ref\";\nimport type { RefTarget } from \"@/lib/solid/ref\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface BarVisualizerActions {\n  paint: (levels: ArrayLike<number>) => void;\n}\n\nexport interface BarVisualizerProps extends Omit<DivDOMProps, \"ref\"> {\n  className?: string;\n  ref?: RefTarget<HTMLDivElement>;\n  source?: FrameSource<VisualFrame> | null;\n  levels?: ArrayLike<number>;\n  barCount?: number;\n  align?: \"center\" | \"start\" | \"end\";\n  mirrored?: boolean;\n  minLevel?: number;\n  idle?: BarIdle;\n  loading?: boolean;\n  orientation?: Orientation;\n  actionsRef?: RefTarget<BarVisualizerActions>;\n}\n\nconst ALIGN_CLASS = {\n  center: \"items-center\",\n  end: \"items-end\",\n  start: \"items-start\",\n};\n\nconst noop = () => {};\n\nexport const BarVisualizer = (props: BarVisualizerProps) => {\n  const config = useAudioConfig();\n  const reducedMotion = useReducedMotion();\n\n  const orientation = () =>\n    props.orientation ?? config.orientation ?? \"horizontal\";\n\n  const count = () => props.barCount ?? 24;\n\n  const indexes = createMemo(() =>\n    Array.from({ length: count() }, (_, index) => index)\n  );\n\n  let root: HTMLDivElement | undefined;\n  const bars: HTMLSpanElement[] = [];\n  let input: ArrayLike<number> | null = null;\n  let wake = noop;\n  let hadLevels = false;\n\n  const visible = useVisibility(\n    () => root ?? null,\n    (shown) => {\n      if (shown) wake();\n    }\n  );\n\n  const paint = (levels: ArrayLike<number>) => {\n    input = levels;\n    wake();\n  };\n\n  useFrameSource(\n    () => props.source,\n    (frame) => paint(frame.bands)\n  );\n  createCompatEffect(\n    () => props.levels,\n    (levels) => {\n      if (levels) {\n        input = levels;\n        hadLevels = true;\n      } else if (hadLevels) {\n        input = null;\n        hadLevels = false;\n      }\n\n      wake();\n    }\n  );\n  createCompatEffect(\n    () => props.actionsRef,\n    (ref) => {\n      setRefValue(ref, { paint });\n\n      return () => setRefValue(ref, null);\n    }\n  );\n  createCompatEffect(\n    () => ({\n      barCount: count(),\n      idle: props.idle ?? \"static\",\n      loading: props.loading ?? false,\n      minLevel: props.minLevel ?? 0.08,\n      mirrored: props.mirrored ?? false,\n      reducedMotion: reducedMotion(),\n    }),\n    (options) => {\n      const levels = createBarLevels(options);\n      const shown = new Float32Array(options.barCount).fill(-1);\n      const clock = createPainterClock();\n      let lastPaint = Number.NEGATIVE_INFINITY;\n      let activeShown: boolean | null = null;\n\n      const task = createFrameTask((frameMs) => {\n        if (!visible.current) return false;\n        const now = clock(frameMs);\n\n        if (options.reducedMotion && now - lastPaint < 250) return true;\n        lastPaint = now;\n        const active = levels.step(now, input);\n\n        if (active !== activeShown) {\n          activeShown = active;\n          root?.toggleAttribute(\"data-active\", active);\n        }\n\n        for (const [index, value] of levels.levels.entries()) {\n          if (Math.abs(value - shown[index]) > 0.002) {\n            shown[index] = value;\n            bars[index]?.style.setProperty(\"--bar-level\", value.toFixed(4));\n          }\n        }\n\n        return !levels.settled;\n      });\n\n      wake = task.wake;\n      task.wake();\n\n      return () => {\n        wake = noop;\n        task.stop();\n        root?.removeAttribute(\"data-active\");\n      };\n    }\n  );\n\n  const rest = omitProps(props, [\n    \"class\",\n    \"className\",\n    \"ref\",\n    \"source\",\n    \"levels\",\n    \"barCount\",\n    \"align\",\n    \"mirrored\",\n    \"minLevel\",\n    \"idle\",\n    \"loading\",\n    \"orientation\",\n    \"actionsRef\",\n  ]);\n\n  return (\n    <div\n      aria-label=\"Audio visualizer\"\n      class={cn(\n        \"flex justify-center gap-(--bar-gap) [--bar-gap:0.1875rem] [--bar-radius:9999px] [--bar-width:0.375rem]\",\n        orientation() === \"horizontal\"\n          ? \"h-16 w-full flex-row\"\n          : \"h-full w-16 flex-col\",\n        ALIGN_CLASS[props.align ?? \"center\"],\n        props.class,\n        props.className\n      )}\n      data-loading={props.loading ? \"\" : undefined}\n      data-orientation={orientation()}\n      data-slot=\"bar-visualizer\"\n      role=\"img\"\n      {...rest}\n      ref={(node: HTMLDivElement) => {\n        root = node;\n        setRefValue(props.ref, node);\n      }}\n    >\n      <For each={indexes()}>\n        {(index) => (\n          <span\n            class={cn(\n              \"rounded-(--bar-radius) bg-current\",\n              orientation() === \"horizontal\"\n                ? \"h-[calc(var(--bar-level)*100%)] max-w-(--bar-width) min-w-0 flex-1\"\n                : \"max-h-(--bar-width) min-h-0 w-[calc(var(--bar-level)*100%)] flex-1\"\n            )}\n            data-index={index}\n            data-slot=\"bar-visualizer-bar\"\n            ref={(node: HTMLSpanElement) => {\n              bars[index] = node;\n            }}\n            style={{ \"--bar-level\": props.minLevel ?? 0.08 }}\n          />\n        )}\n      </For>\n    </div>\n  );\n};\n",
      "type": "registry:ui"
    },
    {
      "path": "lib/audiocn-license.txt",
      "content": "Audio component source adapted from https://github.com/audiocn/ui.\nMIT License — Copyright (c) 2026 OrcDev\n\nRegular SVG icon geometry adapted from @phosphor-icons/react 2.1.10.\nMIT License — Copyright (c) 2020 Phosphor Icons\n\nThe following permission and warranty terms apply to both notices.\nRetain this file with copies or substantial portions of the source.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
      "type": "registry:file",
      "target": "@lib/audiocn-license.txt"
    }
  ],
  "type": "registry:ui"
}
