Waveform
Draws an audio clip's shape from peak values you supply, and doubles as a seek control.
<arc-waveform>Overview
Waveform draws an audio clip's shape from an array of peak amplitudes (one number per bar, 0 to 1) and marks playback progress on it. The played region is in the accent color with a soft glow, the unplayed region is muted, and a thin glowing playhead sits at the current position. Set interactive and the same element becomes a scrubber, with pointer dragging, keyboard seeking and slider semantics for assistive technology. variant="bars" draws one bar per peak, centered on the middle line, and mirror draws a filled min/max envelope.
The component doesn't load, decode or play audio. You compute the peaks however you like (from a decoded buffer, a server-side analysis pass or a cached sidecar file) and pass them as the peaks property. The SVG depends only on its props, so it renders on the server.
position is a fraction of the total (0 to 1), not seconds. If your player thinks in seconds, divide by the duration on the way in and multiply on the way out. With duration set, the time field on both event details does the multiplying for you, a monospace time readout appears below the track, and screen readers hear elapsed and total time instead of a percentage.
While the reader scrubs, arc-input fires on every pointer move with the live position, and arc-change fires once on release with the final one, as with ARC UI's other inputs. Seek your audio source on arc-change, and use arc-input for live feedback such as a time display or audible scrubbing.
Guidelines
Do
- Compute peaks once per clip and cache them. A few dozen to a few hundred values is plenty, and each is clamped to 0 to 1
- Set `duration` whenever you know it
- Give every waveform a `label`. It names the slider, or describes the image when the waveform isn't interactive
- Use `bars` for scrubbers and player UI, and `mirror` for dense timeline lanes where separate bars would shimmer
- Set the height with `--waveform-height` when the default doesn't suit its row
Don't
- Don't use it for general trend data. Use Sparkline. The mirrored geometry distorts ordinary series
- Don't use it as a level indicator or progress bar. Meter shows one current value against a range
- Don't feed it raw sample data. Downsample to peaks first. In `bars`, every peak is its own SVG element
- Don't seek your audio source on `arc-input`. It fires on every pointer move
Features
- Keyboard seeking with the arrow keys, PageUp and PageDown, and Home and End
- `steps` divides the track into discrete frames, and the arrow keys move one step
- `value-text` replaces the screen reader wording with your own
- A slider when interactive, and a labeled image otherwise
- Scales with its SVG viewBox, so it fits any width without measuring
- Empty or missing peaks render an empty track, not an error
Preview
Usage
Waveform is in the media group, so the default @arclux/arc-ui entry point doesn't include it. Import it from@arclux/arc-ui/media or from its own subpath,@arclux/arc-ui/waveform.
Its events and state need JavaScript, so use the Web Component or a framework wrapper for those.
<script type="module" src="@arclux/arc-ui"></script>
<!-- Interactive scrubber with time readouts -->
<arc-waveform id="scrubber" interactive duration="212" label="Track position"></arc-waveform>
<!-- Static clip preview, mirror envelope -->
<arc-waveform id="clip" variant="mirror" position="0.6" label="Vocal take"></arc-waveform>
<script type="module">
const scrubber = document.getElementById('scrubber');
// Peaks are a property, not an attribute — you compute them (0..1 per bar).
scrubber.peaks = await fetchPeaks('track-7');
scrubber.addEventListener('arc-input', (e) => {
// Live position while dragging: e.detail.value is 0..1,
// e.detail.time is seconds because duration is set.
timeDisplay.textContent = format(e.detail.time);
});
scrubber.addEventListener('arc-change', (e) => {
audio.currentTime = e.detail.time; // seek once, on release
});
// Follow playback
audio.addEventListener('timeupdate', () => {
scrubber.position = audio.currentTime / audio.duration;
});
</script>import { Waveform } from '@arclux/arc-ui-react';
export function TrackScrubber({ peaks, audio }: { peaks: number[]; audio: HTMLAudioElement }) {
return (
<Waveform
peaks={peaks}
duration={audio.duration}
position={audio.currentTime / audio.duration}
interactive
label="Track position"
onArcInput={(e) => console.log('Live:', e.detail.time)}
onArcChange={(e) => { audio.currentTime = e.detail.time; }}
/>
);
}<script setup>
import { Waveform } from '@arclux/arc-ui-vue';
import { ref } from 'vue';
const peaks = ref([0.2, 0.5, 0.9, 0.4, 0.7, 0.3, 0.8]);
const position = ref(0);
</script>
<template>
<Waveform
:peaks="peaks"
:position="position"
:duration="212"
interactive
label="Track position"
@arc-input="(e) => console.log('Live:', e.detail.time)"
@arc-change="(e) => seek(e.detail.time)"
/>
</template><script>
import { Waveform } from '@arclux/arc-ui-svelte';
let peaks = [0.2, 0.5, 0.9, 0.4, 0.7, 0.3, 0.8];
let position = 0;
</script>
<Waveform
{peaks}
{position}
duration={212}
interactive
label="Track position"
on:arc-input={(e) => console.log('Live:', e.detail.time)}
on:arc-change={(e) => seek(e.detail.time)}
/>import { Component } from '@angular/core';
import { Waveform } from '@arclux/arc-ui-angular';
@Component({
imports: [Waveform],
template: `
<arc-waveform
[peaks]="peaks"
[position]="position"
duration="212"
interactive
label="Track position"
(arc-input)="onScrub($event)"
(arc-change)="onSeek($event)"
></arc-waveform>
`,
})
export class TrackScrubberComponent {
peaks = [0.2, 0.5, 0.9, 0.4, 0.7, 0.3, 0.8];
position = 0;
onScrub(e: CustomEvent) { console.log('Live:', e.detail.time); }
onSeek(e: CustomEvent) { this.position = e.detail.value; }
}import { Waveform } from '@arclux/arc-ui-solid';
import { createSignal } from 'solid-js';
export function TrackScrubber() {
const [position, setPosition] = createSignal(0);
const peaks = [0.2, 0.5, 0.9, 0.4, 0.7, 0.3, 0.8];
return (
<Waveform
peaks={peaks}
position={position()}
duration={212}
interactive
label="Track position"
onArcChange={(e) => setPosition(e.detail.value)}
/>
);
}import { Waveform } from '@arclux/arc-ui-preact';
import { useState } from 'preact/hooks';
export function TrackScrubber() {
const [position, setPosition] = useState(0);
const peaks = [0.2, 0.5, 0.9, 0.4, 0.7, 0.3, 0.8];
return (
<Waveform
peaks={peaks}
position={position}
duration={212}
interactive
label="Track position"
onArcChange={(e) => setPosition(e.detail.value)}
/>
);
}API
labelstring''- Accessible name for the waveform. Announced as the slider label when interactive, or as the image description otherwise.
peaksArray[]- Peak amplitudes as a number array, each value 0 to 1. Set it from script, a framework binding, or a JSON attribute. Values outside the range are clamped. An empty or missing array renders an empty track.
positionnumber0- Current playhead position as a fraction of the total, 0 to 1. Not seconds: multiply by
durationyourself if you track seconds. Updated by the component during scrubbing and reflected as an attribute. durationnumber0- Total duration in seconds. Optional; when set, time readouts render below the waveform and the slider announces times instead of percentages.
interactivebooleanfalse- Enables scrubbing. The waveform becomes a focusable slider: click or drag to seek, arrow keys to nudge, Home/End to jump. Without it the waveform is a static image.
variant'bars' | 'mirror''bars'- Rendering style.
barsdraws discrete bar pairs mirrored around the center line;mirrordraws a filled min/max envelope. stepsnumber0- Divides the track into this many equal steps, for a timeline of discrete frames rather than continuous audio. The playhead snaps to a step from pointer and keyboard alike, arrow keys move one step, Page Up/Down a tenth of the track (at least one step), and the slider reports the step number rather than a percentage. Unset, the track is continuous.
value-textstring- What the slider announces for the current position, replacing the built-in percentage or time. Set it from your
arc-inputhandler, which runs before the position renders, so the text and the value always arrive together (e.g. "85 of 200 ms").
Events
arc-inputdetail:{ value: number, time: number | null }- Fired continuously while scrubbing (every pointer move and each keyboard nudge).
valueis the position fraction 0-1;timeis seconds whendurationis set, otherwise null. Use for live preview: updating a time display, or audibly scrubbing. arc-changedetail:{ value: number, time: number | null }- Fired once when the seek commits: on pointer release, or with each keyboard nudge. Use for the actual seek on your audio source.
See also
- SparklineA small inline line or bar chart, drawn as SVG from a comma-separated string of numbers.
- MeterGauge with color-coded fill zones (success, warning, error) set by `low`, `high` and `optimum` thresholds.
- SliderA one-thumb slider for picking a number from a range, with an optional label and value readout.