wavesurfer.js 7.9.9 → 7.10.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.
Files changed (59) hide show
  1. package/README.md +3 -47
  2. package/dist/__tests__/player.test.js +13 -0
  3. package/dist/base-plugin.d.ts +1 -0
  4. package/dist/base-plugin.js +9 -0
  5. package/dist/fft.d.ts +54 -0
  6. package/dist/fft.js +596 -0
  7. package/dist/player.js +9 -1
  8. package/dist/plugins/envelope.cjs +1 -1
  9. package/dist/plugins/envelope.esm.js +1 -1
  10. package/dist/plugins/envelope.js +1 -1
  11. package/dist/plugins/envelope.min.js +1 -1
  12. package/dist/plugins/hover.cjs +1 -1
  13. package/dist/plugins/hover.d.ts +1 -0
  14. package/dist/plugins/hover.esm.js +1 -1
  15. package/dist/plugins/hover.js +1 -1
  16. package/dist/plugins/hover.min.js +1 -1
  17. package/dist/plugins/minimap.cjs +1 -1
  18. package/dist/plugins/minimap.esm.js +1 -1
  19. package/dist/plugins/minimap.js +1 -1
  20. package/dist/plugins/minimap.min.js +1 -1
  21. package/dist/plugins/record.cjs +1 -1
  22. package/dist/plugins/record.esm.js +1 -1
  23. package/dist/plugins/record.js +1 -1
  24. package/dist/plugins/record.min.js +1 -1
  25. package/dist/plugins/regions.cjs +1 -1
  26. package/dist/plugins/regions.esm.js +1 -1
  27. package/dist/plugins/regions.js +1 -1
  28. package/dist/plugins/regions.min.js +1 -1
  29. package/dist/plugins/spectrogram-windowed.cjs +1 -0
  30. package/dist/plugins/spectrogram-windowed.d.ts +138 -0
  31. package/dist/plugins/spectrogram-windowed.esm.js +1 -0
  32. package/dist/plugins/spectrogram-windowed.js +1 -0
  33. package/dist/plugins/spectrogram-windowed.min.js +1 -0
  34. package/dist/plugins/spectrogram-worker.d.ts +5 -0
  35. package/dist/plugins/spectrogram-worker.js +85 -0
  36. package/dist/plugins/spectrogram.cjs +1 -1
  37. package/dist/plugins/spectrogram.d.ts +42 -24
  38. package/dist/plugins/spectrogram.esm.js +1 -1
  39. package/dist/plugins/spectrogram.js +1 -1
  40. package/dist/plugins/spectrogram.min.js +1 -1
  41. package/dist/plugins/timeline.cjs +1 -1
  42. package/dist/plugins/timeline.d.ts +1 -0
  43. package/dist/plugins/timeline.esm.js +1 -1
  44. package/dist/plugins/timeline.js +1 -1
  45. package/dist/plugins/timeline.min.js +1 -1
  46. package/dist/plugins/zoom.cjs +1 -1
  47. package/dist/plugins/zoom.esm.js +1 -1
  48. package/dist/plugins/zoom.js +1 -1
  49. package/dist/plugins/zoom.min.js +1 -1
  50. package/dist/renderer.js +3 -1
  51. package/dist/types.d.ts +3 -0
  52. package/dist/wavesurfer.cjs +1 -1
  53. package/dist/wavesurfer.d.ts +2 -0
  54. package/dist/wavesurfer.esm.js +1 -1
  55. package/dist/wavesurfer.js +9 -0
  56. package/dist/wavesurfer.min.js +1 -1
  57. package/dist/webaudio.d.ts +4 -0
  58. package/dist/webaudio.js +25 -0
  59. package/package.json +6 -5
