Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

audio-visualizer

Canvas-based audio visualization that pairs with any <audio> element via the for attribute. Supports bars, waveform, and circle modes.

Overview

A companion component that draws canvas-based audio visualizations. It connects to any <audio> element by ID via the for attribute — mirroring the <label for=""> pattern.

Separated from <audio-player> so it can be independently positioned, omitted, or paired with a plain <audio> element.

Visualization Modes

Bars (default)

Classic frequency bar chart equalizer. Press play to see the visualization.

Waveform

Time-domain oscilloscope line, drawn from all fftSize samples.

Circle

Radial frequency display.

Paired with audio-player

The visualizer works alongside <audio-player> — just give the inner <audio> an ID.

Attributes

AttributeRequiredDefaultDescription
forYes--ID of the target <audio> element
data-modeNobarsVisualization style: bars, waveform, circle (unknown values fall back to bars). This is the visualizer's own drawing mode, not the colour mode
data-fft-sizeNo256AnalyserNode FFT size (power of 2, 32-32768). Other values are rounded to the nearest power of two and clamped to that range
data-stateSet by component--cross-origin when the source is cross-origin without CORS (see below), error if Web Audio could not connect. Absent while visualizing

CSS Custom Properties

PropertyDefaultDescription
--audio-visualizer-colorvar(--color-primary)Bar / waveform draw color
--audio-visualizer-bgvar(--color-surface-sunken)Canvas background
--audio-visualizer-height80pxCanvas block size
--audio-visualizer-radiusvar(--radius-m)Canvas border radius

Behavior

  • Lazy AudioContext — created on first play event, respects browser autoplay policy
  • Shared AudioContext — multiple visualizers on one page share a single context (browsers cap at ~6)
  • Off-screen pause — stops canvas rendering via IntersectionObserver when not visible
  • Reduced motion — with prefers-reduced-motion: reduce the canvas does not animate: it shows a single static frame (a flat baseline before playback) instead of a blank box, and audio continues playing. Turning the preference off mid-playback resumes the animation
  • Idle baseline — before playback starts the canvas draws a flat baseline in the current mode, so the box is never empty
  • Cheap frames — the canvas context, resolved colours and sample buffers are cached. The canvas is resized with a ResizeObserver, and colours are re-read on vb:theme-change and colour-scheme changes rather than every frame
  • Live attributes — changing data-mode or data-fft-size takes effect immediately; changing for after playback started drops the tap on the old <audio> and binds to the new one on its next play
  • One output path per audio — several visualizers can share one <audio>; the element is routed to the speakers once and each visualizer only taps it, so volume is unchanged. Hooking is permanent for the page (a Web Audio rule): from the first play the <audio> plays through the shared AudioContext, even after the visualizer is removed or retargeted
  • Survives DOM moves — moving the element re-arms visibility tracking and resumes drawing
  • Graceful fallback — if AudioContext is unavailable it renders nothing; if the audio cannot be hooked it sets data-state and logs a console warning instead of throwing, and playback is not interrupted

Cross-Origin Audio (CORS)

Web Audio can only read samples from media the page is allowed to read. Hooking a cross-origin <audio> that was loaded without CORS would make the browser output silence, so the visualizer refuses: it leaves the audio untouched (it keeps playing normally), sets data-state="cross-origin" and logs one console warning.

To visualize audio from another origin, add crossorigin="anonymous" to the <audio> and serve the file with an Access-Control-Allow-Origin header that permits your page. Same-origin, data: and blob: sources need nothing extra.

Progressive Enhancement

Without JS, the visualizer renders nothing — the <audio> plays normally. The visualizer is pure enhancement with no impact on audio functionality.

The :not(:defined) CSS rule hides the element before JS loads, preventing a flash of unstyled content.

Accessibility

  • Canvas is aria-hidden="true" — purely decorative
  • Respects prefers-reduced-motion: a static frame instead of animation
  • Does not interfere with audio element controls or keyboard navigation

Related

↑