wavesurfer.js 7.5.4 → 7.5.5

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 CHANGED
@@ -34,7 +34,7 @@ const wavesurfer = WaveSurfer.create({
34
34
 
35
35
  To import one of the plugins, e.g. the [Regions plugin](https://wavesurfer.xyz/examples/?regions.js):
36
36
  ```js
37
- import Regions from 'wavesurfer.js/dist/plugins/regions.js'
37
+ import Regions from 'wavesurfer.js/dist/plugins/regions.esm.js'
38
38
  ```
39
39
 
40
40
  Or as a script tag that will export `WaveSurfer.Regions`:
@@ -1,6 +1,91 @@
1
- import type { GenericPlugin } from './base-plugin.js';
2
- import Player from './player.js';
3
- export type WaveSurferOptions = {
1
+ type GeneralEventTypes = {
2
+ [EventName: string]: unknown[];
3
+ };
4
+ type EventListener<EventTypes extends GeneralEventTypes, EventName extends keyof EventTypes> = (...args: EventTypes[EventName]) => void;
5
+ /** A simple event emitter that can be used to listen to and emit events. */
6
+ declare class EventEmitter<EventTypes extends GeneralEventTypes> {
7
+ private listeners;
8
+ /** Add an event listener */
9
+ addEventListener<EventName extends keyof EventTypes>(event: EventName, listener: EventListener<EventTypes, EventName>, options?: {
10
+ once?: boolean;
11
+ }): () => void;
12
+ removeEventListener<EventName extends keyof EventTypes>(event: EventName, listener: EventListener<EventTypes, EventName>): void;
13
+ /** Subscribe to an event. Returns an unsubscribe function. */
14
+ on: <EventName extends keyof EventTypes>(event: EventName, listener: EventListener<EventTypes, EventName>, options?: {
15
+ once?: boolean;
16
+ }) => () => void;
17
+ /** Unsubscribe from an event */
18
+ un: <EventName extends keyof EventTypes>(event: EventName, listener: EventListener<EventTypes, EventName>) => void;
19
+ /** Subscribe to an event only once */
20
+ once<EventName extends keyof EventTypes>(event: EventName, listener: EventListener<EventTypes, EventName>): () => void;
21
+ /** Clear all events */
22
+ unAll(): void;
23
+ /** Emit an event */
24
+ protected emit<EventName extends keyof EventTypes>(eventName: EventName, ...args: EventTypes[EventName]): void;
25
+ }
26
+
27
+ type BasePluginEvents = {
28
+ destroy: [];
29
+ };
30
+ type GenericPlugin = BasePlugin<BasePluginEvents, unknown>;
31
+ declare class BasePlugin<EventTypes extends BasePluginEvents, Options> extends EventEmitter<EventTypes> {
32
+ protected wavesurfer?: WaveSurfer;
33
+ protected subscriptions: (() => void)[];
34
+ protected options: Options;
35
+ constructor(options: Options);
36
+ onInit(): void;
37
+ init(wavesurfer: WaveSurfer): void;
38
+ destroy(): void;
39
+ }
40
+
41
+ type PlayerOptions = {
42
+ media?: HTMLMediaElement;
43
+ mediaControls?: boolean;
44
+ autoplay?: boolean;
45
+ playbackRate?: number;
46
+ };
47
+ declare class Player<T extends GeneralEventTypes> extends EventEmitter<T> {
48
+ protected media: HTMLMediaElement;
49
+ private isExternalMedia;
50
+ constructor(options: PlayerOptions);
51
+ protected onMediaEvent(event: keyof HTMLMediaElementEventMap, callback: () => void, options?: AddEventListenerOptions): () => void;
52
+ protected onceMediaEvent(event: keyof HTMLMediaElementEventMap, callback: () => void): () => void;
53
+ protected getSrc(): string;
54
+ private revokeSrc;
55
+ protected setSrc(url: string, blob?: Blob): void;
56
+ protected destroy(): void;
57
+ protected setMediaElement(element: HTMLMediaElement): void;
58
+ /** Start playing the audio */
59
+ play(): Promise<void>;
60
+ /** Pause the audio */
61
+ pause(): void;
62
+ /** Check if the audio is playing */
63
+ isPlaying(): boolean;
64
+ /** Jumpt to a specific time in the audio (in seconds) */
65
+ setTime(time: number): void;
66
+ /** Get the duration of the audio in seconds */
67
+ getDuration(): number;
68
+ /** Get the current audio position in seconds */
69
+ getCurrentTime(): number;
70
+ /** Get the audio volume */
71
+ getVolume(): number;
72
+ /** Set the audio volume */
73
+ setVolume(volume: number): void;
74
+ /** Get the audio muted state */
75
+ getMuted(): boolean;
76
+ /** Mute or unmute the audio */
77
+ setMuted(muted: boolean): void;
78
+ /** Get the playback speed */
79
+ getPlaybackRate(): number;
80
+ /** Set the playback speed, pass an optional false to NOT preserve the pitch */
81
+ setPlaybackRate(rate: number, preservePitch?: boolean): void;
82
+ /** Get the HTML media element */
83
+ getMediaElement(): HTMLMediaElement;
84
+ /** Set a sink id to change the audio output device */
85
+ setSinkId(sinkId: string): Promise<void>;
86
+ }
87
+
88
+ type WaveSurferOptions = {
4
89
  /** Required: an HTML element or selector where the waveform will be rendered */
5
90
  container: HTMLElement | string;
6
91
  /** The height of the waveform in pixels, or "auto" to fill the container height */
@@ -80,7 +165,7 @@ declare const defaultOptions: {
80
165
  autoCenter: boolean;
81
166
  sampleRate: number;
82
167
  };
83
- export type WaveSurferEvents = {
168
+ type WaveSurferEvents = {
84
169
  /** When audio starts loading */
85
170
  load: [url: string];
86
171
  /** During audio loading */
@@ -189,4 +274,5 @@ declare class WaveSurfer extends Player<WaveSurferEvents> {
189
274
  /** Unmount wavesurfer */
190
275
  destroy(): void;
191
276
  }
192
- export default WaveSurfer;
277
+
278
+ export { type WaveSurferEvents, type WaveSurferOptions, WaveSurfer as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wavesurfer.js",
3
- "version": "7.5.4",
3
+ "version": "7.5.5",
4
4
  "license": "BSD-3-Clause",
5
5
  "author": "katspaugh",
6
6
  "description": "Navigable audio waveform player",
@@ -28,17 +28,17 @@
28
28
  "types": "./dist/wavesurfer.d.ts",
29
29
  "exports": {
30
30
  ".": {
31
- "import": "./dist/wavesurfer.js",
31
+ "import": "./dist/wavesurfer.esm.js",
32
32
  "types": "./dist/wavesurfer.d.ts",
33
33
  "require": "./dist/wavesurfer.cjs"
34
34
  },
35
35
  "./dist/plugins/*.js": {
36
- "import": "./dist/plugins/*.js",
36
+ "import": "./dist/plugins/*.esm.js",
37
37
  "types": "./dist/plugins/*.d.ts",
38
38
  "require": "./dist/plugins/*.cjs"
39
39
  },
40
40
  "./plugins/*": {
41
- "import": "./dist/plugins/*.js",
41
+ "import": "./dist/plugins/*.esm.js",
42
42
  "types": "./dist/plugins/*.d.ts",
43
43
  "require": "./dist/plugins/*.cjs"
44
44
  },
@@ -56,7 +56,7 @@
56
56
  "cypress": "cypress open --e2e",
57
57
  "cypress:canary": "cypress open --e2e -b chrome:canary",
58
58
  "test": "cypress run",
59
- "serve": "npx live-server --port=9090 --no-browser --ignore='.*'",
59
+ "serve": "npx live-server --port=9090 --no-browser --ignore='.*,src'",
60
60
  "start": "npm run build:dev & npm run serve"
61
61
  },
62
62
  "devDependencies": {
@@ -71,6 +71,7 @@
71
71
  "eslint-plugin-prettier": "^4.2.1",
72
72
  "prettier": "^2.8.7",
73
73
  "rollup": "^3.26.2",
74
+ "rollup-plugin-dts": "^6.1.0",
74
75
  "typescript": "^5.0.4"
75
76
  }
76
77
  }