package/README.md CHANGED
@@ -15,10 +15,9 @@
15
15
  3. [Plugins](#plugins)
16
16
  4. [CSS styling](#css-styling)
17
17
  5. [Frequent questions](#questions)
18
- 6. [Upgrading from v6 to v7](#upgrading-from-v6-to-v7)
19
- 7. [Development](#development)
20
- 8. [Tests](#tests)
21
- 9. [Feedback](#feedback)
18
+ 6. [Development](#development)
19
+ 7. [Tests](#tests)
20
+ 8. [Feedback](#feedback)
22
21
 
23
22
  ## Getting started
24
23
 
@@ -132,49 +131,6 @@ However, please keep in mind that this forum is dedicated to wavesurfer-specific
132
131
  Generally, wavesurfer.js doesn't aim to be a wrapper for all things Web Audio. It's just a player with a waveform visualization. It does allow connecting itself to a Web Audio graph by exporting its audio element (see <a href="https://wavesurfer.xyz/examples/?4436ec40a2ab943243755e659ae32196">this example</a>) but nothign more than that. Please don't expect wavesurfer to be able to cut, add effects, or process your audio in any way.
133
132
  </details>
134
133
 
135
- ## Upgrading from v6 to v7
136
-
137
- Wavesurfer.js v7 is a TypeScript rewrite of wavesurfer.js that brings several improvements:
138
-
139
- * Typed API for better development experience
140
- * Enhanced decoding and rendering performance
141
- * New and improved plugins
142
-
143
- Most options, events, and methods are similar to those in previous versions.
144
-
145
- ### Notable differences
146
- * HTML audio playback by default (used to be an opt-in via `backend: "MediaElement"`)
147
- * The Markers plugin is removed – you should use the Regions plugin with just a `startTime`.
148
- * No Microphone plugin – superseded by the new Record plugin with more features.
149
- * The Cursor plugin is replaced by the Hover plugin.
150
-
151
- ### Removed options
152
- * `audioContext`, `closeAudioContext`, `audioScriptProcessor`
153
- * `autoCenterImmediately` – `autoCenter` is now always immediate unless the audio is playing
154
- * `backgroundColor`, `hideCursor` – this can be easily set via CSS
155
- * `mediaType` – you should instead pass an entire media element in the `media` option. [Example](https://wavesurfer.xyz/examples/?video.js).
156
- * `partialRender` – done by default
157
- * `pixelRatio` – `window.devicePixelRatio` is used by default
158
- * `renderer` – there's just one renderer for now, so no need for this option
159
- * `responsive` – responsiveness is enabled by default
160
- * `scrollParent` – the container will scroll if `minPxPerSec` is set to a higher value
161
- * `skipLength` – there's no `skipForward` and `skipBackward` methods anymore
162
- * `splitChannelsOptions` – you should now use `splitChannels` to pass the channel options. Pass `height: 0` to hide a channel. See [this example](https://wavesurfer.xyz/examples/?split-channels.js).
163
- * `drawingContextAttributes`, `maxCanvasWidth`, `forceDecode` – removed to reduce code complexity
164
- * `xhr` - please use `fetchParams` instead
165
- * `barMinHeight` - the minimum bar height is now 1 pixel by default
166
-
167
- ### Removed methods
168
- * `getFilters`, `setFilter` – see the [Web Audio example](https://wavesurfer.xyz/examples/?webaudio.js)
169
- * `drawBuffer` – to redraw the waveform, use `setOptions` instead and pass new rendering options
170
- * `cancelAjax` – you can pass an [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) in `fetchParams`
171
- * `skipForward`, `skipBackward`, `setPlayEnd` – can be implemented using `setTime(time)`
172
- * `exportPCM` is replaced with `exportPeaks` which returns arrays of floats
173
- * `toggleMute` is now called `setMuted(true | false)`
174
- * `setHeight`, `setWaveColor`, `setCursorColor`, etc. – use `setOptions` with the corresponding params instead. E.g., `wavesurfer.setOptions({ height: 300, waveColor: '#abc' })`
175
-
176
- See the complete [documentation of the new API](http://wavesurfer.xyz/docs).
177
-
178
134
  ## Development
179
135
 
180
136
  To get started with development, follow these steps:
@@ -24,6 +24,19 @@ describe('Player', () => {
24
24
  player.pause();
25
25
  expect(media.pause).toHaveBeenCalled();
26
26
  }));
27
+ test('pause before play promise resolves does not reject', () => __awaiter(void 0, void 0, void 0, function* () {
28
+ const abort = new DOMException('interrupted', 'AbortError');
29
+ let rejectPlay = () => undefined;
30
+ const media = createMedia();
31
+ media.play = jest.fn(() => new Promise((_, reject) => {
32
+ rejectPlay = reject;
33
+ }));
34
+ const player = new Player({ media });
35
+ const promise = player.play();
36
+ player.pause();
37
+ rejectPlay(abort);
38
+ yield expect(promise).resolves.toBeUndefined();
39
+ }));
27
40
  test('volume and muted', () => {
28
41
  const media = createMedia();
29
42
  const player = new Player({ media });
@@ -9,6 +9,7 @@ export declare class BasePlugin<EventTypes extends BasePluginEvents, Options> ex
9
9
  protected wavesurfer?: WaveSurfer;
10
10
  protected subscriptions: (() => void)[];
11
11
  protected options: Options;
12
+ private isDestroyed;
12
13
  /** Create a plugin instance */
13
14
  constructor(options: Options);
14
15
  /** Called after this.wavesurfer is available */
@@ -5,6 +5,7 @@ export class BasePlugin extends EventEmitter {
5
5
  constructor(options) {
6
6
  super();
7
7
  this.subscriptions = [];
8
+ this.isDestroyed = false;
8
9
  this.options = options;
9
10
  }
10
11
  /** Called after this.wavesurfer is available */
@@ -13,6 +14,11 @@ export class BasePlugin extends EventEmitter {
13
14
  }
14
15
  /** Do not call directly, only called by WavesSurfer internally */
15
16
  _init(wavesurfer) {
17
+ // Reset state if plugin was previously destroyed
18
+ if (this.isDestroyed) {
19
+ this.subscriptions = [];
20
+ this.isDestroyed = false;
21
+ }
16
22
  this.wavesurfer = wavesurfer;
17
23
  this.onInit();
18
24
  }
@@ -20,6 +26,9 @@ export class BasePlugin extends EventEmitter {
20
26
  destroy() {
21
27
  this.emit('destroy');
22
28
  this.subscriptions.forEach((unsubscribe) => unsubscribe());
29
+ this.subscriptions = [];
30
+ this.isDestroyed = true;
31
+ this.wavesurfer = undefined;
23
32
  }
24
33
  }
25
34
  export default BasePlugin;
package/dist/fft.d.ts ADDED
@@ -0,0 +1,54 @@
1
+ /**
2
+ * FFT (Fast Fourier Transform) implementation
3
+ * Based on https://github.com/corbanbrook/dsp.js
4
+ *
5
+ * Centralized FFT functionality for spectrogram plugins
6
+ */
7
+ export declare const ERB_A: number;
8
+ export declare function hzToMel(hz: number): number;
9
+ export declare function melToHz(mel: number): number;
10
+ export declare function hzToLog(hz: number): number;
11
+ export declare function logToHz(log: number): number;
12
+ export declare function hzToBark(hz: number): number;
13
+ export declare function barkToHz(bark: number): number;
14
+ export declare function hzToErb(hz: number): number;
15
+ export declare function erbToHz(erb: number): number;
16
+ export declare function hzToScale(hz: number, scale: 'linear' | 'logarithmic' | 'mel' | 'bark' | 'erb'): number;
17
+ export declare function scaleToHz(scale: number, scaleType: 'linear' | 'logarithmic' | 'mel' | 'bark' | 'erb'): number;
18
+ export declare function applyFilterBank(fftPoints: Float32Array, filterBank: number[][]): Float32Array;
19
+ export declare function createFilterBankForScale(scale: 'linear' | 'logarithmic' | 'mel' | 'bark' | 'erb', numFilters: number, fftSamples: number, sampleRate: number): number[][] | null;
20
+ export declare const COLOR_MAPS: {
21
+ gray: () => number[][];
22
+ igray: () => number[][];
23
+ roseus: () => number[][];
24
+ };
25
+ /**
26
+ * Set up color map based on options
27
+ */
28
+ export declare function setupColorMap(colorMap?: number[][] | 'gray' | 'igray' | 'roseus'): number[][];
29
+ /**
30
+ * Format frequency value for display
31
+ */
32
+ export declare function freqType(freq: number): string;
33
+ /**
34
+ * Get frequency unit for display
35
+ */
36
+ export declare function unitType(freq: number): string;
37
+ /**
38
+ * Get frequency value for label at given index
39
+ */
40
+ export declare function getLabelFrequency(index: number, labelIndex: number, frequencyMin: number, frequencyMax: number, scale: 'linear' | 'logarithmic' | 'mel' | 'bark' | 'erb'): number;
41
+ /**
42
+ * Create wrapper click handler for relative position calculation
43
+ */
44
+ export declare function createWrapperClickHandler(wrapper: HTMLElement, emit: (event: string, ...args: any[]) => void): (e: MouseEvent) => void;
45
+ /**
46
+ * Calculate FFT - Based on https://github.com/corbanbrook/dsp.js
47
+ */
48
+ declare function FFT(bufferSize: number, sampleRate: number, windowFunc: string, alpha: number): void;
49
+ export declare class FFT {
50
+ constructor(bufferSize: number, sampleRate: number, windowFunc: string, alpha: number);
51
+ calculateSpectrum(buffer: Float32Array): Float32Array;
52
+ }
53
+ export { FFT };
54
+ export default FFT;