components / spectrum

spectrum.

live frequency analyser off a web audio AnalyserNode (or any sample callback). canvas, logarithmically-spaced columns, instant attack and gradual decay so it reads as loudness instead of strobing. waveform is the static counterpart — a shape that never repaints.

installation
bunx @justin06lee/chrome@latest add spectrum
props
nametypedefaultdescription
analyserAnalyserNode-web audio analyser to read; create it once and hand it over, the component only reads.
sample(time: number) => number[]-escape hatch for anything that isn't a web audio graph — return `bars` magnitudes in 0–1 per frame. ignored when analyser is set.
barsnumber40column count.
heightnumber64
barWidthnumber6widest a column may get; columns flex to fill.
gapnumber2
accentstring'#fff'
mirrorbooleanfalsemirror the columns around the centre line.
decaynumber0.12fall speed per frame, 0–1. lower falls slower.
peakHoldbooleantruehold a thin cap at each column's recent maximum.
pausedbooleanfalsestop reading and let the columns settle to the floor.
ariaLabelstring'audio spectrum'
classNamestring-