@waveform-playlist/ui-components 14.0.1 → 15.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -0
- package/dist/index.d.mts +241 -163
- package/dist/index.d.ts +241 -163
- package/dist/index.js +947 -710
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +830 -593
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -47,6 +47,50 @@ function TrackMeter({ levels }: { levels: number[] }) {
|
|
|
47
47
|
}
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
+
For a live meter, pass the `meter` source returned by `useOutputMeter` (`@waveform-playlist/browser/tone`) or `useMicrophoneLevel` (`@waveform-playlist/recording`). The component draws each reading straight to the DOM and does not re-render for it:
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
import { SegmentedVUMeter, useMeterLevels } from '@waveform-playlist/ui-components';
|
|
54
|
+
import type { MeterSource } from '@waveform-playlist/core';
|
|
55
|
+
|
|
56
|
+
function LiveMeter({ meter }: { meter: MeterSource }) {
|
|
57
|
+
return <SegmentedVUMeter meter={meter} channelLabels={['L', 'R']} />;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// The numbers as React state, at most 10 times a second by default.
|
|
61
|
+
function PeakReadout({ meter }: { meter: MeterSource }) {
|
|
62
|
+
const { peakLevels } = useMeterLevels(meter);
|
|
63
|
+
return <span>{Math.round(Math.max(...peakLevels) * 100)}%</span>;
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## The drawing context: `usePlaylistInfo()`
|
|
68
|
+
|
|
69
|
+
The drawing primitives (`Track`, `SmartChannel`, `SmartScale`, `TimeScale`) read what they need from the view they are drawn in through `PlaylistInfoContext`. A root of `@waveform-playlist/browser` (`WaveformRoot`, `MediaElementWaveformRoot`) always publishes it for its view: the options of the `<WaveformViewOptions>` above it (the defaults for those not set), the provider's sample rate, the zoom and the height of the timescale strip. Only where there is no root above do the context's own defaults apply: `sampleRate` 48000, `samplesPerPixel` 1000, `waveHeight` 80, `timeScaleHeight` 15, `barWidth` 1, `barGap` 0, `roundedBars` false, `progressBarWidth` 1.
|
|
70
|
+
|
|
71
|
+
```tsx
|
|
72
|
+
import { usePlaylistInfo, type PlaylistInfo } from '@waveform-playlist/ui-components';
|
|
73
|
+
|
|
74
|
+
const {
|
|
75
|
+
sampleRate,
|
|
76
|
+
samplesPerPixel,
|
|
77
|
+
waveHeight, // px of one channel; default 80
|
|
78
|
+
timeScaleHeight, // px of the timescale strip; inside a root, 0 when the view has none
|
|
79
|
+
barWidth, // default 1
|
|
80
|
+
barGap, // default 0
|
|
81
|
+
roundedBars, // default false
|
|
82
|
+
progressBarWidth, // px of the playhead line; default barWidth + barGap
|
|
83
|
+
}: PlaylistInfo = usePlaylistInfo();
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
If you render `<PlaylistInfoContext value={…}>` yourself, give it every field of `PlaylistInfo` (`roundedBars` and `progressBarWidth` are required; `controls` and `zoomLevels` are no longer part of it). `DEFAULT_WAVE_HEIGHT` (80), `DEFAULT_BAR_WIDTH` (1) and `DEFAULT_BAR_GAP` (0) are exported.
|
|
87
|
+
|
|
88
|
+
`Channel` never steps less than one pixel from one bar to the next: a `barWidth + barGap` under 1 is drawn with a step of 1.
|
|
89
|
+
|
|
90
|
+
`SpectrogramChannel` takes the background of its area from the theme key `spectrogramBackgroundColor` (`#000` without it). That background shows until the spectrogram has been drawn and where a chunk is not mounted. A new `waveHeight` mounts new canvases, which are registered again through `onCanvasRegister`.
|
|
91
|
+
|
|
92
|
+
A `Clip` given `isPlaceholder` (the clip's audio is still loading) is drawn without drag and trim handles, dimmed to the theme key `placeholderClipOpacity` (a number from 0 to 1; 0.5 when not set). A placeholder with no peaks to draw gets `<ClipPlaceholderBody />` as its child: a box over the clip's channel area in the colour of the waveform's bars (`waveFillColor`, `selectedWaveFillColor` with `isSelected`, `grey` when the theme gives no usable colour), carrying `data-clip-placeholder-body="true"`; the clip dims it, and it sets no opacity of its own.
|
|
93
|
+
|
|
50
94
|
## Theming
|
|
51
95
|
|
|
52
96
|
Wrap your tree in styled-components' `ThemeProvider` with a `WaveformPlaylistTheme` object — `defaultTheme` and `darkTheme` are exported as starting points and can be partially overridden:
|