wavesurfer.js 7.5.1 → 7.5.3
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/dist/plugins/minimap.cjs +1 -1
- package/dist/plugins/minimap.esm.js +1 -1
- package/dist/plugins/minimap.js +1 -1
- package/dist/plugins/minimap.min.js +1 -1
- package/dist/plugins/plugins/record.d.ts +2 -1
- package/dist/plugins/plugins/timeline.d.ts +2 -0
- package/dist/plugins/plugins/zoom.d.ts +16 -0
- package/dist/plugins/record.cjs +1 -1
- package/dist/plugins/record.d.ts +2 -1
- package/dist/plugins/record.esm.js +1 -1
- package/dist/plugins/record.js +1 -1
- package/dist/plugins/record.min.js +1 -1
- package/dist/plugins/timeline.cjs +1 -1
- package/dist/plugins/timeline.d.ts +2 -0
- package/dist/plugins/timeline.esm.js +1 -1
- package/dist/plugins/timeline.js +1 -1
- package/dist/plugins/timeline.min.js +1 -1
- package/dist/plugins/wavesurfer.d.ts +1 -1
- package/dist/plugins/zoom.cjs +1 -1
- package/dist/plugins/zoom.d.ts +16 -0
- package/dist/plugins/zoom.esm.js +1 -1
- package/dist/plugins/zoom.js +1 -1
- package/dist/plugins/zoom.min.js +1 -1
- package/dist/renderer.js +33 -35
- package/dist/wavesurfer.cjs +1 -1
- package/dist/wavesurfer.d.ts +1 -1
- package/dist/wavesurfer.esm.js +1 -1
- package/dist/wavesurfer.min.js +1 -1
- package/package.json +1 -1
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* Zoom in or out on the waveform when scrolling the mouse wheel
|
|
5
5
|
*
|
|
6
6
|
* @author HoodyHuo (https://github.com/HoodyHuo)
|
|
7
|
+
* @author Chris Morbitzer (https://github.com/cmorbitzer)
|
|
8
|
+
* @author Sam Hulick (https://github.com/ffxsam)
|
|
7
9
|
*
|
|
8
10
|
* @example
|
|
9
11
|
* // ... initialising wavesurfer with the plugin
|
|
@@ -18,17 +20,31 @@
|
|
|
18
20
|
*/
|
|
19
21
|
import { BasePlugin, BasePluginEvents } from '../base-plugin.js';
|
|
20
22
|
export type ZoomPluginOptions = {
|
|
23
|
+
/**
|
|
24
|
+
* The amount of zoom per wheel step, e.g. 0.5 means a 50% magnification per scroll
|
|
25
|
+
*
|
|
26
|
+
* @default 0.5
|
|
27
|
+
*/
|
|
21
28
|
scale?: number;
|
|
22
29
|
maxZoom?: number;
|
|
30
|
+
/**
|
|
31
|
+
* The amount the wheel or trackpad needs to be moved before zooming the waveform. Set this value to 0 to have totally
|
|
32
|
+
* fluid zooming (this has a high CPU cost).
|
|
33
|
+
*
|
|
34
|
+
* @default 5
|
|
35
|
+
*/
|
|
36
|
+
deltaThreshold?: number;
|
|
23
37
|
};
|
|
24
38
|
declare const defaultOptions: {
|
|
25
39
|
scale: number;
|
|
40
|
+
deltaThreshold: number;
|
|
26
41
|
};
|
|
27
42
|
export type ZoomPluginEvents = BasePluginEvents;
|
|
28
43
|
declare class ZoomPlugin extends BasePlugin<ZoomPluginEvents, ZoomPluginOptions> {
|
|
29
44
|
protected options: ZoomPluginOptions & typeof defaultOptions;
|
|
30
45
|
private wrapper;
|
|
31
46
|
private container;
|
|
47
|
+
private accumulatedDelta;
|
|
32
48
|
constructor(options?: ZoomPluginOptions);
|
|
33
49
|
static create(options?: ZoomPluginOptions): ZoomPlugin;
|
|
34
50
|
onInit(): void;
|
package/dist/plugins/record.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function e(e,t,
|
|
1
|
+
"use strict";function e(e,i,t,s){return new(t||(t=Promise))((function(r,o){function n(e){try{d(s.next(e))}catch(e){o(e)}}function a(e){try{d(s.throw(e))}catch(e){o(e)}}function d(e){var i;e.done?r(e.value):(i=e.value,i instanceof t?i:new t((function(e){e(i)}))).then(n,a)}d((s=s.apply(e,i||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class i{constructor(){this.listeners={},this.on=this.addEventListener,this.un=this.removeEventListener}addEventListener(e,i,t){if(this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e].add(i),null==t?void 0:t.once){const t=()=>{this.removeEventListener(e,t),this.removeEventListener(e,i)};return this.addEventListener(e,t),t}return()=>this.removeEventListener(e,i)}removeEventListener(e,i){var t;null===(t=this.listeners[e])||void 0===t||t.delete(i)}once(e,i){return this.on(e,i,{once:!0})}unAll(){this.listeners={}}emit(e,...i){this.listeners[e]&&this.listeners[e].forEach((e=>e(...i)))}}class t extends i{constructor(e){super(),this.subscriptions=[],this.options=e}onInit(){}init(e){this.wavesurfer=e,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((e=>e()))}}const s=["audio/webm","audio/wav","audio/mpeg","audio/mp4","audio/mp3"];class r extends t{constructor(e){var i,t,s,r;super(Object.assign(Object.assign({},e),{audioBitsPerSecond:null!==(i=e.audioBitsPerSecond)&&void 0!==i?i:128e3,scrollingWaveform:null!==(t=e.scrollingWaveform)&&void 0!==t&&t,scrollingWaveformWindow:null!==(s=e.scrollingWaveformWindow)&&void 0!==s?s:5,renderRecordedAudio:null===(r=e.renderRecordedAudio)||void 0===r||r})),this.stream=null,this.mediaRecorder=null,this.dataWindow=null,this.isWaveformPaused=!1}static create(e){return new r(e||{})}renderMicStream(e){const i=new AudioContext,t=i.createMediaStreamSource(e),s=i.createAnalyser();t.connect(s);const r=s.frequencyBinCount,o=new Float32Array(r);let n;const a=Math.floor((this.options.scrollingWaveformWindow||0)*i.sampleRate),d=()=>{var e;if(this.isWaveformPaused)return void(n=requestAnimationFrame(d));if(s.getFloatTimeDomainData(o),this.options.scrollingWaveform){const e=Math.min(a,this.dataWindow?this.dataWindow.length+r:r),i=new Float32Array(a);if(this.dataWindow){const t=Math.max(0,a-this.dataWindow.length);i.set(this.dataWindow.slice(-e+r),t)}i.set(o,a-r),this.dataWindow=i}else this.dataWindow=o;const i=this.options.scrollingWaveformWindow;this.wavesurfer&&(null!==(e=this.originalOptions)&&void 0!==e||(this.originalOptions={cursorWidth:this.wavesurfer.options.cursorWidth,interact:this.wavesurfer.options.interact}),this.wavesurfer.options.cursorWidth=0,this.wavesurfer.options.interact=!1,this.wavesurfer.load("",[this.dataWindow],i)),n=requestAnimationFrame(d)};return d(),{onDestroy:()=>{cancelAnimationFrame(n),null==t||t.disconnect(),null==i||i.close()},onEnd:()=>{this.isWaveformPaused=!0,cancelAnimationFrame(n),this.stopMic()}}}startMic(i){return e(this,void 0,void 0,(function*(){let e;try{e=yield navigator.mediaDevices.getUserMedia({audio:!(null==i?void 0:i.deviceId)||{deviceId:i.deviceId}})}catch(e){throw new Error("Error accessing the microphone: "+e.message)}const{onDestroy:t,onEnd:s}=this.renderMicStream(e);return this.subscriptions.push(this.once("destroy",t)),this.subscriptions.push(this.once("record-end",s)),this.stream=e,e}))}stopMic(){this.stream&&(this.stream.getTracks().forEach((e=>e.stop())),this.stream=null,this.mediaRecorder=null)}startRecording(i){return e(this,void 0,void 0,(function*(){const e=this.stream||(yield this.startMic(i));this.dataWindow=null;const t=this.mediaRecorder||new MediaRecorder(e,{mimeType:this.options.mimeType||s.find((e=>MediaRecorder.isTypeSupported(e))),audioBitsPerSecond:this.options.audioBitsPerSecond});this.mediaRecorder=t,this.stopRecording();const r=[];t.ondataavailable=e=>{e.data.size>0&&r.push(e.data)};const o=e=>{var i;const s=new Blob(r,{type:t.mimeType});this.emit(e,s),this.options.renderRecordedAudio&&(this.applyOriginalOptionsIfNeeded(),null===(i=this.wavesurfer)||void 0===i||i.load(URL.createObjectURL(s)))};t.onpause=()=>o("record-pause"),t.onstop=()=>o("record-end"),t.start(),this.isWaveformPaused=!1,this.emit("record-start")}))}isRecording(){var e;return"recording"===(null===(e=this.mediaRecorder)||void 0===e?void 0:e.state)}isPaused(){var e;return"paused"===(null===(e=this.mediaRecorder)||void 0===e?void 0:e.state)}isActive(){var e;return"inactive"!==(null===(e=this.mediaRecorder)||void 0===e?void 0:e.state)}stopRecording(){var e;this.isActive()&&(null===(e=this.mediaRecorder)||void 0===e||e.stop())}pauseRecording(){var e,i;this.isRecording()&&(this.isWaveformPaused=!0,null===(e=this.mediaRecorder)||void 0===e||e.requestData(),null===(i=this.mediaRecorder)||void 0===i||i.pause())}resumeRecording(){var e;this.isPaused()&&(this.isWaveformPaused=!1,null===(e=this.mediaRecorder)||void 0===e||e.resume(),this.emit("record-resume"))}static getAvailableAudioDevices(){return e(this,void 0,void 0,(function*(){return navigator.mediaDevices.enumerateDevices().then((e=>e.filter((e=>"audioinput"===e.kind))))}))}destroy(){this.applyOriginalOptionsIfNeeded(),super.destroy(),this.stopRecording(),this.stopMic()}applyOriginalOptionsIfNeeded(){this.wavesurfer&&this.originalOptions&&(this.wavesurfer.options.cursorWidth=this.originalOptions.cursorWidth,this.wavesurfer.options.interact=this.originalOptions.interact,delete this.originalOptions)}}module.exports=r;
|
package/dist/plugins/record.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export type RecordPluginDeviceOptions = {
|
|
|
22
22
|
};
|
|
23
23
|
export type RecordPluginEvents = BasePluginEvents & {
|
|
24
24
|
'record-start': [];
|
|
25
|
-
'record-pause': [];
|
|
25
|
+
'record-pause': [blob: Blob];
|
|
26
26
|
'record-resume': [];
|
|
27
27
|
'record-end': [blob: Blob];
|
|
28
28
|
};
|
|
@@ -65,5 +65,6 @@ declare class RecordPlugin extends BasePlugin<RecordPluginEvents, RecordPluginOp
|
|
|
65
65
|
static getAvailableAudioDevices(): Promise<MediaDeviceInfo[]>;
|
|
66
66
|
/** Destroy the plugin */
|
|
67
67
|
destroy(): void;
|
|
68
|
+
private applyOriginalOptionsIfNeeded;
|
|
68
69
|
}
|
|
69
70
|
export default RecordPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e,t,
|
|
1
|
+
function e(e,i,t,s){return new(t||(t=Promise))((function(r,o){function n(e){try{d(s.next(e))}catch(e){o(e)}}function a(e){try{d(s.throw(e))}catch(e){o(e)}}function d(e){var i;e.done?r(e.value):(i=e.value,i instanceof t?i:new t((function(e){e(i)}))).then(n,a)}d((s=s.apply(e,i||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class i{constructor(){this.listeners={},this.on=this.addEventListener,this.un=this.removeEventListener}addEventListener(e,i,t){if(this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e].add(i),null==t?void 0:t.once){const t=()=>{this.removeEventListener(e,t),this.removeEventListener(e,i)};return this.addEventListener(e,t),t}return()=>this.removeEventListener(e,i)}removeEventListener(e,i){var t;null===(t=this.listeners[e])||void 0===t||t.delete(i)}once(e,i){return this.on(e,i,{once:!0})}unAll(){this.listeners={}}emit(e,...i){this.listeners[e]&&this.listeners[e].forEach((e=>e(...i)))}}class t extends i{constructor(e){super(),this.subscriptions=[],this.options=e}onInit(){}init(e){this.wavesurfer=e,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((e=>e()))}}const s=["audio/webm","audio/wav","audio/mpeg","audio/mp4","audio/mp3"];class r extends t{constructor(e){var i,t,s,r;super(Object.assign(Object.assign({},e),{audioBitsPerSecond:null!==(i=e.audioBitsPerSecond)&&void 0!==i?i:128e3,scrollingWaveform:null!==(t=e.scrollingWaveform)&&void 0!==t&&t,scrollingWaveformWindow:null!==(s=e.scrollingWaveformWindow)&&void 0!==s?s:5,renderRecordedAudio:null===(r=e.renderRecordedAudio)||void 0===r||r})),this.stream=null,this.mediaRecorder=null,this.dataWindow=null,this.isWaveformPaused=!1}static create(e){return new r(e||{})}renderMicStream(e){const i=new AudioContext,t=i.createMediaStreamSource(e),s=i.createAnalyser();t.connect(s);const r=s.frequencyBinCount,o=new Float32Array(r);let n;const a=Math.floor((this.options.scrollingWaveformWindow||0)*i.sampleRate),d=()=>{var e;if(this.isWaveformPaused)return void(n=requestAnimationFrame(d));if(s.getFloatTimeDomainData(o),this.options.scrollingWaveform){const e=Math.min(a,this.dataWindow?this.dataWindow.length+r:r),i=new Float32Array(a);if(this.dataWindow){const t=Math.max(0,a-this.dataWindow.length);i.set(this.dataWindow.slice(-e+r),t)}i.set(o,a-r),this.dataWindow=i}else this.dataWindow=o;const i=this.options.scrollingWaveformWindow;this.wavesurfer&&(null!==(e=this.originalOptions)&&void 0!==e||(this.originalOptions={cursorWidth:this.wavesurfer.options.cursorWidth,interact:this.wavesurfer.options.interact}),this.wavesurfer.options.cursorWidth=0,this.wavesurfer.options.interact=!1,this.wavesurfer.load("",[this.dataWindow],i)),n=requestAnimationFrame(d)};return d(),{onDestroy:()=>{cancelAnimationFrame(n),null==t||t.disconnect(),null==i||i.close()},onEnd:()=>{this.isWaveformPaused=!0,cancelAnimationFrame(n),this.stopMic()}}}startMic(i){return e(this,void 0,void 0,(function*(){let e;try{e=yield navigator.mediaDevices.getUserMedia({audio:!(null==i?void 0:i.deviceId)||{deviceId:i.deviceId}})}catch(e){throw new Error("Error accessing the microphone: "+e.message)}const{onDestroy:t,onEnd:s}=this.renderMicStream(e);return this.subscriptions.push(this.once("destroy",t)),this.subscriptions.push(this.once("record-end",s)),this.stream=e,e}))}stopMic(){this.stream&&(this.stream.getTracks().forEach((e=>e.stop())),this.stream=null,this.mediaRecorder=null)}startRecording(i){return e(this,void 0,void 0,(function*(){const e=this.stream||(yield this.startMic(i));this.dataWindow=null;const t=this.mediaRecorder||new MediaRecorder(e,{mimeType:this.options.mimeType||s.find((e=>MediaRecorder.isTypeSupported(e))),audioBitsPerSecond:this.options.audioBitsPerSecond});this.mediaRecorder=t,this.stopRecording();const r=[];t.ondataavailable=e=>{e.data.size>0&&r.push(e.data)};const o=e=>{var i;const s=new Blob(r,{type:t.mimeType});this.emit(e,s),this.options.renderRecordedAudio&&(this.applyOriginalOptionsIfNeeded(),null===(i=this.wavesurfer)||void 0===i||i.load(URL.createObjectURL(s)))};t.onpause=()=>o("record-pause"),t.onstop=()=>o("record-end"),t.start(),this.isWaveformPaused=!1,this.emit("record-start")}))}isRecording(){var e;return"recording"===(null===(e=this.mediaRecorder)||void 0===e?void 0:e.state)}isPaused(){var e;return"paused"===(null===(e=this.mediaRecorder)||void 0===e?void 0:e.state)}isActive(){var e;return"inactive"!==(null===(e=this.mediaRecorder)||void 0===e?void 0:e.state)}stopRecording(){var e;this.isActive()&&(null===(e=this.mediaRecorder)||void 0===e||e.stop())}pauseRecording(){var e,i;this.isRecording()&&(this.isWaveformPaused=!0,null===(e=this.mediaRecorder)||void 0===e||e.requestData(),null===(i=this.mediaRecorder)||void 0===i||i.pause())}resumeRecording(){var e;this.isPaused()&&(this.isWaveformPaused=!1,null===(e=this.mediaRecorder)||void 0===e||e.resume(),this.emit("record-resume"))}static getAvailableAudioDevices(){return e(this,void 0,void 0,(function*(){return navigator.mediaDevices.enumerateDevices().then((e=>e.filter((e=>"audioinput"===e.kind))))}))}destroy(){this.applyOriginalOptionsIfNeeded(),super.destroy(),this.stopRecording(),this.stopMic()}applyOriginalOptionsIfNeeded(){this.wavesurfer&&this.originalOptions&&(this.wavesurfer.options.cursorWidth=this.originalOptions.cursorWidth,this.wavesurfer.options.interact=this.originalOptions.interact,delete this.originalOptions)}}export{r as default};
|
package/dist/plugins/record.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e,t,
|
|
1
|
+
function e(e,i,t,s){return new(t||(t=Promise))((function(r,o){function n(e){try{d(s.next(e))}catch(e){o(e)}}function a(e){try{d(s.throw(e))}catch(e){o(e)}}function d(e){var i;e.done?r(e.value):(i=e.value,i instanceof t?i:new t((function(e){e(i)}))).then(n,a)}d((s=s.apply(e,i||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class i{constructor(){this.listeners={},this.on=this.addEventListener,this.un=this.removeEventListener}addEventListener(e,i,t){if(this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e].add(i),null==t?void 0:t.once){const t=()=>{this.removeEventListener(e,t),this.removeEventListener(e,i)};return this.addEventListener(e,t),t}return()=>this.removeEventListener(e,i)}removeEventListener(e,i){var t;null===(t=this.listeners[e])||void 0===t||t.delete(i)}once(e,i){return this.on(e,i,{once:!0})}unAll(){this.listeners={}}emit(e,...i){this.listeners[e]&&this.listeners[e].forEach((e=>e(...i)))}}class t extends i{constructor(e){super(),this.subscriptions=[],this.options=e}onInit(){}init(e){this.wavesurfer=e,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((e=>e()))}}const s=["audio/webm","audio/wav","audio/mpeg","audio/mp4","audio/mp3"];class r extends t{constructor(e){var i,t,s,r;super(Object.assign(Object.assign({},e),{audioBitsPerSecond:null!==(i=e.audioBitsPerSecond)&&void 0!==i?i:128e3,scrollingWaveform:null!==(t=e.scrollingWaveform)&&void 0!==t&&t,scrollingWaveformWindow:null!==(s=e.scrollingWaveformWindow)&&void 0!==s?s:5,renderRecordedAudio:null===(r=e.renderRecordedAudio)||void 0===r||r})),this.stream=null,this.mediaRecorder=null,this.dataWindow=null,this.isWaveformPaused=!1}static create(e){return new r(e||{})}renderMicStream(e){const i=new AudioContext,t=i.createMediaStreamSource(e),s=i.createAnalyser();t.connect(s);const r=s.frequencyBinCount,o=new Float32Array(r);let n;const a=Math.floor((this.options.scrollingWaveformWindow||0)*i.sampleRate),d=()=>{var e;if(this.isWaveformPaused)return void(n=requestAnimationFrame(d));if(s.getFloatTimeDomainData(o),this.options.scrollingWaveform){const e=Math.min(a,this.dataWindow?this.dataWindow.length+r:r),i=new Float32Array(a);if(this.dataWindow){const t=Math.max(0,a-this.dataWindow.length);i.set(this.dataWindow.slice(-e+r),t)}i.set(o,a-r),this.dataWindow=i}else this.dataWindow=o;const i=this.options.scrollingWaveformWindow;this.wavesurfer&&(null!==(e=this.originalOptions)&&void 0!==e||(this.originalOptions={cursorWidth:this.wavesurfer.options.cursorWidth,interact:this.wavesurfer.options.interact}),this.wavesurfer.options.cursorWidth=0,this.wavesurfer.options.interact=!1,this.wavesurfer.load("",[this.dataWindow],i)),n=requestAnimationFrame(d)};return d(),{onDestroy:()=>{cancelAnimationFrame(n),null==t||t.disconnect(),null==i||i.close()},onEnd:()=>{this.isWaveformPaused=!0,cancelAnimationFrame(n),this.stopMic()}}}startMic(i){return e(this,void 0,void 0,(function*(){let e;try{e=yield navigator.mediaDevices.getUserMedia({audio:!(null==i?void 0:i.deviceId)||{deviceId:i.deviceId}})}catch(e){throw new Error("Error accessing the microphone: "+e.message)}const{onDestroy:t,onEnd:s}=this.renderMicStream(e);return this.subscriptions.push(this.once("destroy",t)),this.subscriptions.push(this.once("record-end",s)),this.stream=e,e}))}stopMic(){this.stream&&(this.stream.getTracks().forEach((e=>e.stop())),this.stream=null,this.mediaRecorder=null)}startRecording(i){return e(this,void 0,void 0,(function*(){const e=this.stream||(yield this.startMic(i));this.dataWindow=null;const t=this.mediaRecorder||new MediaRecorder(e,{mimeType:this.options.mimeType||s.find((e=>MediaRecorder.isTypeSupported(e))),audioBitsPerSecond:this.options.audioBitsPerSecond});this.mediaRecorder=t,this.stopRecording();const r=[];t.ondataavailable=e=>{e.data.size>0&&r.push(e.data)};const o=e=>{var i;const s=new Blob(r,{type:t.mimeType});this.emit(e,s),this.options.renderRecordedAudio&&(this.applyOriginalOptionsIfNeeded(),null===(i=this.wavesurfer)||void 0===i||i.load(URL.createObjectURL(s)))};t.onpause=()=>o("record-pause"),t.onstop=()=>o("record-end"),t.start(),this.isWaveformPaused=!1,this.emit("record-start")}))}isRecording(){var e;return"recording"===(null===(e=this.mediaRecorder)||void 0===e?void 0:e.state)}isPaused(){var e;return"paused"===(null===(e=this.mediaRecorder)||void 0===e?void 0:e.state)}isActive(){var e;return"inactive"!==(null===(e=this.mediaRecorder)||void 0===e?void 0:e.state)}stopRecording(){var e;this.isActive()&&(null===(e=this.mediaRecorder)||void 0===e||e.stop())}pauseRecording(){var e,i;this.isRecording()&&(this.isWaveformPaused=!0,null===(e=this.mediaRecorder)||void 0===e||e.requestData(),null===(i=this.mediaRecorder)||void 0===i||i.pause())}resumeRecording(){var e;this.isPaused()&&(this.isWaveformPaused=!1,null===(e=this.mediaRecorder)||void 0===e||e.resume(),this.emit("record-resume"))}static getAvailableAudioDevices(){return e(this,void 0,void 0,(function*(){return navigator.mediaDevices.enumerateDevices().then((e=>e.filter((e=>"audioinput"===e.kind))))}))}destroy(){this.applyOriginalOptionsIfNeeded(),super.destroy(),this.stopRecording(),this.stopMic()}applyOriginalOptionsIfNeeded(){this.wavesurfer&&this.originalOptions&&(this.wavesurfer.options.cursorWidth=this.originalOptions.cursorWidth,this.wavesurfer.options.interact=this.originalOptions.interact,delete this.originalOptions)}}export{r as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,
|
|
1
|
+
!function(e,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):((e="undefined"!=typeof globalThis?globalThis:e||self).WaveSurfer=e.WaveSurfer||{},e.WaveSurfer.Record=i())}(this,(function(){"use strict";function e(e,i,t,s){return new(t||(t=Promise))((function(r,o){function n(e){try{d(s.next(e))}catch(e){o(e)}}function a(e){try{d(s.throw(e))}catch(e){o(e)}}function d(e){var i;e.done?r(e.value):(i=e.value,i instanceof t?i:new t((function(e){e(i)}))).then(n,a)}d((s=s.apply(e,i||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class i{constructor(){this.listeners={},this.on=this.addEventListener,this.un=this.removeEventListener}addEventListener(e,i,t){if(this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e].add(i),null==t?void 0:t.once){const t=()=>{this.removeEventListener(e,t),this.removeEventListener(e,i)};return this.addEventListener(e,t),t}return()=>this.removeEventListener(e,i)}removeEventListener(e,i){var t;null===(t=this.listeners[e])||void 0===t||t.delete(i)}once(e,i){return this.on(e,i,{once:!0})}unAll(){this.listeners={}}emit(e,...i){this.listeners[e]&&this.listeners[e].forEach((e=>e(...i)))}}class t extends i{constructor(e){super(),this.subscriptions=[],this.options=e}onInit(){}init(e){this.wavesurfer=e,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((e=>e()))}}const s=["audio/webm","audio/wav","audio/mpeg","audio/mp4","audio/mp3"];class r extends t{constructor(e){var i,t,s,r;super(Object.assign(Object.assign({},e),{audioBitsPerSecond:null!==(i=e.audioBitsPerSecond)&&void 0!==i?i:128e3,scrollingWaveform:null!==(t=e.scrollingWaveform)&&void 0!==t&&t,scrollingWaveformWindow:null!==(s=e.scrollingWaveformWindow)&&void 0!==s?s:5,renderRecordedAudio:null===(r=e.renderRecordedAudio)||void 0===r||r})),this.stream=null,this.mediaRecorder=null,this.dataWindow=null,this.isWaveformPaused=!1}static create(e){return new r(e||{})}renderMicStream(e){const i=new AudioContext,t=i.createMediaStreamSource(e),s=i.createAnalyser();t.connect(s);const r=s.frequencyBinCount,o=new Float32Array(r);let n;const a=Math.floor((this.options.scrollingWaveformWindow||0)*i.sampleRate),d=()=>{var e;if(this.isWaveformPaused)return void(n=requestAnimationFrame(d));if(s.getFloatTimeDomainData(o),this.options.scrollingWaveform){const e=Math.min(a,this.dataWindow?this.dataWindow.length+r:r),i=new Float32Array(a);if(this.dataWindow){const t=Math.max(0,a-this.dataWindow.length);i.set(this.dataWindow.slice(-e+r),t)}i.set(o,a-r),this.dataWindow=i}else this.dataWindow=o;const i=this.options.scrollingWaveformWindow;this.wavesurfer&&(null!==(e=this.originalOptions)&&void 0!==e||(this.originalOptions={cursorWidth:this.wavesurfer.options.cursorWidth,interact:this.wavesurfer.options.interact}),this.wavesurfer.options.cursorWidth=0,this.wavesurfer.options.interact=!1,this.wavesurfer.load("",[this.dataWindow],i)),n=requestAnimationFrame(d)};return d(),{onDestroy:()=>{cancelAnimationFrame(n),null==t||t.disconnect(),null==i||i.close()},onEnd:()=>{this.isWaveformPaused=!0,cancelAnimationFrame(n),this.stopMic()}}}startMic(i){return e(this,void 0,void 0,(function*(){let e;try{e=yield navigator.mediaDevices.getUserMedia({audio:!(null==i?void 0:i.deviceId)||{deviceId:i.deviceId}})}catch(e){throw new Error("Error accessing the microphone: "+e.message)}const{onDestroy:t,onEnd:s}=this.renderMicStream(e);return this.subscriptions.push(this.once("destroy",t)),this.subscriptions.push(this.once("record-end",s)),this.stream=e,e}))}stopMic(){this.stream&&(this.stream.getTracks().forEach((e=>e.stop())),this.stream=null,this.mediaRecorder=null)}startRecording(i){return e(this,void 0,void 0,(function*(){const e=this.stream||(yield this.startMic(i));this.dataWindow=null;const t=this.mediaRecorder||new MediaRecorder(e,{mimeType:this.options.mimeType||s.find((e=>MediaRecorder.isTypeSupported(e))),audioBitsPerSecond:this.options.audioBitsPerSecond});this.mediaRecorder=t,this.stopRecording();const r=[];t.ondataavailable=e=>{e.data.size>0&&r.push(e.data)};const o=e=>{var i;const s=new Blob(r,{type:t.mimeType});this.emit(e,s),this.options.renderRecordedAudio&&(this.applyOriginalOptionsIfNeeded(),null===(i=this.wavesurfer)||void 0===i||i.load(URL.createObjectURL(s)))};t.onpause=()=>o("record-pause"),t.onstop=()=>o("record-end"),t.start(),this.isWaveformPaused=!1,this.emit("record-start")}))}isRecording(){var e;return"recording"===(null===(e=this.mediaRecorder)||void 0===e?void 0:e.state)}isPaused(){var e;return"paused"===(null===(e=this.mediaRecorder)||void 0===e?void 0:e.state)}isActive(){var e;return"inactive"!==(null===(e=this.mediaRecorder)||void 0===e?void 0:e.state)}stopRecording(){var e;this.isActive()&&(null===(e=this.mediaRecorder)||void 0===e||e.stop())}pauseRecording(){var e,i;this.isRecording()&&(this.isWaveformPaused=!0,null===(e=this.mediaRecorder)||void 0===e||e.requestData(),null===(i=this.mediaRecorder)||void 0===i||i.pause())}resumeRecording(){var e;this.isPaused()&&(this.isWaveformPaused=!1,null===(e=this.mediaRecorder)||void 0===e||e.resume(),this.emit("record-resume"))}static getAvailableAudioDevices(){return e(this,void 0,void 0,(function*(){return navigator.mediaDevices.enumerateDevices().then((e=>e.filter((e=>"audioinput"===e.kind))))}))}destroy(){this.applyOriginalOptionsIfNeeded(),super.destroy(),this.stopRecording(),this.stopMic()}applyOriginalOptionsIfNeeded(){this.wavesurfer&&this.originalOptions&&(this.wavesurfer.options.cursorWidth=this.originalOptions.cursorWidth,this.wavesurfer.options.interact=this.originalOptions.interact,delete this.originalOptions)}}return r}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";class t{constructor(){this.listeners={},this.on=this.addEventListener,this.un=this.removeEventListener}addEventListener(t,e,i){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),null==i?void 0:i.once){const i=()=>{this.removeEventListener(t,i),this.removeEventListener(t,e)};return this.addEventListener(t,i),i}return()=>this.removeEventListener(t,e)}removeEventListener(t,e){var i;null===(i=this.listeners[t])||void 0===i||i.delete(e)}once(t,e){return this.on(t,e,{once:!0})}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}}class e extends t{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}}const i={height:20,formatTimeCallback:t=>{if(t/60>1){return`${Math.floor(t/60)}:${`${(t=Math.round(t%60))<10?"0":""}${t}`}`}return`${Math.round(1e3*t)/1e3}`}};class n extends e{constructor(t){super(t||{}),this.options=Object.assign({},i,t),this.timelineWrapper=this.initTimelineWrapper()}static create(t){return new n(t)}onInit(){var t;if(!this.wavesurfer)throw Error("WaveSurfer is not initialized");let e=this.wavesurfer.getWrapper();if(this.options.container instanceof HTMLElement)e=this.options.container;else if("string"==typeof this.options.container){const t=document.querySelector(this.options.container);if(!t)throw Error(`No Timeline container found matching ${this.options.container}`);e=t}this.options.insertPosition?(e.firstElementChild||e).insertAdjacentElement(this.options.insertPosition,this.timelineWrapper):e.appendChild(this.timelineWrapper),this.subscriptions.push(this.wavesurfer.on("redraw",(()=>this.initTimeline()))),((null===(t=this.wavesurfer)||void 0===t?void 0:t.getDuration())||this.options.duration)&&this.initTimeline()}destroy(){this.timelineWrapper.remove(),super.destroy()}initTimelineWrapper(){const t=document.createElement("div");return t.setAttribute("part","timeline"),t.setAttribute("style","pointer-events: none;"),t}defaultTimeInterval(t){return t>=25?1:5*t>=25?5:15*t>=25?15:60*Math.ceil(.5/t)}defaultPrimaryLabelInterval(t){return t>=25?10:5*t>=25?6:4}defaultSecondaryLabelInterval(t){return t>=25?5:2}initTimeline(){var t,e,i,n,s,r;const
|
|
1
|
+
"use strict";class t{constructor(){this.listeners={},this.on=this.addEventListener,this.un=this.removeEventListener}addEventListener(t,e,i){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),null==i?void 0:i.once){const i=()=>{this.removeEventListener(t,i),this.removeEventListener(t,e)};return this.addEventListener(t,i),i}return()=>this.removeEventListener(t,e)}removeEventListener(t,e){var i;null===(i=this.listeners[t])||void 0===i||i.delete(e)}once(t,e){return this.on(t,e,{once:!0})}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}}class e extends t{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}}const i={height:20,formatTimeCallback:t=>{if(t/60>1){return`${Math.floor(t/60)}:${`${(t=Math.round(t%60))<10?"0":""}${t}`}`}return`${Math.round(1e3*t)/1e3}`}};class n extends e{constructor(t){super(t||{}),this.options=Object.assign({},i,t),this.timelineWrapper=this.initTimelineWrapper()}static create(t){return new n(t)}onInit(){var t;if(!this.wavesurfer)throw Error("WaveSurfer is not initialized");let e=this.wavesurfer.getWrapper();if(this.options.container instanceof HTMLElement)e=this.options.container;else if("string"==typeof this.options.container){const t=document.querySelector(this.options.container);if(!t)throw Error(`No Timeline container found matching ${this.options.container}`);e=t}this.options.insertPosition?(e.firstElementChild||e).insertAdjacentElement(this.options.insertPosition,this.timelineWrapper):e.appendChild(this.timelineWrapper),this.subscriptions.push(this.wavesurfer.on("redraw",(()=>this.initTimeline()))),((null===(t=this.wavesurfer)||void 0===t?void 0:t.getDuration())||this.options.duration)&&this.initTimeline()}destroy(){this.timelineWrapper.remove(),super.destroy()}initTimelineWrapper(){const t=document.createElement("div");return t.setAttribute("part","timeline"),t.setAttribute("style","pointer-events: none;"),t}defaultTimeInterval(t){return t>=25?1:5*t>=25?5:15*t>=25?15:60*Math.ceil(.5/t)}defaultPrimaryLabelInterval(t){return t>=25?10:5*t>=25?6:4}defaultSecondaryLabelInterval(t){return t>=25?5:2}initTimeline(){var t,e,i,n,s,r,o;const l=null!==(i=null!==(e=null===(t=this.wavesurfer)||void 0===t?void 0:t.getDuration())&&void 0!==e?e:this.options.duration)&&void 0!==i?i:0,a=this.timelineWrapper.scrollWidth/l,h=null!==(n=this.options.timeInterval)&&void 0!==n?n:this.defaultTimeInterval(a),p=null!==(s=this.options.primaryLabelInterval)&&void 0!==s?s:this.defaultPrimaryLabelInterval(a),d=this.options.primaryLabelSpacing,u=null!==(r=this.options.secondaryLabelInterval)&&void 0!==r?r:this.defaultSecondaryLabelInterval(a),c=this.options.secondaryLabelSpacing,v="beforebegin"===this.options.insertPosition,m=document.createElement("div");if(m.setAttribute("style",`\n height: ${this.options.height}px;\n overflow: hidden;\n font-size: ${this.options.height/2}px;\n white-space: nowrap;\n position: relative;\n `),v){const t="\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n z-index: 2;\n ";m.setAttribute("style",m.getAttribute("style")+t)}"string"==typeof this.options.style?m.setAttribute("style",m.getAttribute("style")+this.options.style):"object"==typeof this.options.style&&Object.assign(m.style,this.options.style);const f=document.createElement("div");f.setAttribute("style",`\n width: 0;\n height: 50%;\n display: flex;\n flex-direction: column;\n justify-content: ${v?"flex-start":"flex-end"};\n ${v?"top: 0;":"bottom: 0;"}\n overflow: visible;\n border-left: 1px solid currentColor;\n opacity: ${null!==(o=this.options.secondaryLabelOpacity)&&void 0!==o?o:.25};\n position: absolute;\n z-index: 1;\n `);for(let t=0,e=0;t<l;t+=h,e++){const i=f.cloneNode(),n=Math.round(100*t)/100%p==0||d&&e%d==0,s=Math.round(100*t)/100%u==0||c&&e%c==0;(n||s)&&(i.style.height="100%",i.style.textIndent="3px",i.textContent=this.options.formatTimeCallback(t),n&&(i.style.opacity="1"));const r=n?"primary":s?"secondary":"tick";i.setAttribute("part",`timeline-notch timeline-notch-${r}`),i.style.left=t*a+"px",m.appendChild(i)}this.timelineWrapper.innerHTML="",this.timelineWrapper.appendChild(m),this.emit("ready")}}module.exports=n;
|
|
@@ -25,6 +25,8 @@ export type TimelinePluginOptions = {
|
|
|
25
25
|
style?: Partial<CSSStyleDeclaration> | string;
|
|
26
26
|
/** Turn the time into a suitable label for the time. */
|
|
27
27
|
formatTimeCallback?: (seconds: number) => string;
|
|
28
|
+
/** Opacity of the secondary labels, defaults to 0.25 */
|
|
29
|
+
secondaryLabelOpacity?: number;
|
|
28
30
|
};
|
|
29
31
|
declare const defaultOptions: {
|
|
30
32
|
height: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
class t{constructor(){this.listeners={},this.on=this.addEventListener,this.un=this.removeEventListener}addEventListener(t,e,i){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),null==i?void 0:i.once){const i=()=>{this.removeEventListener(t,i),this.removeEventListener(t,e)};return this.addEventListener(t,i),i}return()=>this.removeEventListener(t,e)}removeEventListener(t,e){var i;null===(i=this.listeners[t])||void 0===i||i.delete(e)}once(t,e){return this.on(t,e,{once:!0})}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}}class e extends t{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}}const i={height:20,formatTimeCallback:t=>{if(t/60>1){return`${Math.floor(t/60)}:${`${(t=Math.round(t%60))<10?"0":""}${t}`}`}return`${Math.round(1e3*t)/1e3}`}};class n extends e{constructor(t){super(t||{}),this.options=Object.assign({},i,t),this.timelineWrapper=this.initTimelineWrapper()}static create(t){return new n(t)}onInit(){var t;if(!this.wavesurfer)throw Error("WaveSurfer is not initialized");let e=this.wavesurfer.getWrapper();if(this.options.container instanceof HTMLElement)e=this.options.container;else if("string"==typeof this.options.container){const t=document.querySelector(this.options.container);if(!t)throw Error(`No Timeline container found matching ${this.options.container}`);e=t}this.options.insertPosition?(e.firstElementChild||e).insertAdjacentElement(this.options.insertPosition,this.timelineWrapper):e.appendChild(this.timelineWrapper),this.subscriptions.push(this.wavesurfer.on("redraw",(()=>this.initTimeline()))),((null===(t=this.wavesurfer)||void 0===t?void 0:t.getDuration())||this.options.duration)&&this.initTimeline()}destroy(){this.timelineWrapper.remove(),super.destroy()}initTimelineWrapper(){const t=document.createElement("div");return t.setAttribute("part","timeline"),t.setAttribute("style","pointer-events: none;"),t}defaultTimeInterval(t){return t>=25?1:5*t>=25?5:15*t>=25?15:60*Math.ceil(.5/t)}defaultPrimaryLabelInterval(t){return t>=25?10:5*t>=25?6:4}defaultSecondaryLabelInterval(t){return t>=25?5:2}initTimeline(){var t,e,i,n,s,r;const
|
|
1
|
+
class t{constructor(){this.listeners={},this.on=this.addEventListener,this.un=this.removeEventListener}addEventListener(t,e,i){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),null==i?void 0:i.once){const i=()=>{this.removeEventListener(t,i),this.removeEventListener(t,e)};return this.addEventListener(t,i),i}return()=>this.removeEventListener(t,e)}removeEventListener(t,e){var i;null===(i=this.listeners[t])||void 0===i||i.delete(e)}once(t,e){return this.on(t,e,{once:!0})}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}}class e extends t{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}}const i={height:20,formatTimeCallback:t=>{if(t/60>1){return`${Math.floor(t/60)}:${`${(t=Math.round(t%60))<10?"0":""}${t}`}`}return`${Math.round(1e3*t)/1e3}`}};class n extends e{constructor(t){super(t||{}),this.options=Object.assign({},i,t),this.timelineWrapper=this.initTimelineWrapper()}static create(t){return new n(t)}onInit(){var t;if(!this.wavesurfer)throw Error("WaveSurfer is not initialized");let e=this.wavesurfer.getWrapper();if(this.options.container instanceof HTMLElement)e=this.options.container;else if("string"==typeof this.options.container){const t=document.querySelector(this.options.container);if(!t)throw Error(`No Timeline container found matching ${this.options.container}`);e=t}this.options.insertPosition?(e.firstElementChild||e).insertAdjacentElement(this.options.insertPosition,this.timelineWrapper):e.appendChild(this.timelineWrapper),this.subscriptions.push(this.wavesurfer.on("redraw",(()=>this.initTimeline()))),((null===(t=this.wavesurfer)||void 0===t?void 0:t.getDuration())||this.options.duration)&&this.initTimeline()}destroy(){this.timelineWrapper.remove(),super.destroy()}initTimelineWrapper(){const t=document.createElement("div");return t.setAttribute("part","timeline"),t.setAttribute("style","pointer-events: none;"),t}defaultTimeInterval(t){return t>=25?1:5*t>=25?5:15*t>=25?15:60*Math.ceil(.5/t)}defaultPrimaryLabelInterval(t){return t>=25?10:5*t>=25?6:4}defaultSecondaryLabelInterval(t){return t>=25?5:2}initTimeline(){var t,e,i,n,s,r,o;const l=null!==(i=null!==(e=null===(t=this.wavesurfer)||void 0===t?void 0:t.getDuration())&&void 0!==e?e:this.options.duration)&&void 0!==i?i:0,a=this.timelineWrapper.scrollWidth/l,h=null!==(n=this.options.timeInterval)&&void 0!==n?n:this.defaultTimeInterval(a),p=null!==(s=this.options.primaryLabelInterval)&&void 0!==s?s:this.defaultPrimaryLabelInterval(a),d=this.options.primaryLabelSpacing,u=null!==(r=this.options.secondaryLabelInterval)&&void 0!==r?r:this.defaultSecondaryLabelInterval(a),c=this.options.secondaryLabelSpacing,v="beforebegin"===this.options.insertPosition,m=document.createElement("div");if(m.setAttribute("style",`\n height: ${this.options.height}px;\n overflow: hidden;\n font-size: ${this.options.height/2}px;\n white-space: nowrap;\n position: relative;\n `),v){const t="\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n z-index: 2;\n ";m.setAttribute("style",m.getAttribute("style")+t)}"string"==typeof this.options.style?m.setAttribute("style",m.getAttribute("style")+this.options.style):"object"==typeof this.options.style&&Object.assign(m.style,this.options.style);const f=document.createElement("div");f.setAttribute("style",`\n width: 0;\n height: 50%;\n display: flex;\n flex-direction: column;\n justify-content: ${v?"flex-start":"flex-end"};\n ${v?"top: 0;":"bottom: 0;"}\n overflow: visible;\n border-left: 1px solid currentColor;\n opacity: ${null!==(o=this.options.secondaryLabelOpacity)&&void 0!==o?o:.25};\n position: absolute;\n z-index: 1;\n `);for(let t=0,e=0;t<l;t+=h,e++){const i=f.cloneNode(),n=Math.round(100*t)/100%p==0||d&&e%d==0,s=Math.round(100*t)/100%u==0||c&&e%c==0;(n||s)&&(i.style.height="100%",i.style.textIndent="3px",i.textContent=this.options.formatTimeCallback(t),n&&(i.style.opacity="1"));const r=n?"primary":s?"secondary":"tick";i.setAttribute("part",`timeline-notch timeline-notch-${r}`),i.style.left=t*a+"px",m.appendChild(i)}this.timelineWrapper.innerHTML="",this.timelineWrapper.appendChild(m),this.emit("ready")}}export{n as default};
|
package/dist/plugins/timeline.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class t{constructor(){this.listeners={},this.on=this.addEventListener,this.un=this.removeEventListener}addEventListener(t,e,i){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),null==i?void 0:i.once){const i=()=>{this.removeEventListener(t,i),this.removeEventListener(t,e)};return this.addEventListener(t,i),i}return()=>this.removeEventListener(t,e)}removeEventListener(t,e){var i;null===(i=this.listeners[t])||void 0===i||i.delete(e)}once(t,e){return this.on(t,e,{once:!0})}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}}class e extends t{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}}const i={height:20,formatTimeCallback:t=>{if(t/60>1){return`${Math.floor(t/60)}:${`${(t=Math.round(t%60))<10?"0":""}${t}`}`}return`${Math.round(1e3*t)/1e3}`}};class n extends e{constructor(t){super(t||{}),this.options=Object.assign({},i,t),this.timelineWrapper=this.initTimelineWrapper()}static create(t){return new n(t)}onInit(){var t;if(!this.wavesurfer)throw Error("WaveSurfer is not initialized");let e=this.wavesurfer.getWrapper();if(this.options.container instanceof HTMLElement)e=this.options.container;else if("string"==typeof this.options.container){const t=document.querySelector(this.options.container);if(!t)throw Error(`No Timeline container found matching ${this.options.container}`);e=t}this.options.insertPosition?(e.firstElementChild||e).insertAdjacentElement(this.options.insertPosition,this.timelineWrapper):e.appendChild(this.timelineWrapper),this.subscriptions.push(this.wavesurfer.on("redraw",(()=>this.initTimeline()))),((null===(t=this.wavesurfer)||void 0===t?void 0:t.getDuration())||this.options.duration)&&this.initTimeline()}destroy(){this.timelineWrapper.remove(),super.destroy()}initTimelineWrapper(){const t=document.createElement("div");return t.setAttribute("part","timeline"),t.setAttribute("style","pointer-events: none;"),t}defaultTimeInterval(t){return t>=25?1:5*t>=25?5:15*t>=25?15:60*Math.ceil(.5/t)}defaultPrimaryLabelInterval(t){return t>=25?10:5*t>=25?6:4}defaultSecondaryLabelInterval(t){return t>=25?5:2}initTimeline(){var t,e,i,n,s,r;const
|
|
1
|
+
class t{constructor(){this.listeners={},this.on=this.addEventListener,this.un=this.removeEventListener}addEventListener(t,e,i){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),null==i?void 0:i.once){const i=()=>{this.removeEventListener(t,i),this.removeEventListener(t,e)};return this.addEventListener(t,i),i}return()=>this.removeEventListener(t,e)}removeEventListener(t,e){var i;null===(i=this.listeners[t])||void 0===i||i.delete(e)}once(t,e){return this.on(t,e,{once:!0})}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}}class e extends t{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}}const i={height:20,formatTimeCallback:t=>{if(t/60>1){return`${Math.floor(t/60)}:${`${(t=Math.round(t%60))<10?"0":""}${t}`}`}return`${Math.round(1e3*t)/1e3}`}};class n extends e{constructor(t){super(t||{}),this.options=Object.assign({},i,t),this.timelineWrapper=this.initTimelineWrapper()}static create(t){return new n(t)}onInit(){var t;if(!this.wavesurfer)throw Error("WaveSurfer is not initialized");let e=this.wavesurfer.getWrapper();if(this.options.container instanceof HTMLElement)e=this.options.container;else if("string"==typeof this.options.container){const t=document.querySelector(this.options.container);if(!t)throw Error(`No Timeline container found matching ${this.options.container}`);e=t}this.options.insertPosition?(e.firstElementChild||e).insertAdjacentElement(this.options.insertPosition,this.timelineWrapper):e.appendChild(this.timelineWrapper),this.subscriptions.push(this.wavesurfer.on("redraw",(()=>this.initTimeline()))),((null===(t=this.wavesurfer)||void 0===t?void 0:t.getDuration())||this.options.duration)&&this.initTimeline()}destroy(){this.timelineWrapper.remove(),super.destroy()}initTimelineWrapper(){const t=document.createElement("div");return t.setAttribute("part","timeline"),t.setAttribute("style","pointer-events: none;"),t}defaultTimeInterval(t){return t>=25?1:5*t>=25?5:15*t>=25?15:60*Math.ceil(.5/t)}defaultPrimaryLabelInterval(t){return t>=25?10:5*t>=25?6:4}defaultSecondaryLabelInterval(t){return t>=25?5:2}initTimeline(){var t,e,i,n,s,r,o;const l=null!==(i=null!==(e=null===(t=this.wavesurfer)||void 0===t?void 0:t.getDuration())&&void 0!==e?e:this.options.duration)&&void 0!==i?i:0,a=this.timelineWrapper.scrollWidth/l,h=null!==(n=this.options.timeInterval)&&void 0!==n?n:this.defaultTimeInterval(a),p=null!==(s=this.options.primaryLabelInterval)&&void 0!==s?s:this.defaultPrimaryLabelInterval(a),d=this.options.primaryLabelSpacing,u=null!==(r=this.options.secondaryLabelInterval)&&void 0!==r?r:this.defaultSecondaryLabelInterval(a),c=this.options.secondaryLabelSpacing,v="beforebegin"===this.options.insertPosition,m=document.createElement("div");if(m.setAttribute("style",`\n height: ${this.options.height}px;\n overflow: hidden;\n font-size: ${this.options.height/2}px;\n white-space: nowrap;\n position: relative;\n `),v){const t="\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n z-index: 2;\n ";m.setAttribute("style",m.getAttribute("style")+t)}"string"==typeof this.options.style?m.setAttribute("style",m.getAttribute("style")+this.options.style):"object"==typeof this.options.style&&Object.assign(m.style,this.options.style);const f=document.createElement("div");f.setAttribute("style",`\n width: 0;\n height: 50%;\n display: flex;\n flex-direction: column;\n justify-content: ${v?"flex-start":"flex-end"};\n ${v?"top: 0;":"bottom: 0;"}\n overflow: visible;\n border-left: 1px solid currentColor;\n opacity: ${null!==(o=this.options.secondaryLabelOpacity)&&void 0!==o?o:.25};\n position: absolute;\n z-index: 1;\n `);for(let t=0,e=0;t<l;t+=h,e++){const i=f.cloneNode(),n=Math.round(100*t)/100%p==0||d&&e%d==0,s=Math.round(100*t)/100%u==0||c&&e%c==0;(n||s)&&(i.style.height="100%",i.style.textIndent="3px",i.textContent=this.options.formatTimeCallback(t),n&&(i.style.opacity="1"));const r=n?"primary":s?"secondary":"tick";i.setAttribute("part",`timeline-notch timeline-notch-${r}`),i.style.left=t*a+"px",m.appendChild(i)}this.timelineWrapper.innerHTML="",this.timelineWrapper.appendChild(m),this.emit("ready")}}export{n as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):((t="undefined"!=typeof globalThis?globalThis:t||self).WaveSurfer=t.WaveSurfer||{},t.WaveSurfer.Timeline=e())}(this,(function(){"use strict";class t{constructor(){this.listeners={},this.on=this.addEventListener,this.un=this.removeEventListener}addEventListener(t,e,i){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),null==i?void 0:i.once){const i=()=>{this.removeEventListener(t,i),this.removeEventListener(t,e)};return this.addEventListener(t,i),i}return()=>this.removeEventListener(t,e)}removeEventListener(t,e){var i;null===(i=this.listeners[t])||void 0===i||i.delete(e)}once(t,e){return this.on(t,e,{once:!0})}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}}class e extends t{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}}const i={height:20,formatTimeCallback:t=>{if(t/60>1){return`${Math.floor(t/60)}:${`${(t=Math.round(t%60))<10?"0":""}${t}`}`}return`${Math.round(1e3*t)/1e3}`}};class n extends e{constructor(t){super(t||{}),this.options=Object.assign({},i,t),this.timelineWrapper=this.initTimelineWrapper()}static create(t){return new n(t)}onInit(){var t;if(!this.wavesurfer)throw Error("WaveSurfer is not initialized");let e=this.wavesurfer.getWrapper();if(this.options.container instanceof HTMLElement)e=this.options.container;else if("string"==typeof this.options.container){const t=document.querySelector(this.options.container);if(!t)throw Error(`No Timeline container found matching ${this.options.container}`);e=t}this.options.insertPosition?(e.firstElementChild||e).insertAdjacentElement(this.options.insertPosition,this.timelineWrapper):e.appendChild(this.timelineWrapper),this.subscriptions.push(this.wavesurfer.on("redraw",(()=>this.initTimeline()))),((null===(t=this.wavesurfer)||void 0===t?void 0:t.getDuration())||this.options.duration)&&this.initTimeline()}destroy(){this.timelineWrapper.remove(),super.destroy()}initTimelineWrapper(){const t=document.createElement("div");return t.setAttribute("part","timeline"),t.setAttribute("style","pointer-events: none;"),t}defaultTimeInterval(t){return t>=25?1:5*t>=25?5:15*t>=25?15:60*Math.ceil(.5/t)}defaultPrimaryLabelInterval(t){return t>=25?10:5*t>=25?6:4}defaultSecondaryLabelInterval(t){return t>=25?5:2}initTimeline(){var t,e,i,n,s,r;const
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):((t="undefined"!=typeof globalThis?globalThis:t||self).WaveSurfer=t.WaveSurfer||{},t.WaveSurfer.Timeline=e())}(this,(function(){"use strict";class t{constructor(){this.listeners={},this.on=this.addEventListener,this.un=this.removeEventListener}addEventListener(t,e,i){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),null==i?void 0:i.once){const i=()=>{this.removeEventListener(t,i),this.removeEventListener(t,e)};return this.addEventListener(t,i),i}return()=>this.removeEventListener(t,e)}removeEventListener(t,e){var i;null===(i=this.listeners[t])||void 0===i||i.delete(e)}once(t,e){return this.on(t,e,{once:!0})}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}}class e extends t{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}}const i={height:20,formatTimeCallback:t=>{if(t/60>1){return`${Math.floor(t/60)}:${`${(t=Math.round(t%60))<10?"0":""}${t}`}`}return`${Math.round(1e3*t)/1e3}`}};class n extends e{constructor(t){super(t||{}),this.options=Object.assign({},i,t),this.timelineWrapper=this.initTimelineWrapper()}static create(t){return new n(t)}onInit(){var t;if(!this.wavesurfer)throw Error("WaveSurfer is not initialized");let e=this.wavesurfer.getWrapper();if(this.options.container instanceof HTMLElement)e=this.options.container;else if("string"==typeof this.options.container){const t=document.querySelector(this.options.container);if(!t)throw Error(`No Timeline container found matching ${this.options.container}`);e=t}this.options.insertPosition?(e.firstElementChild||e).insertAdjacentElement(this.options.insertPosition,this.timelineWrapper):e.appendChild(this.timelineWrapper),this.subscriptions.push(this.wavesurfer.on("redraw",(()=>this.initTimeline()))),((null===(t=this.wavesurfer)||void 0===t?void 0:t.getDuration())||this.options.duration)&&this.initTimeline()}destroy(){this.timelineWrapper.remove(),super.destroy()}initTimelineWrapper(){const t=document.createElement("div");return t.setAttribute("part","timeline"),t.setAttribute("style","pointer-events: none;"),t}defaultTimeInterval(t){return t>=25?1:5*t>=25?5:15*t>=25?15:60*Math.ceil(.5/t)}defaultPrimaryLabelInterval(t){return t>=25?10:5*t>=25?6:4}defaultSecondaryLabelInterval(t){return t>=25?5:2}initTimeline(){var t,e,i,n,s,r,o;const l=null!==(i=null!==(e=null===(t=this.wavesurfer)||void 0===t?void 0:t.getDuration())&&void 0!==e?e:this.options.duration)&&void 0!==i?i:0,a=this.timelineWrapper.scrollWidth/l,h=null!==(n=this.options.timeInterval)&&void 0!==n?n:this.defaultTimeInterval(a),p=null!==(s=this.options.primaryLabelInterval)&&void 0!==s?s:this.defaultPrimaryLabelInterval(a),d=this.options.primaryLabelSpacing,u=null!==(r=this.options.secondaryLabelInterval)&&void 0!==r?r:this.defaultSecondaryLabelInterval(a),c=this.options.secondaryLabelSpacing,f="beforebegin"===this.options.insertPosition,v=document.createElement("div");if(v.setAttribute("style",`\n height: ${this.options.height}px;\n overflow: hidden;\n font-size: ${this.options.height/2}px;\n white-space: nowrap;\n position: relative;\n `),f){const t="\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n z-index: 2;\n ";v.setAttribute("style",v.getAttribute("style")+t)}"string"==typeof this.options.style?v.setAttribute("style",v.getAttribute("style")+this.options.style):"object"==typeof this.options.style&&Object.assign(v.style,this.options.style);const m=document.createElement("div");m.setAttribute("style",`\n width: 0;\n height: 50%;\n display: flex;\n flex-direction: column;\n justify-content: ${f?"flex-start":"flex-end"};\n ${f?"top: 0;":"bottom: 0;"}\n overflow: visible;\n border-left: 1px solid currentColor;\n opacity: ${null!==(o=this.options.secondaryLabelOpacity)&&void 0!==o?o:.25};\n position: absolute;\n z-index: 1;\n `);for(let t=0,e=0;t<l;t+=h,e++){const i=m.cloneNode(),n=Math.round(100*t)/100%p==0||d&&e%d==0,s=Math.round(100*t)/100%u==0||c&&e%c==0;(n||s)&&(i.style.height="100%",i.style.textIndent="3px",i.textContent=this.options.formatTimeCallback(t),n&&(i.style.opacity="1"));const r=n?"primary":s?"secondary":"tick";i.setAttribute("part",`timeline-notch timeline-notch-${r}`),i.style.left=t*a+"px",v.appendChild(i)}this.timelineWrapper.innerHTML="",this.timelineWrapper.appendChild(v),this.emit("ready")}}return n}));
|
|
@@ -56,7 +56,7 @@ export type WaveSurferOptions = {
|
|
|
56
56
|
/** Decoding sample rate. Doesn't affect the playback. Defaults to 8000 */
|
|
57
57
|
sampleRate?: number;
|
|
58
58
|
/** Render each audio channel as a separate waveform */
|
|
59
|
-
splitChannels?: WaveSurferOptions[];
|
|
59
|
+
splitChannels?: Partial<WaveSurferOptions>[];
|
|
60
60
|
/** Stretch the waveform to the full height */
|
|
61
61
|
normalize?: boolean;
|
|
62
62
|
/** The list of plugins to initialize on start */
|
package/dist/plugins/zoom.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";class
|
|
1
|
+
"use strict";class t{constructor(){this.listeners={},this.on=this.addEventListener,this.un=this.removeEventListener}addEventListener(t,e,s){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),null==s?void 0:s.once){const s=()=>{this.removeEventListener(t,s),this.removeEventListener(t,e)};return this.addEventListener(t,s),s}return()=>this.removeEventListener(t,e)}removeEventListener(t,e){var s;null===(s=this.listeners[t])||void 0===s||s.delete(e)}once(t,e){return this.on(t,e,{once:!0})}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}}class e extends t{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}}const s={scale:.5,deltaThreshold:5};class i extends e{constructor(t){super(t||{}),this.wrapper=void 0,this.container=null,this.accumulatedDelta=0,this.onWheel=t=>{if(this.wavesurfer&&this.container&&!(Math.abs(t.deltaX)>=Math.abs(t.deltaY))&&(t.preventDefault(),this.accumulatedDelta+=-t.deltaY,0===this.options.deltaThreshold||Math.abs(this.accumulatedDelta)>=this.options.deltaThreshold)){const e=this.wavesurfer.getDuration(),s=this.wavesurfer.options.minPxPerSec,i=t.clientX,r=this.container.clientWidth,n=(this.wavesurfer.getScroll()+i)/s,o=this.calculateNewZoom(s,this.accumulatedDelta),a=r/o*(i/r);o*e<r?(this.wavesurfer.zoom(r/e),this.container.scrollLeft=0):(this.wavesurfer.zoom(o),this.container.scrollLeft=(n-a)*o),this.accumulatedDelta=0}},this.calculateNewZoom=(t,e)=>{const s=Math.max(0,t+e*this.options.scale);return void 0===this.options.maxZoom?s:Math.min(s,this.options.maxZoom)},this.options=Object.assign({},s,t)}static create(t){return new i(t)}onInit(){var t;this.wrapper=null===(t=this.wavesurfer)||void 0===t?void 0:t.getWrapper(),this.wrapper&&(this.container=this.wrapper.parentElement,this.wrapper.addEventListener("wheel",this.onWheel))}destroy(){this.wrapper&&this.wrapper.removeEventListener("wheel",this.onWheel),super.destroy()}}module.exports=i;
|
package/dist/plugins/zoom.d.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* Zoom in or out on the waveform when scrolling the mouse wheel
|
|
5
5
|
*
|
|
6
6
|
* @author HoodyHuo (https://github.com/HoodyHuo)
|
|
7
|
+
* @author Chris Morbitzer (https://github.com/cmorbitzer)
|
|
8
|
+
* @author Sam Hulick (https://github.com/ffxsam)
|
|
7
9
|
*
|
|
8
10
|
* @example
|
|
9
11
|
* // ... initialising wavesurfer with the plugin
|
|
@@ -18,17 +20,31 @@
|
|
|
18
20
|
*/
|
|
19
21
|
import { BasePlugin, BasePluginEvents } from '../base-plugin.js';
|
|
20
22
|
export type ZoomPluginOptions = {
|
|
23
|
+
/**
|
|
24
|
+
* The amount of zoom per wheel step, e.g. 0.5 means a 50% magnification per scroll
|
|
25
|
+
*
|
|
26
|
+
* @default 0.5
|
|
27
|
+
*/
|
|
21
28
|
scale?: number;
|
|
22
29
|
maxZoom?: number;
|
|
30
|
+
/**
|
|
31
|
+
* The amount the wheel or trackpad needs to be moved before zooming the waveform. Set this value to 0 to have totally
|
|
32
|
+
* fluid zooming (this has a high CPU cost).
|
|
33
|
+
*
|
|
34
|
+
* @default 5
|
|
35
|
+
*/
|
|
36
|
+
deltaThreshold?: number;
|
|
23
37
|
};
|
|
24
38
|
declare const defaultOptions: {
|
|
25
39
|
scale: number;
|
|
40
|
+
deltaThreshold: number;
|
|
26
41
|
};
|
|
27
42
|
export type ZoomPluginEvents = BasePluginEvents;
|
|
28
43
|
declare class ZoomPlugin extends BasePlugin<ZoomPluginEvents, ZoomPluginOptions> {
|
|
29
44
|
protected options: ZoomPluginOptions & typeof defaultOptions;
|
|
30
45
|
private wrapper;
|
|
31
46
|
private container;
|
|
47
|
+
private accumulatedDelta;
|
|
32
48
|
constructor(options?: ZoomPluginOptions);
|
|
33
49
|
static create(options?: ZoomPluginOptions): ZoomPlugin;
|
|
34
50
|
onInit(): void;
|
package/dist/plugins/zoom.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class
|
|
1
|
+
class t{constructor(){this.listeners={},this.on=this.addEventListener,this.un=this.removeEventListener}addEventListener(t,e,s){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),null==s?void 0:s.once){const s=()=>{this.removeEventListener(t,s),this.removeEventListener(t,e)};return this.addEventListener(t,s),s}return()=>this.removeEventListener(t,e)}removeEventListener(t,e){var s;null===(s=this.listeners[t])||void 0===s||s.delete(e)}once(t,e){return this.on(t,e,{once:!0})}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}}class e extends t{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}}const s={scale:.5,deltaThreshold:5};class i extends e{constructor(t){super(t||{}),this.wrapper=void 0,this.container=null,this.accumulatedDelta=0,this.onWheel=t=>{if(this.wavesurfer&&this.container&&!(Math.abs(t.deltaX)>=Math.abs(t.deltaY))&&(t.preventDefault(),this.accumulatedDelta+=-t.deltaY,0===this.options.deltaThreshold||Math.abs(this.accumulatedDelta)>=this.options.deltaThreshold)){const e=this.wavesurfer.getDuration(),s=this.wavesurfer.options.minPxPerSec,i=t.clientX,r=this.container.clientWidth,n=(this.wavesurfer.getScroll()+i)/s,o=this.calculateNewZoom(s,this.accumulatedDelta),a=r/o*(i/r);o*e<r?(this.wavesurfer.zoom(r/e),this.container.scrollLeft=0):(this.wavesurfer.zoom(o),this.container.scrollLeft=(n-a)*o),this.accumulatedDelta=0}},this.calculateNewZoom=(t,e)=>{const s=Math.max(0,t+e*this.options.scale);return void 0===this.options.maxZoom?s:Math.min(s,this.options.maxZoom)},this.options=Object.assign({},s,t)}static create(t){return new i(t)}onInit(){var t;this.wrapper=null===(t=this.wavesurfer)||void 0===t?void 0:t.getWrapper(),this.wrapper&&(this.container=this.wrapper.parentElement,this.wrapper.addEventListener("wheel",this.onWheel))}destroy(){this.wrapper&&this.wrapper.removeEventListener("wheel",this.onWheel),super.destroy()}}export{i as default};
|
package/dist/plugins/zoom.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class
|
|
1
|
+
class t{constructor(){this.listeners={},this.on=this.addEventListener,this.un=this.removeEventListener}addEventListener(t,e,s){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),null==s?void 0:s.once){const s=()=>{this.removeEventListener(t,s),this.removeEventListener(t,e)};return this.addEventListener(t,s),s}return()=>this.removeEventListener(t,e)}removeEventListener(t,e){var s;null===(s=this.listeners[t])||void 0===s||s.delete(e)}once(t,e){return this.on(t,e,{once:!0})}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}}class e extends t{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}}const s={scale:.5,deltaThreshold:5};class i extends e{constructor(t){super(t||{}),this.wrapper=void 0,this.container=null,this.accumulatedDelta=0,this.onWheel=t=>{if(this.wavesurfer&&this.container&&!(Math.abs(t.deltaX)>=Math.abs(t.deltaY))&&(t.preventDefault(),this.accumulatedDelta+=-t.deltaY,0===this.options.deltaThreshold||Math.abs(this.accumulatedDelta)>=this.options.deltaThreshold)){const e=this.wavesurfer.getDuration(),s=this.wavesurfer.options.minPxPerSec,i=t.clientX,r=this.container.clientWidth,n=(this.wavesurfer.getScroll()+i)/s,o=this.calculateNewZoom(s,this.accumulatedDelta),a=r/o*(i/r);o*e<r?(this.wavesurfer.zoom(r/e),this.container.scrollLeft=0):(this.wavesurfer.zoom(o),this.container.scrollLeft=(n-a)*o),this.accumulatedDelta=0}},this.calculateNewZoom=(t,e)=>{const s=Math.max(0,t+e*this.options.scale);return void 0===this.options.maxZoom?s:Math.min(s,this.options.maxZoom)},this.options=Object.assign({},s,t)}static create(t){return new i(t)}onInit(){var t;this.wrapper=null===(t=this.wavesurfer)||void 0===t?void 0:t.getWrapper(),this.wrapper&&(this.container=this.wrapper.parentElement,this.wrapper.addEventListener("wheel",this.onWheel))}destroy(){this.wrapper&&this.wrapper.removeEventListener("wheel",this.onWheel),super.destroy()}}export{i as default};
|
package/dist/plugins/zoom.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e="undefined"!=typeof globalThis?globalThis:e||self).WaveSurfer=e.WaveSurfer||{},e.WaveSurfer.Zoom=t())}(this,(function(){"use strict";class e{constructor(){this.listeners={},this.on=this.addEventListener,this.un=this.removeEventListener}addEventListener(e,t,s){if(this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e].add(t),null==s?void 0:s.once){const s=()=>{this.removeEventListener(e,s),this.removeEventListener(e,t)};return this.addEventListener(e,s),s}return()=>this.removeEventListener(e,t)}removeEventListener(e,t){var s;null===(s=this.listeners[e])||void 0===s||s.delete(t)}once(e,t){return this.on(e,t,{once:!0})}unAll(){this.listeners={}}emit(e,...t){this.listeners[e]&&this.listeners[e].forEach((e=>e(...t)))}}class t extends e{constructor(e){super(),this.subscriptions=[],this.options=e}onInit(){}init(e){this.wavesurfer=e,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((e=>e()))}}const s={scale:.5};class i extends t{constructor(e){super(e||{}),this.wrapper=void 0,this.container=null,this.onWheel=e=>{if(
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e="undefined"!=typeof globalThis?globalThis:e||self).WaveSurfer=e.WaveSurfer||{},e.WaveSurfer.Zoom=t())}(this,(function(){"use strict";class e{constructor(){this.listeners={},this.on=this.addEventListener,this.un=this.removeEventListener}addEventListener(e,t,s){if(this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e].add(t),null==s?void 0:s.once){const s=()=>{this.removeEventListener(e,s),this.removeEventListener(e,t)};return this.addEventListener(e,s),s}return()=>this.removeEventListener(e,t)}removeEventListener(e,t){var s;null===(s=this.listeners[e])||void 0===s||s.delete(t)}once(e,t){return this.on(e,t,{once:!0})}unAll(){this.listeners={}}emit(e,...t){this.listeners[e]&&this.listeners[e].forEach((e=>e(...t)))}}class t extends e{constructor(e){super(),this.subscriptions=[],this.options=e}onInit(){}init(e){this.wavesurfer=e,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((e=>e()))}}const s={scale:.5,deltaThreshold:5};class i extends t{constructor(e){super(e||{}),this.wrapper=void 0,this.container=null,this.accumulatedDelta=0,this.onWheel=e=>{if(this.wavesurfer&&this.container&&!(Math.abs(e.deltaX)>=Math.abs(e.deltaY))&&(e.preventDefault(),this.accumulatedDelta+=-e.deltaY,0===this.options.deltaThreshold||Math.abs(this.accumulatedDelta)>=this.options.deltaThreshold)){const t=this.wavesurfer.getDuration(),s=this.wavesurfer.options.minPxPerSec,i=e.clientX,r=this.container.clientWidth,n=(this.wavesurfer.getScroll()+i)/s,o=this.calculateNewZoom(s,this.accumulatedDelta),a=r/o*(i/r);o*t<r?(this.wavesurfer.zoom(r/t),this.container.scrollLeft=0):(this.wavesurfer.zoom(o),this.container.scrollLeft=(n-a)*o),this.accumulatedDelta=0}},this.calculateNewZoom=(e,t)=>{const s=Math.max(0,e+t*this.options.scale);return void 0===this.options.maxZoom?s:Math.min(s,this.options.maxZoom)},this.options=Object.assign({},s,e)}static create(e){return new i(e)}onInit(){var e;this.wrapper=null===(e=this.wavesurfer)||void 0===e?void 0:e.getWrapper(),this.wrapper&&(this.container=this.wrapper.parentElement,this.wrapper.addEventListener("wheel",this.onWheel))}destroy(){this.wrapper&&this.wrapper.removeEventListener("wheel",this.onWheel),super.destroy()}}return i}));
|
package/dist/renderer.js
CHANGED
|
@@ -94,13 +94,13 @@ class Renderer extends EventEmitter {
|
|
|
94
94
|
// On end drag
|
|
95
95
|
() => (this.isDragging = false));
|
|
96
96
|
}
|
|
97
|
-
getHeight() {
|
|
97
|
+
getHeight(optionsHeight) {
|
|
98
98
|
const defaultHeight = 128;
|
|
99
|
-
if (
|
|
99
|
+
if (optionsHeight == null)
|
|
100
100
|
return defaultHeight;
|
|
101
|
-
if (!isNaN(Number(
|
|
102
|
-
return Number(
|
|
103
|
-
if (
|
|
101
|
+
if (!isNaN(Number(optionsHeight)))
|
|
102
|
+
return Number(optionsHeight);
|
|
103
|
+
if (optionsHeight === 'auto')
|
|
104
104
|
return this.parent.clientHeight || defaultHeight;
|
|
105
105
|
return defaultHeight;
|
|
106
106
|
}
|
|
@@ -137,7 +137,7 @@ class Renderer extends EventEmitter {
|
|
|
137
137
|
z-index: 2;
|
|
138
138
|
}
|
|
139
139
|
:host .canvases {
|
|
140
|
-
min-height: ${this.getHeight()}px;
|
|
140
|
+
min-height: ${this.getHeight(this.options.height)}px;
|
|
141
141
|
}
|
|
142
142
|
:host .canvases > div {
|
|
143
143
|
position: relative;
|
|
@@ -223,7 +223,8 @@ class Renderer extends EventEmitter {
|
|
|
223
223
|
return color[0] || '';
|
|
224
224
|
const canvasElement = document.createElement('canvas');
|
|
225
225
|
const ctx = canvasElement.getContext('2d');
|
|
226
|
-
const
|
|
226
|
+
const gradientHeight = canvasElement.height * (window.devicePixelRatio || 1);
|
|
227
|
+
const gradient = ctx.createLinearGradient(0, 0, 0, gradientHeight);
|
|
227
228
|
const colorStopPercentage = 1 / (color.length - 1);
|
|
228
229
|
color.forEach((color, index) => {
|
|
229
230
|
const offset = index * colorStopPercentage;
|
|
@@ -356,7 +357,7 @@ class Renderer extends EventEmitter {
|
|
|
356
357
|
renderChannel(channelData, options, width) {
|
|
357
358
|
// A container for canvases
|
|
358
359
|
const canvasContainer = document.createElement('div');
|
|
359
|
-
const height = this.getHeight();
|
|
360
|
+
const height = this.getHeight(options.height);
|
|
360
361
|
canvasContainer.style.height = `${height}px`;
|
|
361
362
|
this.canvasWrapper.style.minHeight = `${height}px`;
|
|
362
363
|
this.canvasWrapper.appendChild(canvasContainer);
|
|
@@ -474,39 +475,36 @@ class Renderer extends EventEmitter {
|
|
|
474
475
|
this.reRender();
|
|
475
476
|
}
|
|
476
477
|
scrollIntoView(progress, isPlaying = false) {
|
|
477
|
-
const {
|
|
478
|
-
const progressWidth =
|
|
479
|
-
const
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
// Otherwise, scroll to the center immediately
|
|
491
|
-
this.scrollContainer.scrollLeft = progressWidth - center;
|
|
492
|
-
}
|
|
478
|
+
const { scrollLeft, scrollWidth, clientWidth } = this.scrollContainer;
|
|
479
|
+
const progressWidth = progress * scrollWidth;
|
|
480
|
+
const startEdge = scrollLeft;
|
|
481
|
+
const endEdge = scrollLeft + clientWidth;
|
|
482
|
+
const middle = clientWidth / 2;
|
|
483
|
+
if (this.isDragging) {
|
|
484
|
+
// Scroll when dragging close to the edge of the viewport
|
|
485
|
+
const minGap = 30;
|
|
486
|
+
if (progressWidth + minGap > endEdge) {
|
|
487
|
+
this.scrollContainer.scrollLeft += minGap;
|
|
488
|
+
}
|
|
489
|
+
else if (progressWidth - minGap < startEdge) {
|
|
490
|
+
this.scrollContainer.scrollLeft -= minGap;
|
|
493
491
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
this.scrollContainer.scrollLeft =
|
|
498
|
-
progressWidth < scrollLeft ? progressWidth - gap : progressWidth - clientWidth + gap;
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
if (progressWidth < startEdge || progressWidth > endEdge) {
|
|
495
|
+
this.scrollContainer.scrollLeft = progressWidth - (this.options.autoCenter ? middle : 0);
|
|
499
496
|
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
497
|
+
// Keep the cursor centered when playing
|
|
498
|
+
const center = progressWidth - scrollLeft - middle;
|
|
499
|
+
if (isPlaying && this.options.autoCenter && center > 0) {
|
|
500
|
+
this.scrollContainer.scrollLeft += Math.min(center, 10);
|
|
503
501
|
}
|
|
504
502
|
}
|
|
505
503
|
// Emit the scroll event
|
|
506
504
|
{
|
|
507
|
-
const
|
|
508
|
-
const startX =
|
|
509
|
-
const endX = (
|
|
505
|
+
const newScroll = this.scrollContainer.scrollLeft;
|
|
506
|
+
const startX = newScroll / scrollWidth;
|
|
507
|
+
const endX = (newScroll + clientWidth) / scrollWidth;
|
|
510
508
|
this.emit('scroll', startX, endX);
|
|
511
509
|
}
|
|
512
510
|
}
|