wavesurfer.js 6.5.1 → 7.0.0-alpha.0
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/.eslintrc.json +24 -0
- package/.prettierrc +8 -0
- package/README.md +26 -117
- package/dist/base-plugin.d.ts +10 -0
- package/dist/base-plugin.js +13 -0
- package/dist/decoder.d.ts +10 -0
- package/dist/decoder.js +43 -0
- package/dist/event-emitter.d.ts +11 -0
- package/dist/event-emitter.js +21 -0
- package/dist/fetcher.d.ts +4 -0
- package/dist/fetcher.js +17 -0
- package/dist/index.d.ts +92 -0
- package/dist/index.js +166 -0
- package/dist/player-webaudio.d.ts +8 -0
- package/dist/player-webaudio.js +31 -0
- package/dist/player.d.ts +16 -0
- package/dist/player.js +40 -0
- package/dist/plugins/regions.d.ts +48 -0
- package/dist/plugins/regions.js +183 -0
- package/dist/renderer.d.ts +34 -0
- package/dist/renderer.js +193 -0
- package/dist/timer.d.ts +10 -0
- package/dist/timer.js +17 -0
- package/examples/audio.ogg +0 -0
- package/examples/bars.js +19 -0
- package/examples/basic.js +8 -0
- package/examples/gradient.js +28 -0
- package/examples/regions.js +63 -0
- package/examples/video.js +19 -0
- package/examples/webaudio.js +14 -0
- package/package.json +19 -99
- package/src/base-plugin.ts +20 -0
- package/src/decoder.ts +41 -0
- package/src/event-emitter.ts +35 -0
- package/src/fetcher.ts +7 -0
- package/src/index.ts +252 -0
- package/src/player-webaudio.ts +34 -0
- package/src/player.ts +50 -0
- package/src/plugins/regions.ts +240 -0
- package/src/renderer.ts +250 -0
- package/src/timer.ts +27 -0
- package/tsconfig.json +105 -0
- package/tutorial/index.html +47 -0
- package/tutorial/src/editor.js +70 -0
- package/tutorial/src/init.js +66 -0
- package/tutorial/src/url.js +25 -0
- package/tutorial/style.css +211 -0
- package/yarn-error.log +1049 -0
- package/LICENSE +0 -29
- package/dist/plugin/wavesurfer.cursor.js +0 -418
- package/dist/plugin/wavesurfer.cursor.js.map +0 -1
- package/dist/plugin/wavesurfer.cursor.min.js +0 -7
- package/dist/plugin/wavesurfer.cursor.min.js.map +0 -1
- package/dist/plugin/wavesurfer.elan.js +0 -381
- package/dist/plugin/wavesurfer.elan.js.map +0 -1
- package/dist/plugin/wavesurfer.elan.min.js +0 -7
- package/dist/plugin/wavesurfer.elan.min.js.map +0 -1
- package/dist/plugin/wavesurfer.markers.js +0 -520
- package/dist/plugin/wavesurfer.markers.js.map +0 -1
- package/dist/plugin/wavesurfer.markers.min.js +0 -7
- package/dist/plugin/wavesurfer.markers.min.js.map +0 -1
- package/dist/plugin/wavesurfer.mediasession.js +0 -181
- package/dist/plugin/wavesurfer.mediasession.js.map +0 -1
- package/dist/plugin/wavesurfer.mediasession.min.js +0 -7
- package/dist/plugin/wavesurfer.mediasession.min.js.map +0 -1
- package/dist/plugin/wavesurfer.microphone.js +0 -466
- package/dist/plugin/wavesurfer.microphone.js.map +0 -1
- package/dist/plugin/wavesurfer.microphone.min.js +0 -7
- package/dist/plugin/wavesurfer.microphone.min.js.map +0 -1
- package/dist/plugin/wavesurfer.minimap.js +0 -440
- package/dist/plugin/wavesurfer.minimap.js.map +0 -1
- package/dist/plugin/wavesurfer.minimap.min.js +0 -7
- package/dist/plugin/wavesurfer.minimap.min.js.map +0 -1
- package/dist/plugin/wavesurfer.playhead.js +0 -300
- package/dist/plugin/wavesurfer.playhead.js.map +0 -1
- package/dist/plugin/wavesurfer.playhead.min.js +0 -7
- package/dist/plugin/wavesurfer.playhead.min.js.map +0 -1
- package/dist/plugin/wavesurfer.regions.js +0 -1335
- package/dist/plugin/wavesurfer.regions.js.map +0 -1
- package/dist/plugin/wavesurfer.regions.min.js +0 -7
- package/dist/plugin/wavesurfer.regions.min.js.map +0 -1
- package/dist/plugin/wavesurfer.spectrogram.js +0 -736
- package/dist/plugin/wavesurfer.spectrogram.js.map +0 -1
- package/dist/plugin/wavesurfer.spectrogram.min.js +0 -7
- package/dist/plugin/wavesurfer.spectrogram.min.js.map +0 -1
- package/dist/plugin/wavesurfer.timeline.js +0 -649
- package/dist/plugin/wavesurfer.timeline.js.map +0 -1
- package/dist/plugin/wavesurfer.timeline.min.js +0 -7
- package/dist/plugin/wavesurfer.timeline.min.js.map +0 -1
- package/dist/wavesurfer-html-init.js +0 -381
- package/dist/wavesurfer-html-init.js.map +0 -1
- package/dist/wavesurfer-html-init.min.js +0 -7
- package/dist/wavesurfer-html-init.min.js.map +0 -1
- package/dist/wavesurfer.js +0 -6145
- package/dist/wavesurfer.js.map +0 -1
- package/dist/wavesurfer.min.js +0 -7
- package/dist/wavesurfer.min.js.map +0 -1
- package/src/drawer.canvasentry.js +0 -427
- package/src/drawer.js +0 -413
- package/src/drawer.multicanvas.js +0 -617
- package/src/html-init.js +0 -241
- package/src/mediaelement-webaudio.js +0 -77
- package/src/mediaelement.js +0 -443
- package/src/peakcache.js +0 -127
- package/src/plugin/cursor/index.js +0 -350
- package/src/plugin/elan/index.js +0 -307
- package/src/plugin/markers/index.js +0 -436
- package/src/plugin/mediasession/index.js +0 -94
- package/src/plugin/microphone/index.js +0 -415
- package/src/plugin/minimap/index.js +0 -403
- package/src/plugin/playhead/index.js +0 -226
- package/src/plugin/regions/index.js +0 -478
- package/src/plugin/regions/region.js +0 -875
- package/src/plugin/spectrogram/fft.js +0 -222
- package/src/plugin/spectrogram/index.js +0 -522
- package/src/plugin/timeline/index.js +0 -600
- package/src/util/absMax.js +0 -16
- package/src/util/clamp.js +0 -11
- package/src/util/fetch.js +0 -222
- package/src/util/frame.js +0 -13
- package/src/util/get-id.js +0 -22
- package/src/util/index.js +0 -14
- package/src/util/max.js +0 -16
- package/src/util/min.js +0 -16
- package/src/util/observer.js +0 -144
- package/src/util/orientation.js +0 -98
- package/src/util/prevent-click.js +0 -19
- package/src/util/request-animation-frame.js +0 -15
- package/src/util/silence-mode.js +0 -42
- package/src/util/style.js +0 -16
- package/src/wavesurfer.js +0 -1797
- package/src/webaudio.js +0 -779
package/src/util/fetch.js
DELETED
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @since 3.0.0
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import Observer from './observer';
|
|
6
|
-
|
|
7
|
-
class ProgressHandler {
|
|
8
|
-
/**
|
|
9
|
-
* Instantiate ProgressHandler
|
|
10
|
-
*
|
|
11
|
-
* @param {Observer} instance The `fetchFile` observer instance.
|
|
12
|
-
* @param {Number} contentLength Content length.
|
|
13
|
-
* @param {Response} response Response object.
|
|
14
|
-
*/
|
|
15
|
-
constructor(instance, contentLength, response) {
|
|
16
|
-
this.instance = instance;
|
|
17
|
-
this.instance._reader = response.body.getReader();
|
|
18
|
-
|
|
19
|
-
this.total = parseInt(contentLength, 10);
|
|
20
|
-
this.loaded = 0;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* A method that is called once, immediately after the `ReadableStream``
|
|
25
|
-
* is constructed.
|
|
26
|
-
*
|
|
27
|
-
* @param {ReadableStreamDefaultController} controller Controller instance
|
|
28
|
-
* used to control the stream.
|
|
29
|
-
*/
|
|
30
|
-
start(controller) {
|
|
31
|
-
const read = () => {
|
|
32
|
-
// instance._reader.read() returns a promise that resolves
|
|
33
|
-
// when a value has been received
|
|
34
|
-
this.instance._reader
|
|
35
|
-
.read()
|
|
36
|
-
.then(({ done, value }) => {
|
|
37
|
-
// result objects contain two properties:
|
|
38
|
-
// done - true if the stream has already given you all its data.
|
|
39
|
-
// value - some data. Always undefined when done is true.
|
|
40
|
-
if (done) {
|
|
41
|
-
// ensure onProgress called when content-length=0
|
|
42
|
-
if (this.total === 0) {
|
|
43
|
-
this.instance.onProgress.call(this.instance, {
|
|
44
|
-
loaded: this.loaded,
|
|
45
|
-
total: this.total,
|
|
46
|
-
lengthComputable: false
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
// no more data needs to be consumed, close the stream
|
|
50
|
-
controller.close();
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
this.loaded += value.byteLength;
|
|
55
|
-
this.instance.onProgress.call(this.instance, {
|
|
56
|
-
loaded: this.loaded,
|
|
57
|
-
total: this.total,
|
|
58
|
-
lengthComputable: !(this.total === 0)
|
|
59
|
-
});
|
|
60
|
-
// enqueue the next data chunk into our target stream
|
|
61
|
-
controller.enqueue(value);
|
|
62
|
-
read();
|
|
63
|
-
})
|
|
64
|
-
.catch(error => {
|
|
65
|
-
controller.error(error);
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
read();
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Load a file using `fetch`.
|
|
75
|
-
*
|
|
76
|
-
* @param {object} options Request options to use. See example below.
|
|
77
|
-
* @returns {Observer} Observer instance
|
|
78
|
-
* @example
|
|
79
|
-
* // default options
|
|
80
|
-
* let options = {
|
|
81
|
-
* url: undefined,
|
|
82
|
-
* method: 'GET',
|
|
83
|
-
* mode: 'cors',
|
|
84
|
-
* credentials: 'same-origin',
|
|
85
|
-
* cache: 'default',
|
|
86
|
-
* responseType: 'json',
|
|
87
|
-
* requestHeaders: [],
|
|
88
|
-
* redirect: 'follow',
|
|
89
|
-
* referrer: 'client'
|
|
90
|
-
* };
|
|
91
|
-
*
|
|
92
|
-
* // override some options
|
|
93
|
-
* options.url = '../media/demo.wav';
|
|
94
|
-
|
|
95
|
-
* // available types: 'arraybuffer', 'blob', 'json' or 'text'
|
|
96
|
-
* options.responseType = 'arraybuffer';
|
|
97
|
-
*
|
|
98
|
-
* // make fetch call
|
|
99
|
-
* let request = util.fetchFile(options);
|
|
100
|
-
*
|
|
101
|
-
* // listen for events
|
|
102
|
-
* request.on('progress', e => {
|
|
103
|
-
* console.log('progress', e);
|
|
104
|
-
* });
|
|
105
|
-
*
|
|
106
|
-
* request.on('success', data => {
|
|
107
|
-
* console.log('success!', data);
|
|
108
|
-
* });
|
|
109
|
-
*
|
|
110
|
-
* request.on('error', e => {
|
|
111
|
-
* console.warn('fetchFile error: ', e);
|
|
112
|
-
* });
|
|
113
|
-
*/
|
|
114
|
-
export default function fetchFile(options) {
|
|
115
|
-
if (!options) {
|
|
116
|
-
throw new Error('fetch options missing');
|
|
117
|
-
} else if (!options.url) {
|
|
118
|
-
throw new Error('fetch url missing');
|
|
119
|
-
}
|
|
120
|
-
const instance = new Observer();
|
|
121
|
-
const fetchHeaders = new Headers();
|
|
122
|
-
const fetchRequest = new Request(options.url);
|
|
123
|
-
|
|
124
|
-
// add ability to abort
|
|
125
|
-
instance.controller = new AbortController();
|
|
126
|
-
|
|
127
|
-
// check if headers have to be added
|
|
128
|
-
if (options && options.requestHeaders) {
|
|
129
|
-
// add custom request headers
|
|
130
|
-
options.requestHeaders.forEach(header => {
|
|
131
|
-
fetchHeaders.append(header.key, header.value);
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// parse fetch options
|
|
136
|
-
const responseType = options.responseType || 'json';
|
|
137
|
-
const fetchOptions = {
|
|
138
|
-
method: options.method || 'GET',
|
|
139
|
-
headers: fetchHeaders,
|
|
140
|
-
mode: options.mode || 'cors',
|
|
141
|
-
credentials: options.credentials || 'same-origin',
|
|
142
|
-
cache: options.cache || 'default',
|
|
143
|
-
redirect: options.redirect || 'follow',
|
|
144
|
-
referrer: options.referrer || 'client',
|
|
145
|
-
signal: instance.controller.signal
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
fetch(fetchRequest, fetchOptions)
|
|
149
|
-
.then(response => {
|
|
150
|
-
// store response reference
|
|
151
|
-
instance.response = response;
|
|
152
|
-
|
|
153
|
-
let progressAvailable = true;
|
|
154
|
-
if (!response.body) {
|
|
155
|
-
// ReadableStream is not yet supported in this browser
|
|
156
|
-
// see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream
|
|
157
|
-
progressAvailable = false;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Server must send CORS header "Access-Control-Expose-Headers: content-length"
|
|
161
|
-
const contentLength = response.headers.get('content-length');
|
|
162
|
-
if (contentLength === null) {
|
|
163
|
-
// Content-Length server response header missing.
|
|
164
|
-
// Don't evaluate download progress if we can't compare against a total size
|
|
165
|
-
// see https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#Access-Control-Expose-Headers
|
|
166
|
-
progressAvailable = false;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if (!progressAvailable) {
|
|
170
|
-
// not able to check download progress so skip it
|
|
171
|
-
return response;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// fire progress event when during load
|
|
175
|
-
instance.onProgress = e => {
|
|
176
|
-
instance.fireEvent('progress', e);
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
return new Response(
|
|
180
|
-
new ReadableStream(
|
|
181
|
-
new ProgressHandler(instance, contentLength, response)
|
|
182
|
-
),
|
|
183
|
-
fetchOptions
|
|
184
|
-
);
|
|
185
|
-
})
|
|
186
|
-
.then(response => {
|
|
187
|
-
let errMsg;
|
|
188
|
-
if (response.ok) {
|
|
189
|
-
switch (responseType) {
|
|
190
|
-
case 'arraybuffer':
|
|
191
|
-
return response.arrayBuffer();
|
|
192
|
-
|
|
193
|
-
case 'json':
|
|
194
|
-
return response.json();
|
|
195
|
-
|
|
196
|
-
case 'blob':
|
|
197
|
-
return response.blob();
|
|
198
|
-
|
|
199
|
-
case 'text':
|
|
200
|
-
return response.text();
|
|
201
|
-
|
|
202
|
-
default:
|
|
203
|
-
errMsg = 'Unknown responseType: ' + responseType;
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
if (!errMsg) {
|
|
208
|
-
errMsg = 'HTTP error status: ' + response.status;
|
|
209
|
-
}
|
|
210
|
-
throw new Error(errMsg);
|
|
211
|
-
})
|
|
212
|
-
.then(response => {
|
|
213
|
-
instance.fireEvent('success', response);
|
|
214
|
-
})
|
|
215
|
-
.catch(error => {
|
|
216
|
-
instance.fireEvent('error', error);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
// return the fetch request
|
|
220
|
-
instance.fetchRequest = fetchRequest;
|
|
221
|
-
return instance;
|
|
222
|
-
}
|
package/src/util/frame.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import reqAnimationFrame from './request-animation-frame';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Create a function which will be called at the next requestAnimationFrame
|
|
5
|
-
* cycle
|
|
6
|
-
*
|
|
7
|
-
* @param {function} func The function to call
|
|
8
|
-
*
|
|
9
|
-
* @return {func} The function wrapped within a requestAnimationFrame
|
|
10
|
-
*/
|
|
11
|
-
export default function frame(func) {
|
|
12
|
-
return (...args) => reqAnimationFrame(() => func(...args));
|
|
13
|
-
}
|
package/src/util/get-id.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get a random prefixed ID
|
|
3
|
-
*
|
|
4
|
-
* @param {String} prefix Prefix to use. Default is `'wavesurfer_'`.
|
|
5
|
-
* @returns {String} Random prefixed ID
|
|
6
|
-
* @example
|
|
7
|
-
* console.log(getId()); // logs 'wavesurfer_b5pors4ru6g'
|
|
8
|
-
*
|
|
9
|
-
* let prefix = 'foo-';
|
|
10
|
-
* console.log(getId(prefix)); // logs 'foo-b5pors4ru6g'
|
|
11
|
-
*/
|
|
12
|
-
export default function getId(prefix) {
|
|
13
|
-
if (prefix === undefined) {
|
|
14
|
-
prefix = 'wavesurfer_';
|
|
15
|
-
}
|
|
16
|
-
return (
|
|
17
|
-
prefix +
|
|
18
|
-
Math.random()
|
|
19
|
-
.toString(32)
|
|
20
|
-
.substring(2)
|
|
21
|
-
);
|
|
22
|
-
}
|
package/src/util/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export { default as getId } from './get-id';
|
|
2
|
-
export { default as max } from './max';
|
|
3
|
-
export { default as min } from './min';
|
|
4
|
-
export { default as absMax } from './absMax';
|
|
5
|
-
export { default as Observer } from './observer';
|
|
6
|
-
export { default as style } from './style';
|
|
7
|
-
export { default as requestAnimationFrame } from './request-animation-frame';
|
|
8
|
-
export { default as frame } from './frame';
|
|
9
|
-
export { default as debounce } from 'debounce';
|
|
10
|
-
export { default as preventClick } from './prevent-click';
|
|
11
|
-
export { default as fetchFile } from './fetch';
|
|
12
|
-
export { default as clamp } from './clamp';
|
|
13
|
-
export { default as withOrientation } from './orientation';
|
|
14
|
-
export { default as ignoreSilenceMode } from './silence-mode';
|
package/src/util/max.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the largest value
|
|
3
|
-
*
|
|
4
|
-
* @param {Array} values Array of numbers
|
|
5
|
-
* @returns {Number} Largest number found
|
|
6
|
-
* @example console.log(max([1, 2, 3])); // logs 3
|
|
7
|
-
*/
|
|
8
|
-
export default function max(values) {
|
|
9
|
-
let largest = -Infinity;
|
|
10
|
-
Object.keys(values).forEach(i => {
|
|
11
|
-
if (values[i] > largest) {
|
|
12
|
-
largest = values[i];
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
return largest;
|
|
16
|
-
}
|
package/src/util/min.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the smallest value
|
|
3
|
-
*
|
|
4
|
-
* @param {Array} values Array of numbers
|
|
5
|
-
* @returns {Number} Smallest number found
|
|
6
|
-
* @example console.log(min([1, 2, 3])); // logs 1
|
|
7
|
-
*/
|
|
8
|
-
export default function min(values) {
|
|
9
|
-
let smallest = Number(Infinity);
|
|
10
|
-
Object.keys(values).forEach(i => {
|
|
11
|
-
if (values[i] < smallest) {
|
|
12
|
-
smallest = values[i];
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
return smallest;
|
|
16
|
-
}
|
package/src/util/observer.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {Object} ListenerDescriptor
|
|
3
|
-
* @property {string} name The name of the event
|
|
4
|
-
* @property {function} callback The callback
|
|
5
|
-
* @property {function} un The function to call to remove the listener
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Observer class
|
|
10
|
-
*/
|
|
11
|
-
export default class Observer {
|
|
12
|
-
/**
|
|
13
|
-
* Instantiate Observer
|
|
14
|
-
*/
|
|
15
|
-
constructor() {
|
|
16
|
-
/**
|
|
17
|
-
* @private
|
|
18
|
-
* @todo Initialise the handlers here already and remove the conditional
|
|
19
|
-
* assignment in `on()`
|
|
20
|
-
*/
|
|
21
|
-
this._disabledEventEmissions = [];
|
|
22
|
-
this.handlers = null;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Attach a handler function for an event.
|
|
26
|
-
*
|
|
27
|
-
* @param {string} event Name of the event to listen to
|
|
28
|
-
* @param {function} fn The callback to trigger when the event is fired
|
|
29
|
-
* @return {ListenerDescriptor} The event descriptor
|
|
30
|
-
*/
|
|
31
|
-
on(event, fn) {
|
|
32
|
-
if (!this.handlers) {
|
|
33
|
-
this.handlers = {};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let handlers = this.handlers[event];
|
|
37
|
-
if (!handlers) {
|
|
38
|
-
handlers = this.handlers[event] = [];
|
|
39
|
-
}
|
|
40
|
-
handlers.push(fn);
|
|
41
|
-
|
|
42
|
-
// Return an event descriptor
|
|
43
|
-
return {
|
|
44
|
-
name: event,
|
|
45
|
-
callback: fn,
|
|
46
|
-
un: (e, fn) => this.un(e, fn)
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Remove an event handler.
|
|
52
|
-
*
|
|
53
|
-
* @param {string} event Name of the event the listener that should be
|
|
54
|
-
* removed listens to
|
|
55
|
-
* @param {function} fn The callback that should be removed
|
|
56
|
-
*/
|
|
57
|
-
un(event, fn) {
|
|
58
|
-
if (!this.handlers) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const handlers = this.handlers[event];
|
|
63
|
-
let i;
|
|
64
|
-
if (handlers) {
|
|
65
|
-
if (fn) {
|
|
66
|
-
for (i = handlers.length - 1; i >= 0; i--) {
|
|
67
|
-
if (handlers[i] == fn) {
|
|
68
|
-
handlers.splice(i, 1);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
} else {
|
|
72
|
-
handlers.length = 0;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Remove all event handlers.
|
|
79
|
-
*/
|
|
80
|
-
unAll() {
|
|
81
|
-
this.handlers = null;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Attach a handler to an event. The handler is executed at most once per
|
|
86
|
-
* event type.
|
|
87
|
-
*
|
|
88
|
-
* @param {string} event The event to listen to
|
|
89
|
-
* @param {function} handler The callback that is only to be called once
|
|
90
|
-
* @return {ListenerDescriptor} The event descriptor
|
|
91
|
-
*/
|
|
92
|
-
once(event, handler) {
|
|
93
|
-
const fn = (...args) => {
|
|
94
|
-
/* eslint-disable no-invalid-this */
|
|
95
|
-
handler.apply(this, args);
|
|
96
|
-
/* eslint-enable no-invalid-this */
|
|
97
|
-
setTimeout(() => {
|
|
98
|
-
this.un(event, fn);
|
|
99
|
-
}, 0);
|
|
100
|
-
};
|
|
101
|
-
return this.on(event, fn);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Disable firing a list of events by name. When specified, event handlers for any event type
|
|
106
|
-
* passed in here will not be called.
|
|
107
|
-
*
|
|
108
|
-
* @since 4.0.0
|
|
109
|
-
* @param {string[]} eventNames an array of event names to disable emissions for
|
|
110
|
-
* @example
|
|
111
|
-
* // disable seek and interaction events
|
|
112
|
-
* wavesurfer.setDisabledEventEmissions(['seek', 'interaction']);
|
|
113
|
-
*/
|
|
114
|
-
setDisabledEventEmissions(eventNames) {
|
|
115
|
-
this._disabledEventEmissions = eventNames;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* plugins borrow part of this class without calling the constructor,
|
|
120
|
-
* so we have to be careful about _disabledEventEmissions
|
|
121
|
-
*/
|
|
122
|
-
|
|
123
|
-
_isDisabledEventEmission(event) {
|
|
124
|
-
return this._disabledEventEmissions && this._disabledEventEmissions.includes(event);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Manually fire an event
|
|
129
|
-
*
|
|
130
|
-
* @param {string} event The event to fire manually
|
|
131
|
-
* @param {...any} args The arguments with which to call the listeners
|
|
132
|
-
*/
|
|
133
|
-
fireEvent(event, ...args) {
|
|
134
|
-
if (!this.handlers || this._isDisabledEventEmission(event)) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const handlers = this.handlers[event];
|
|
139
|
-
handlers &&
|
|
140
|
-
handlers.forEach(fn => {
|
|
141
|
-
fn(...args);
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
}
|
package/src/util/orientation.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
const verticalPropMap = {
|
|
2
|
-
width: 'height',
|
|
3
|
-
height: 'width',
|
|
4
|
-
|
|
5
|
-
overflowX: 'overflowY',
|
|
6
|
-
overflowY: 'overflowX',
|
|
7
|
-
|
|
8
|
-
clientWidth: 'clientHeight',
|
|
9
|
-
clientHeight: 'clientWidth',
|
|
10
|
-
|
|
11
|
-
clientX: 'clientY',
|
|
12
|
-
clientY: 'clientX',
|
|
13
|
-
|
|
14
|
-
scrollWidth: 'scrollHeight',
|
|
15
|
-
scrollLeft: 'scrollTop',
|
|
16
|
-
|
|
17
|
-
offsetLeft: 'offsetTop',
|
|
18
|
-
offsetTop: 'offsetLeft',
|
|
19
|
-
offsetHeight: 'offsetWidth',
|
|
20
|
-
offsetWidth: 'offsetHeight',
|
|
21
|
-
|
|
22
|
-
left: 'top',
|
|
23
|
-
right: 'bottom',
|
|
24
|
-
top: 'left',
|
|
25
|
-
bottom: 'right',
|
|
26
|
-
|
|
27
|
-
borderRightStyle: 'borderBottomStyle',
|
|
28
|
-
borderRightWidth: 'borderBottomWidth',
|
|
29
|
-
borderRightColor: 'borderBottomColor'
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Convert a horizontally-oriented property name to a vertical one.
|
|
34
|
-
*
|
|
35
|
-
* @param {string} prop A property name
|
|
36
|
-
* @param {bool} vertical Whether the element is oriented vertically
|
|
37
|
-
* @returns {string} prop, converted appropriately
|
|
38
|
-
*/
|
|
39
|
-
function mapProp(prop, vertical) {
|
|
40
|
-
if (Object.prototype.hasOwnProperty.call(verticalPropMap, prop)) {
|
|
41
|
-
return vertical ? verticalPropMap[prop] : prop;
|
|
42
|
-
} else {
|
|
43
|
-
return prop;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const isProxy = Symbol("isProxy");
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Returns an appropriately oriented object based on vertical.
|
|
51
|
-
* If vertical is true, attribute getting and setting will be mapped through
|
|
52
|
-
* verticalPropMap, so that e.g. getting the object's .width will give its
|
|
53
|
-
* .height instead.
|
|
54
|
-
* Certain methods of an oriented object will return oriented objects as well.
|
|
55
|
-
* Oriented objects can't be added to the DOM directly since they are Proxy objects
|
|
56
|
-
* and thus fail typechecks. Use domElement to get the actual element for this.
|
|
57
|
-
*
|
|
58
|
-
* @param {object} target The object to be wrapped and oriented
|
|
59
|
-
* @param {bool} vertical Whether the element is oriented vertically
|
|
60
|
-
* @returns {Proxy} An oriented object with attr translation via verticalAttrMap
|
|
61
|
-
* @since 5.0.0
|
|
62
|
-
*/
|
|
63
|
-
export default function withOrientation(target, vertical) {
|
|
64
|
-
if (target[isProxy]) {
|
|
65
|
-
return target;
|
|
66
|
-
} else {
|
|
67
|
-
return new Proxy(
|
|
68
|
-
target, {
|
|
69
|
-
get: function(obj, prop, receiver) {
|
|
70
|
-
if (prop === isProxy) {
|
|
71
|
-
return true;
|
|
72
|
-
} else if (prop === 'domElement') {
|
|
73
|
-
return obj;
|
|
74
|
-
} else if (prop === 'style') {
|
|
75
|
-
return withOrientation(obj.style, vertical);
|
|
76
|
-
} else if (prop === 'canvas') {
|
|
77
|
-
return withOrientation(obj.canvas, vertical);
|
|
78
|
-
} else if (prop === 'getBoundingClientRect') {
|
|
79
|
-
return function(...args) {
|
|
80
|
-
return withOrientation(obj.getBoundingClientRect(...args), vertical);
|
|
81
|
-
};
|
|
82
|
-
} else if (prop === 'getContext') {
|
|
83
|
-
return function(...args) {
|
|
84
|
-
return withOrientation(obj.getContext(...args), vertical);
|
|
85
|
-
};
|
|
86
|
-
} else {
|
|
87
|
-
let value = obj[mapProp(prop, vertical)];
|
|
88
|
-
return typeof value == 'function' ? value.bind(obj) : value;
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
set: function(obj, prop, value) {
|
|
92
|
-
obj[mapProp(prop, vertical)] = value;
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stops propagation of click event and removes event listener
|
|
3
|
-
*
|
|
4
|
-
* @private
|
|
5
|
-
* @param {object} event The click event
|
|
6
|
-
*/
|
|
7
|
-
function preventClickHandler(event) {
|
|
8
|
-
event.stopPropagation();
|
|
9
|
-
document.body.removeEventListener('click', preventClickHandler, true);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Starts listening for click event and prevent propagation
|
|
14
|
-
*
|
|
15
|
-
* @param {object} values Values
|
|
16
|
-
*/
|
|
17
|
-
export default function preventClick(values) {
|
|
18
|
-
document.body.addEventListener('click', preventClickHandler, true);
|
|
19
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/* eslint-disable valid-jsdoc */
|
|
2
|
-
/**
|
|
3
|
-
* Returns the `requestAnimationFrame` function for the browser, or a shim with
|
|
4
|
-
* `setTimeout` if the function is not found
|
|
5
|
-
*
|
|
6
|
-
* @return {function} Available `requestAnimationFrame` function for the browser
|
|
7
|
-
*/
|
|
8
|
-
export default (
|
|
9
|
-
window.requestAnimationFrame ||
|
|
10
|
-
window.webkitRequestAnimationFrame ||
|
|
11
|
-
window.mozRequestAnimationFrame ||
|
|
12
|
-
window.oRequestAnimationFrame ||
|
|
13
|
-
window.msRequestAnimationFrame ||
|
|
14
|
-
((callback, element) => setTimeout(callback, 1000 / 60))
|
|
15
|
-
).bind(window);
|
package/src/util/silence-mode.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ignores device silence mode when using the `WebAudio` backend.
|
|
3
|
-
*
|
|
4
|
-
* Many mobile devices contain a hardware button to mute the ringtone for incoming
|
|
5
|
-
* calls and messages. Unfortunately, on some platforms like iOS, this also mutes
|
|
6
|
-
* wavesurfer's audio when using the `WebAudio` backend. This function creates a
|
|
7
|
-
* temporary `<audio>` element that makes sure the WebAudio backend keeps playing
|
|
8
|
-
* when muting the device ringer.
|
|
9
|
-
*
|
|
10
|
-
* @since 5.2.0
|
|
11
|
-
*/
|
|
12
|
-
export default function ignoreSilenceMode() {
|
|
13
|
-
// Set webaudio context with 1 second silent audio 44100 bit rate buffer to allow playing audio even if silent switch is on the device
|
|
14
|
-
const silentAC = new AudioContext();
|
|
15
|
-
const silentBS = silentAC.createBufferSource();
|
|
16
|
-
silentBS.buffer = silentAC.createBuffer(1, 1, 44100);
|
|
17
|
-
silentBS.connect(silentAC.destination);
|
|
18
|
-
silentBS.start();
|
|
19
|
-
|
|
20
|
-
// Set the src to a short bit of url encoded as a silent mp3
|
|
21
|
-
// NOTE The silence MP3 must be high quality, when web audio sounds are played
|
|
22
|
-
// in parallel the web audio sound is mixed to match the bitrate of the html sound
|
|
23
|
-
// 0.01 seconds of silence VBR220-260 Joint Stereo 859B
|
|
24
|
-
const audioData = "data:audio/mpeg;base64,//uQxAAAAAAAAAAAAAAAAAAAAAAAWGluZwAAAA8AAAACAAACcQCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA//////////////////////////////////////////////////////////////////8AAABhTEFNRTMuMTAwA8MAAAAAAAAAABQgJAUHQQAB9AAAAnGMHkkIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//sQxAADgnABGiAAQBCqgCRMAAgEAH///////////////7+n/9FTuQsQH//////2NG0jWUGlio5gLQTOtIoeR2WX////X4s9Atb/JRVCbBUpeRUq//////////////////9RUi0f2jn/+xDECgPCjAEQAABN4AAANIAAAAQVTEFNRTMuMTAwVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVQ==";
|
|
25
|
-
|
|
26
|
-
// disable iOS Airplay (setting the attribute in js doesn't work)
|
|
27
|
-
let tmp = document.createElement("div");
|
|
28
|
-
tmp.innerHTML = '<audio x-webkit-airplay="deny"></audio>';
|
|
29
|
-
|
|
30
|
-
let audioSilentMode = tmp.children.item(0);
|
|
31
|
-
audioSilentMode.src = audioData;
|
|
32
|
-
audioSilentMode.preload = "auto";
|
|
33
|
-
audioSilentMode.type = "audio/mpeg";
|
|
34
|
-
audioSilentMode.disableRemotePlayback = true;
|
|
35
|
-
|
|
36
|
-
// play
|
|
37
|
-
audioSilentMode.play();
|
|
38
|
-
|
|
39
|
-
// cleanup
|
|
40
|
-
audioSilentMode.remove();
|
|
41
|
-
tmp.remove();
|
|
42
|
-
}
|
package/src/util/style.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Apply a map of styles to an element
|
|
3
|
-
*
|
|
4
|
-
* @param {HTMLElement} el The element that the styles will be applied to
|
|
5
|
-
* @param {Object} styles The map of propName: attribute, both are used as-is
|
|
6
|
-
*
|
|
7
|
-
* @return {HTMLElement} el
|
|
8
|
-
*/
|
|
9
|
-
export default function style(el, styles) {
|
|
10
|
-
Object.keys(styles).forEach(prop => {
|
|
11
|
-
if (el.style[prop] !== styles[prop]) {
|
|
12
|
-
el.style[prop] = styles[prop];
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
return el;
|
|
16
|
-
}
|