audiocn-svelte
Esc

Start typing to search the docs

Bar Visualizer

A row of bars driven by frequency bands, with idle, loading and mirrored modes.

2 min read · 328 words

Installation

$ pnpm dlx shadcn-svelte@latest add https://juddisjudd.github.io/audiocn-svelte/r/bar-visualizer.json

Usage

<script lang="ts">
	import { BarVisualizer } from "#lib/components/ui/bar-visualizer/index.js";
</script>

<BarVisualizer aria-label="Voice activity" source={analyser.visual} />

Bars take their color from the text color, so set it with a class such as text-primary. Bars paint on the animation frame without going through Svelte state.

Examples

Alignment

center
end
start

Idle and loading

idle decides what bars do without a signal. loading runs a sweep, for connecting or thinking states.

idle pulse
idle wave
loading

Mirrored

Inside a badge

Live

Theming

Variable or attributeMeaning
--bar-widthMaximum bar width, default 0.375rem
--bar-gapGap between bars, default 0.1875rem
--bar-radiusBar corner radius, default fully rounded
data-activeThe signal is above the floor
data-loadingThe sweep is running
data-indexOn each bar, its position

Accessibility

The root has role="img" and the label "Audio visualizer". Pass aria-label to describe what it shows, or aria-hidden when it is decorative next to a labelled meter.

API reference

PropTypeDefault
source

Bars follow the frame's frequency bands.

FrameSource<VisualFrame> | null—
levels

Levels, 0..1, for declarative use.

ArrayLike<number>—
barCount

Bands are resampled to fit.

number24
align

Where bars grow from.

"center" | "start" | "end""center"
mirrored

Symmetric around the middle bar, lows in the centre.

booleanfalse
minLevel

Resting bar size, 0..1.

number0.08
idle

What bars do without a signal.

"static" | "pulse" | "wave""static"
loading

Run a sweep animation.

booleanfalse
orientation

vertical grows bars sideways.

"horizontal" | "vertical""horizontal"

Exported functions

Bind the component with bind:this to call them. Their type is BarVisualizerActions.

PropTypeDefault
paint

Paint levels, 0..1, directly. They are resampled to the bar count.

(levels: ArrayLike<number>) => void—
Last updated on October 7, 2026