@meersagor/wavesurfer-vue 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -122,7 +122,7 @@ const formatTime = (seconds: number):string => [seconds / 60, seconds % 60].map(
122
122
 
123
123
 
124
124
 
125
- ## useWaveSurferRecorder: composable method Return Types
125
+ ## use useWaveSurferRecorder composable method
126
126
 
127
127
  ```vue
128
128
  <script lang="ts" setup>
@@ -145,6 +145,9 @@ const options = computed(() => ({
145
145
  const { pauseRecording, startRecording, stopRecording, currentTime, isPauseResume } = useWaveSurferRecorder({
146
146
  containerRef,
147
147
  options: options.value,
148
+ recordPluginOptions:{
149
+ continuousWaveform: true
150
+ }
148
151
  })
149
152
 
150
153
  const startAudioRecordHandler = () => {
@@ -173,7 +176,7 @@ const stopHandler = async () => {
173
176
  </div>
174
177
  </template>
175
178
  ```
176
-
179
+ ## useWaveSurferRecorder: method Return Types
177
180
  ### `waveSurfer`
178
181
 
179
182
  - Type: `Ref<WaveSurfer | null>`
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("vue"),b=require("wavesurfer.js"),R=({containerRef:n,options:e})=>{const i=a.ref(null),t=()=>{n.value&&(i.value=b.create({container:n.value,...e}))},r=()=>{i.value&&(i.value.destroy(),i.value=null)};return a.onMounted(()=>{t()}),a.onUnmounted(()=>{r()}),{waveSurfer:i}},M=n=>{const e=a.ref(!1),i=a.ref(!1),t=a.ref(0),r=a.ref(0),o=()=>{e.value=!1,i.value=!1,t.value=0},s=m=>{e.value=!0,i.value=!1,t.value=0,r.value=m},u=()=>{i.value=!0},d=()=>{i.value=!1},c=()=>{n.value&&(t.value=n.value.getCurrentTime())},l=()=>{e.value=!1,i.value=!1};return a.onMounted(()=>{n.value&&(n.value.on("load",o),n.value.on("ready",s),n.value.on("play",u),n.value.on("pause",d),n.value.on("timeupdate",c),n.value.on("destroy",l))}),a.onUnmounted(()=>{n.value&&n.value.unAll()}),{isReady:e,isPlaying:i,currentTime:t,totalDuration:r}},y=({containerRef:n,options:e})=>{const{waveSurfer:i}=R({containerRef:n,options:e}),{isReady:t,totalDuration:r,isPlaying:o,currentTime:s}=M(i);return{waveSurfer:i,isReady:t,totalDuration:r,isPlaying:o,currentTime:s}},D=["audioprocess","click","dblclick","decode","drag","finish","init","interaction","load","loading","pause","play","ready","redraw","redrawcomplete","scroll","seeking","timeupdate","zoom"],T=a.defineComponent({__name:"WaveSurferPlayer",props:{options:{}},setup(n){const e=n,i=a.ref(null),{waveSurfer:t}=y({containerRef:i,options:e.options}),r=a.getCurrentInstance();return a.onMounted(()=>{D.forEach(o=>{t.value?.on(o,(...s)=>{r?.emit(o,...s)})}),r?.emit("waveSurfer",t.value)}),(o,s)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"containerRef",ref:i},null,512))}});function w(n,e,i,t){return new(i||(i=Promise))(function(r,o){function s(c){try{d(t.next(c))}catch(l){o(l)}}function u(c){try{d(t.throw(c))}catch(l){o(l)}}function d(c){var l;c.done?r(c.value):(l=c.value,l instanceof i?l:new i(function(m){m(l)})).then(s,u)}d((t=t.apply(n,[])).next())})}class S{constructor(){this.listeners={}}on(e,i,t){if(this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e].add(i),t?.once){const r=()=>{this.un(e,r),this.un(e,i)};return this.on(e,r),r}return()=>this.un(e,i)}un(e,i){var t;(t=this.listeners[e])===null||t===void 0||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(t=>t(...i))}}class O extends S{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())}}class A extends S{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",()=>{requestAnimationFrame(()=>{this.emit("tick")})}),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}}const E=["audio/webm","audio/wav","audio/mpeg","audio/mp4","audio/mp3"];class W extends O{constructor(e){var i,t,r,o,s,u;super(Object.assign(Object.assign({},e),{audioBitsPerSecond:(i=e.audioBitsPerSecond)!==null&&i!==void 0?i:128e3,scrollingWaveform:(t=e.scrollingWaveform)!==null&&t!==void 0&&t,scrollingWaveformWindow:(r=e.scrollingWaveformWindow)!==null&&r!==void 0?r:5,continuousWaveform:(o=e.continuousWaveform)!==null&&o!==void 0&&o,renderRecordedAudio:(s=e.renderRecordedAudio)===null||s===void 0||s,mediaRecorderTimeslice:(u=e.mediaRecorderTimeslice)!==null&&u!==void 0?u:void 0})),this.stream=null,this.mediaRecorder=null,this.dataWindow=null,this.isWaveformPaused=!1,this.lastStartTime=0,this.lastDuration=0,this.duration=0,this.timer=new A,this.subscriptions.push(this.timer.on("tick",()=>{const d=performance.now()-this.lastStartTime;this.duration=this.isPaused()?this.duration:this.lastDuration+d,this.emit("record-progress",this.duration)}))}static create(e){return new W(e||{})}renderMicStream(e){var i;const t=new AudioContext,r=t.createMediaStreamSource(e),o=t.createAnalyser();r.connect(o),this.options.continuousWaveform&&(o.fftSize=32);const s=o.frequencyBinCount,u=new Float32Array(s);let d=0;this.wavesurfer&&((i=this.originalOptions)!==null&&i!==void 0||(this.originalOptions=Object.assign({},this.wavesurfer.options)),this.wavesurfer.options.interact=!1,this.options.scrollingWaveform&&(this.wavesurfer.options.cursorWidth=0));const c=setInterval(()=>{var l,m,g,h;if(!this.isWaveformPaused){if(o.getFloatTimeDomainData(u),this.options.scrollingWaveform){const f=Math.floor((this.options.scrollingWaveformWindow||0)*t.sampleRate),v=Math.min(f,this.dataWindow?this.dataWindow.length+s:s),p=new Float32Array(f);if(this.dataWindow){const P=Math.max(0,f-this.dataWindow.length);p.set(this.dataWindow.slice(-v+s),P)}p.set(u,f-s),this.dataWindow=p}else if(this.options.continuousWaveform){if(!this.dataWindow){const v=this.options.continuousWaveformDuration?Math.round(100*this.options.continuousWaveformDuration):((m=(l=this.wavesurfer)===null||l===void 0?void 0:l.getWidth())!==null&&m!==void 0?m:0)*window.devicePixelRatio;this.dataWindow=new Float32Array(v)}let f=0;for(let v=0;v<s;v++){const p=Math.abs(u[v]);p>f&&(f=p)}if(d+1>this.dataWindow.length){const v=new Float32Array(2*this.dataWindow.length);v.set(this.dataWindow,0),this.dataWindow=v}this.dataWindow[d]=f,d++}else this.dataWindow=u;if(this.wavesurfer){const f=((h=(g=this.dataWindow)===null||g===void 0?void 0:g.length)!==null&&h!==void 0?h:0)/100;this.wavesurfer.load("",[this.dataWindow],this.options.scrollingWaveform?this.options.scrollingWaveformWindow:f).then(()=>{this.wavesurfer&&this.options.continuousWaveform&&(this.wavesurfer.setTime(this.getDuration()/1e3),this.wavesurfer.options.minPxPerSec||this.wavesurfer.setOptions({minPxPerSec:this.wavesurfer.getWidth()/this.wavesurfer.getDuration()}))}).catch(v=>{console.error("Error rendering real-time recording data:",v)})}}},10);return{onDestroy:()=>{clearInterval(c),r?.disconnect(),t?.close()},onEnd:()=>{this.isWaveformPaused=!0,clearInterval(c),this.stopMic()}}}startMic(e){return w(this,void 0,void 0,function*(){let i;try{i=yield navigator.mediaDevices.getUserMedia({audio:!e?.deviceId||{deviceId:e.deviceId}})}catch(o){throw new Error("Error accessing the microphone: "+o.message)}const{onDestroy:t,onEnd:r}=this.renderMicStream(i);return this.subscriptions.push(this.once("destroy",t)),this.subscriptions.push(this.once("record-end",r)),this.stream=i,i})}stopMic(){this.stream&&(this.stream.getTracks().forEach(e=>e.stop()),this.stream=null,this.mediaRecorder=null)}startRecording(e){return w(this,void 0,void 0,function*(){const i=this.stream||(yield this.startMic(e));this.dataWindow=null;const t=this.mediaRecorder||new MediaRecorder(i,{mimeType:this.options.mimeType||E.find(s=>MediaRecorder.isTypeSupported(s)),audioBitsPerSecond:this.options.audioBitsPerSecond});this.mediaRecorder=t,this.stopRecording();const r=[];t.ondataavailable=s=>{s.data.size>0&&r.push(s.data),this.emit("record-data-available",s.data)};const o=s=>{var u;const d=new Blob(r,{type:t.mimeType});this.emit(s,d),this.options.renderRecordedAudio&&(this.applyOriginalOptionsIfNeeded(),(u=this.wavesurfer)===null||u===void 0||u.load(URL.createObjectURL(d)))};t.onpause=()=>o("record-pause"),t.onstop=()=>o("record-end"),t.start(this.options.mediaRecorderTimeslice),this.lastStartTime=performance.now(),this.lastDuration=0,this.duration=0,this.isWaveformPaused=!1,this.timer.start(),this.emit("record-start")})}getDuration(){return this.duration}isRecording(){var e;return((e=this.mediaRecorder)===null||e===void 0?void 0:e.state)==="recording"}isPaused(){var e;return((e=this.mediaRecorder)===null||e===void 0?void 0:e.state)==="paused"}isActive(){var e;return((e=this.mediaRecorder)===null||e===void 0?void 0:e.state)!=="inactive"}stopRecording(){var e;this.isActive()&&((e=this.mediaRecorder)===null||e===void 0||e.stop(),this.timer.stop())}pauseRecording(){var e,i;this.isRecording()&&(this.isWaveformPaused=!0,(e=this.mediaRecorder)===null||e===void 0||e.requestData(),(i=this.mediaRecorder)===null||i===void 0||i.pause(),this.timer.stop(),this.lastDuration=this.duration)}resumeRecording(){var e;this.isPaused()&&(this.isWaveformPaused=!1,(e=this.mediaRecorder)===null||e===void 0||e.resume(),this.timer.start(),this.lastStartTime=performance.now(),this.emit("record-resume"))}static getAvailableAudioDevices(){return w(this,void 0,void 0,function*(){return navigator.mediaDevices.enumerateDevices().then(e=>e.filter(i=>i.kind==="audioinput"))})}destroy(){this.applyOriginalOptionsIfNeeded(),super.destroy(),this.stopRecording(),this.stopMic()}applyOriginalOptionsIfNeeded(){this.wavesurfer&&this.originalOptions&&(this.wavesurfer.setOptions(this.originalOptions),delete this.originalOptions)}}const I=({containerRef:n,options:e})=>{const{waveSurfer:i}=R({containerRef:n,options:e}),t=a.ref(null),r=a.ref(0),o=a.ref(!1),s=a.ref(!1),u=a.computed(()=>[Math.floor(r.value%36e5/6e4),Math.floor(r.value%6e4/1e3)].map(h=>h<10?"0"+h:h).join(":")),d=a.computed(()=>o.value||!s.value),c=()=>{t.value&&t.value?.on("record-progress",h=>{r.value=h})},l=()=>{if(t.value?.isRecording()||t.value?.isPaused()){t.value?.stopRecording(),o.value=!1,s.value=!0;return}t.value?.startRecording(),o.value=!0,s.value=!1,c()},m=()=>new Promise(h=>{let f;(t.value?.isRecording()||t.value?.isPaused())&&(t.value?.stopRecording(),o.value=!1,s.value=!1),t.value?.on("record-end",v=>{f=v,h(f)})}),g=()=>{if(t.value?.isPaused()){t.value?.resumeRecording(),o.value=!0,s.value=!1;return}o.value=!1,s.value=!0,t.value?.pauseRecording()};return a.onMounted(()=>{const h=i.value?.registerPlugin(W.create({renderRecordedAudio:!1}));h&&(t.value=h)}),{waveSurfer:i,waveSurferRecorder:t,currentTime:u,startRecording:l,stopRecording:m,pauseRecording:g,isRecording:o,isPaused:s,isPauseResume:d}};exports.WaveSurferPlayer=T;exports.useWaveSurfer=y;exports.useWaveSurferRecorder=I;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("vue"),b=require("wavesurfer.js"),R=({containerRef:n,options:e})=>{const t=u.ref(null),i=()=>{n.value&&(t.value=b.create({container:n.value,...e}))},s=()=>{t.value&&(t.value.destroy(),t.value=null)};return u.onMounted(()=>{i()}),u.onUnmounted(()=>{s()}),{waveSurfer:t}},M=n=>{const e=u.ref(!1),t=u.ref(!1),i=u.ref(0),s=u.ref(0),o=()=>{e.value=!1,t.value=!1,i.value=0},r=f=>{e.value=!0,t.value=!1,i.value=0,s.value=f},a=()=>{t.value=!0},l=()=>{t.value=!1},v=()=>{n.value&&(i.value=n.value.getCurrentTime())},c=()=>{e.value=!1,t.value=!1};return u.onMounted(()=>{n.value&&(n.value.on("load",o),n.value.on("ready",r),n.value.on("play",a),n.value.on("pause",l),n.value.on("timeupdate",v),n.value.on("destroy",c))}),u.onUnmounted(()=>{n.value&&n.value.unAll()}),{isReady:e,isPlaying:t,currentTime:i,totalDuration:s}},y=({containerRef:n,options:e})=>{const{waveSurfer:t}=R({containerRef:n,options:e}),{isReady:i,totalDuration:s,isPlaying:o,currentTime:r}=M(t);return{waveSurfer:t,isReady:i,totalDuration:s,isPlaying:o,currentTime:r}},D=["audioprocess","click","dblclick","decode","drag","finish","init","interaction","load","loading","pause","play","ready","redraw","redrawcomplete","scroll","seeking","timeupdate","zoom"],T=u.defineComponent({__name:"WaveSurferPlayer",props:{options:{}},setup(n){const e=n,t=u.ref(null),{waveSurfer:i}=y({containerRef:t,options:e.options}),s=u.getCurrentInstance();return u.onMounted(()=>{D.forEach(o=>{i.value?.on(o,(...r)=>{s?.emit(o,...r)})}),s?.emit("waveSurfer",i.value)}),(o,r)=>(u.openBlock(),u.createElementBlock("div",{ref_key:"containerRef",ref:t},null,512))}});function w(n,e,t,i){return new(t||(t=Promise))(function(s,o){function r(v){try{l(i.next(v))}catch(c){o(c)}}function a(v){try{l(i.throw(v))}catch(c){o(c)}}function l(v){var c;v.done?s(v.value):(c=v.value,c instanceof t?c:new t(function(f){f(c)})).then(r,a)}l((i=i.apply(n,[])).next())})}class S{constructor(){this.listeners={}}on(e,t,i){if(this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e].add(t),i?.once){const s=()=>{this.un(e,s),this.un(e,t)};return this.on(e,s),s}return()=>this.un(e,t)}un(e,t){var i;(i=this.listeners[e])===null||i===void 0||i.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(i=>i(...t))}}class O extends S{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())}}class A extends S{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",()=>{requestAnimationFrame(()=>{this.emit("tick")})}),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}}const E=["audio/webm","audio/wav","audio/mpeg","audio/mp4","audio/mp3"];class W extends O{constructor(e){var t,i,s,o,r,a;super(Object.assign(Object.assign({},e),{audioBitsPerSecond:(t=e.audioBitsPerSecond)!==null&&t!==void 0?t:128e3,scrollingWaveform:(i=e.scrollingWaveform)!==null&&i!==void 0&&i,scrollingWaveformWindow:(s=e.scrollingWaveformWindow)!==null&&s!==void 0?s:5,continuousWaveform:(o=e.continuousWaveform)!==null&&o!==void 0&&o,renderRecordedAudio:(r=e.renderRecordedAudio)===null||r===void 0||r,mediaRecorderTimeslice:(a=e.mediaRecorderTimeslice)!==null&&a!==void 0?a:void 0})),this.stream=null,this.mediaRecorder=null,this.dataWindow=null,this.isWaveformPaused=!1,this.lastStartTime=0,this.lastDuration=0,this.duration=0,this.timer=new A,this.subscriptions.push(this.timer.on("tick",()=>{const l=performance.now()-this.lastStartTime;this.duration=this.isPaused()?this.duration:this.lastDuration+l,this.emit("record-progress",this.duration)}))}static create(e){return new W(e||{})}renderMicStream(e){var t;const i=new AudioContext,s=i.createMediaStreamSource(e),o=i.createAnalyser();s.connect(o),this.options.continuousWaveform&&(o.fftSize=32);const r=o.frequencyBinCount,a=new Float32Array(r);let l=0;this.wavesurfer&&((t=this.originalOptions)!==null&&t!==void 0||(this.originalOptions=Object.assign({},this.wavesurfer.options)),this.wavesurfer.options.interact=!1,this.options.scrollingWaveform&&(this.wavesurfer.options.cursorWidth=0));const v=setInterval(()=>{var c,f,p,g;if(!this.isWaveformPaused){if(o.getFloatTimeDomainData(a),this.options.scrollingWaveform){const d=Math.floor((this.options.scrollingWaveformWindow||0)*i.sampleRate),h=Math.min(d,this.dataWindow?this.dataWindow.length+r:r),m=new Float32Array(d);if(this.dataWindow){const P=Math.max(0,d-this.dataWindow.length);m.set(this.dataWindow.slice(-h+r),P)}m.set(a,d-r),this.dataWindow=m}else if(this.options.continuousWaveform){if(!this.dataWindow){const h=this.options.continuousWaveformDuration?Math.round(100*this.options.continuousWaveformDuration):((f=(c=this.wavesurfer)===null||c===void 0?void 0:c.getWidth())!==null&&f!==void 0?f:0)*window.devicePixelRatio;this.dataWindow=new Float32Array(h)}let d=0;for(let h=0;h<r;h++){const m=Math.abs(a[h]);m>d&&(d=m)}if(l+1>this.dataWindow.length){const h=new Float32Array(2*this.dataWindow.length);h.set(this.dataWindow,0),this.dataWindow=h}this.dataWindow[l]=d,l++}else this.dataWindow=a;if(this.wavesurfer){const d=((g=(p=this.dataWindow)===null||p===void 0?void 0:p.length)!==null&&g!==void 0?g:0)/100;this.wavesurfer.load("",[this.dataWindow],this.options.scrollingWaveform?this.options.scrollingWaveformWindow:d).then(()=>{this.wavesurfer&&this.options.continuousWaveform&&(this.wavesurfer.setTime(this.getDuration()/1e3),this.wavesurfer.options.minPxPerSec||this.wavesurfer.setOptions({minPxPerSec:this.wavesurfer.getWidth()/this.wavesurfer.getDuration()}))}).catch(h=>{console.error("Error rendering real-time recording data:",h)})}}},10);return{onDestroy:()=>{clearInterval(v),s?.disconnect(),i?.close()},onEnd:()=>{this.isWaveformPaused=!0,clearInterval(v),this.stopMic()}}}startMic(e){return w(this,void 0,void 0,function*(){let t;try{t=yield navigator.mediaDevices.getUserMedia({audio:!e?.deviceId||{deviceId:e.deviceId}})}catch(o){throw new Error("Error accessing the microphone: "+o.message)}const{onDestroy:i,onEnd:s}=this.renderMicStream(t);return this.subscriptions.push(this.once("destroy",i)),this.subscriptions.push(this.once("record-end",s)),this.stream=t,t})}stopMic(){this.stream&&(this.stream.getTracks().forEach(e=>e.stop()),this.stream=null,this.mediaRecorder=null)}startRecording(e){return w(this,void 0,void 0,function*(){const t=this.stream||(yield this.startMic(e));this.dataWindow=null;const i=this.mediaRecorder||new MediaRecorder(t,{mimeType:this.options.mimeType||E.find(r=>MediaRecorder.isTypeSupported(r)),audioBitsPerSecond:this.options.audioBitsPerSecond});this.mediaRecorder=i,this.stopRecording();const s=[];i.ondataavailable=r=>{r.data.size>0&&s.push(r.data),this.emit("record-data-available",r.data)};const o=r=>{var a;const l=new Blob(s,{type:i.mimeType});this.emit(r,l),this.options.renderRecordedAudio&&(this.applyOriginalOptionsIfNeeded(),(a=this.wavesurfer)===null||a===void 0||a.load(URL.createObjectURL(l)))};i.onpause=()=>o("record-pause"),i.onstop=()=>o("record-end"),i.start(this.options.mediaRecorderTimeslice),this.lastStartTime=performance.now(),this.lastDuration=0,this.duration=0,this.isWaveformPaused=!1,this.timer.start(),this.emit("record-start")})}getDuration(){return this.duration}isRecording(){var e;return((e=this.mediaRecorder)===null||e===void 0?void 0:e.state)==="recording"}isPaused(){var e;return((e=this.mediaRecorder)===null||e===void 0?void 0:e.state)==="paused"}isActive(){var e;return((e=this.mediaRecorder)===null||e===void 0?void 0:e.state)!=="inactive"}stopRecording(){var e;this.isActive()&&((e=this.mediaRecorder)===null||e===void 0||e.stop(),this.timer.stop())}pauseRecording(){var e,t;this.isRecording()&&(this.isWaveformPaused=!0,(e=this.mediaRecorder)===null||e===void 0||e.requestData(),(t=this.mediaRecorder)===null||t===void 0||t.pause(),this.timer.stop(),this.lastDuration=this.duration)}resumeRecording(){var e;this.isPaused()&&(this.isWaveformPaused=!1,(e=this.mediaRecorder)===null||e===void 0||e.resume(),this.timer.start(),this.lastStartTime=performance.now(),this.emit("record-resume"))}static getAvailableAudioDevices(){return w(this,void 0,void 0,function*(){return navigator.mediaDevices.enumerateDevices().then(e=>e.filter(t=>t.kind==="audioinput"))})}destroy(){this.applyOriginalOptionsIfNeeded(),super.destroy(),this.stopRecording(),this.stopMic()}applyOriginalOptionsIfNeeded(){this.wavesurfer&&this.originalOptions&&(this.wavesurfer.setOptions(this.originalOptions),delete this.originalOptions)}}const I=({containerRef:n,options:e,recordPluginOptions:t})=>{const{waveSurfer:i}=R({containerRef:n,options:e}),s=u.ref(null),o=u.ref(0),r=u.ref(!1),a=u.ref(!1),l=u.computed(()=>[Math.floor(o.value%36e5/6e4),Math.floor(o.value%6e4/1e3)].map(d=>d<10?"0"+d:d).join(":")),v=u.computed(()=>r.value||!a.value),c=()=>{s.value&&s.value?.on("record-progress",d=>{o.value=d})},f=()=>{if(s.value?.isRecording()||s.value?.isPaused()){s.value?.stopRecording(),r.value=!1,a.value=!0;return}s.value?.startRecording(),r.value=!0,a.value=!1,c()},p=()=>new Promise(d=>{let h;(s.value?.isRecording()||s.value?.isPaused())&&(s.value?.stopRecording(),r.value=!1,a.value=!1),s.value?.on("record-end",m=>{h=m,d(h)})}),g=()=>{if(s.value?.isPaused()){s.value?.resumeRecording(),r.value=!0,a.value=!1;return}r.value=!1,a.value=!0,s.value?.pauseRecording()};return u.onMounted(()=>{const d=i.value?.registerPlugin(W.create({renderRecordedAudio:!1,...t}));d&&(s.value=d)}),{waveSurfer:i,waveSurferRecorder:s,currentTime:l,startRecording:f,stopRecording:p,pauseRecording:g,isRecording:r,isPaused:a,isPauseResume:v}};exports.WaveSurferPlayer=T;exports.useWaveSurfer=y;exports.useWaveSurferRecorder=I;
@@ -1,51 +1,51 @@
1
- import { ref as m, onMounted as w, onUnmounted as S, defineComponent as T, getCurrentInstance as M, openBlock as A, createElementBlock as O, computed as y } from "vue";
1
+ import { ref as v, onMounted as w, onUnmounted as S, defineComponent as T, getCurrentInstance as M, openBlock as A, createElementBlock as O, computed as y } from "vue";
2
2
  import E from "wavesurfer.js";
3
3
  const P = ({ containerRef: n, options: e }) => {
4
- const i = m(null), t = () => {
5
- n.value && (i.value = E.create({
4
+ const t = v(null), i = () => {
5
+ n.value && (t.value = E.create({
6
6
  container: n.value,
7
7
  ...e
8
8
  }));
9
- }, o = () => {
10
- i.value && (i.value.destroy(), i.value = null);
9
+ }, s = () => {
10
+ t.value && (t.value.destroy(), t.value = null);
11
11
  };
12
12
  return w(() => {
13
- t();
13
+ i();
14
14
  }), S(() => {
15
- o();
16
- }), { waveSurfer: i };
15
+ s();
16
+ }), { waveSurfer: t };
17
17
  }, I = (n) => {
18
- const e = m(!1), i = m(!1), t = m(0), o = m(0), r = () => {
19
- e.value = !1, i.value = !1, t.value = 0;
20
- }, s = (f) => {
21
- e.value = !0, i.value = !1, t.value = 0, o.value = f;
18
+ const e = v(!1), t = v(!1), i = v(0), s = v(0), r = () => {
19
+ e.value = !1, t.value = !1, i.value = 0;
20
+ }, o = (m) => {
21
+ e.value = !0, t.value = !1, i.value = 0, s.value = m;
22
22
  }, a = () => {
23
- i.value = !0;
24
- }, u = () => {
25
- i.value = !1;
26
- }, l = () => {
27
- n.value && (t.value = n.value.getCurrentTime());
23
+ t.value = !0;
28
24
  }, d = () => {
29
- e.value = !1, i.value = !1;
25
+ t.value = !1;
26
+ }, h = () => {
27
+ n.value && (i.value = n.value.getCurrentTime());
28
+ }, l = () => {
29
+ e.value = !1, t.value = !1;
30
30
  };
31
31
  return w(() => {
32
- n.value && (n.value.on("load", r), n.value.on("ready", s), n.value.on("play", a), n.value.on("pause", u), n.value.on("timeupdate", l), n.value.on("destroy", d));
32
+ n.value && (n.value.on("load", r), n.value.on("ready", o), n.value.on("play", a), n.value.on("pause", d), n.value.on("timeupdate", h), n.value.on("destroy", l));
33
33
  }), S(() => {
34
34
  n.value && n.value.unAll();
35
35
  }), {
36
36
  isReady: e,
37
- isPlaying: i,
38
- currentTime: t,
39
- totalDuration: o
37
+ isPlaying: t,
38
+ currentTime: i,
39
+ totalDuration: s
40
40
  };
41
41
  }, k = ({ containerRef: n, options: e }) => {
42
- const { waveSurfer: i } = P({ containerRef: n, options: e }), { isReady: t, totalDuration: o, isPlaying: r, currentTime: s } = I(i);
42
+ const { waveSurfer: t } = P({ containerRef: n, options: e }), { isReady: i, totalDuration: s, isPlaying: r, currentTime: o } = I(t);
43
43
  return {
44
- waveSurfer: i,
45
- isReady: t,
46
- totalDuration: o,
44
+ waveSurfer: t,
45
+ isReady: i,
46
+ totalDuration: s,
47
47
  isPlaying: r,
48
- currentTime: s
48
+ currentTime: o
49
49
  };
50
50
  }, x = ["audioprocess", "click", "dblclick", "decode", "drag", "finish", "init", "interaction", "load", "loading", "pause", "play", "ready", "redraw", "redrawcomplete", "scroll", "seeking", "timeupdate", "zoom"], U = /* @__PURE__ */ T({
51
51
  __name: "WaveSurferPlayer",
@@ -53,69 +53,69 @@ const P = ({ containerRef: n, options: e }) => {
53
53
  options: {}
54
54
  },
55
55
  setup(n) {
56
- const e = n, i = m(null), { waveSurfer: t } = k({ containerRef: i, options: e.options }), o = M();
56
+ const e = n, t = v(null), { waveSurfer: i } = k({ containerRef: t, options: e.options }), s = M();
57
57
  return w(() => {
58
58
  x.forEach((r) => {
59
- t.value?.on(r, (...s) => {
60
- o?.emit(r, ...s);
59
+ i.value?.on(r, (...o) => {
60
+ s?.emit(r, ...o);
61
61
  });
62
- }), o?.emit("waveSurfer", t.value);
63
- }), (r, s) => (A(), O("div", {
62
+ }), s?.emit("waveSurfer", i.value);
63
+ }), (r, o) => (A(), O("div", {
64
64
  ref_key: "containerRef",
65
- ref: i
65
+ ref: t
66
66
  }, null, 512));
67
67
  }
68
68
  });
69
- function W(n, e, i, t) {
70
- return new (i || (i = Promise))(function(o, r) {
71
- function s(l) {
69
+ function W(n, e, t, i) {
70
+ return new (t || (t = Promise))(function(s, r) {
71
+ function o(h) {
72
72
  try {
73
- u(t.next(l));
74
- } catch (d) {
75
- r(d);
73
+ d(i.next(h));
74
+ } catch (l) {
75
+ r(l);
76
76
  }
77
77
  }
78
- function a(l) {
78
+ function a(h) {
79
79
  try {
80
- u(t.throw(l));
81
- } catch (d) {
82
- r(d);
80
+ d(i.throw(h));
81
+ } catch (l) {
82
+ r(l);
83
83
  }
84
84
  }
85
- function u(l) {
86
- var d;
87
- l.done ? o(l.value) : (d = l.value, d instanceof i ? d : new i(function(f) {
88
- f(d);
89
- })).then(s, a);
85
+ function d(h) {
86
+ var l;
87
+ h.done ? s(h.value) : (l = h.value, l instanceof t ? l : new t(function(m) {
88
+ m(l);
89
+ })).then(o, a);
90
90
  }
91
- u((t = t.apply(n, [])).next());
91
+ d((i = i.apply(n, [])).next());
92
92
  });
93
93
  }
94
94
  class b {
95
95
  constructor() {
96
96
  this.listeners = {};
97
97
  }
98
- on(e, i, t) {
99
- if (this.listeners[e] || (this.listeners[e] = /* @__PURE__ */ new Set()), this.listeners[e].add(i), t?.once) {
100
- const o = () => {
101
- this.un(e, o), this.un(e, i);
98
+ on(e, t, i) {
99
+ if (this.listeners[e] || (this.listeners[e] = /* @__PURE__ */ new Set()), this.listeners[e].add(t), i?.once) {
100
+ const s = () => {
101
+ this.un(e, s), this.un(e, t);
102
102
  };
103
- return this.on(e, o), o;
103
+ return this.on(e, s), s;
104
104
  }
105
- return () => this.un(e, i);
105
+ return () => this.un(e, t);
106
106
  }
107
- un(e, i) {
108
- var t;
109
- (t = this.listeners[e]) === null || t === void 0 || t.delete(i);
107
+ un(e, t) {
108
+ var i;
109
+ (i = this.listeners[e]) === null || i === void 0 || i.delete(t);
110
110
  }
111
- once(e, i) {
112
- return this.on(e, i, { once: !0 });
111
+ once(e, t) {
112
+ return this.on(e, t, { once: !0 });
113
113
  }
114
114
  unAll() {
115
115
  this.listeners = {};
116
116
  }
117
- emit(e, ...i) {
118
- this.listeners[e] && this.listeners[e].forEach((t) => t(...i));
117
+ emit(e, ...t) {
118
+ this.listeners[e] && this.listeners[e].forEach((i) => i(...t));
119
119
  }
120
120
  }
121
121
  class B extends b {
@@ -153,74 +153,74 @@ class _ extends b {
153
153
  const F = ["audio/webm", "audio/wav", "audio/mpeg", "audio/mp4", "audio/mp3"];
154
154
  class R extends B {
155
155
  constructor(e) {
156
- var i, t, o, r, s, a;
157
- super(Object.assign(Object.assign({}, e), { audioBitsPerSecond: (i = e.audioBitsPerSecond) !== null && i !== void 0 ? i : 128e3, scrollingWaveform: (t = e.scrollingWaveform) !== null && t !== void 0 && t, scrollingWaveformWindow: (o = e.scrollingWaveformWindow) !== null && o !== void 0 ? o : 5, continuousWaveform: (r = e.continuousWaveform) !== null && r !== void 0 && r, renderRecordedAudio: (s = e.renderRecordedAudio) === null || s === void 0 || s, mediaRecorderTimeslice: (a = e.mediaRecorderTimeslice) !== null && a !== void 0 ? a : void 0 })), this.stream = null, this.mediaRecorder = null, this.dataWindow = null, this.isWaveformPaused = !1, this.lastStartTime = 0, this.lastDuration = 0, this.duration = 0, this.timer = new _(), this.subscriptions.push(this.timer.on("tick", () => {
158
- const u = performance.now() - this.lastStartTime;
159
- this.duration = this.isPaused() ? this.duration : this.lastDuration + u, this.emit("record-progress", this.duration);
156
+ var t, i, s, r, o, a;
157
+ super(Object.assign(Object.assign({}, e), { audioBitsPerSecond: (t = e.audioBitsPerSecond) !== null && t !== void 0 ? t : 128e3, scrollingWaveform: (i = e.scrollingWaveform) !== null && i !== void 0 && i, scrollingWaveformWindow: (s = e.scrollingWaveformWindow) !== null && s !== void 0 ? s : 5, continuousWaveform: (r = e.continuousWaveform) !== null && r !== void 0 && r, renderRecordedAudio: (o = e.renderRecordedAudio) === null || o === void 0 || o, mediaRecorderTimeslice: (a = e.mediaRecorderTimeslice) !== null && a !== void 0 ? a : void 0 })), this.stream = null, this.mediaRecorder = null, this.dataWindow = null, this.isWaveformPaused = !1, this.lastStartTime = 0, this.lastDuration = 0, this.duration = 0, this.timer = new _(), this.subscriptions.push(this.timer.on("tick", () => {
158
+ const d = performance.now() - this.lastStartTime;
159
+ this.duration = this.isPaused() ? this.duration : this.lastDuration + d, this.emit("record-progress", this.duration);
160
160
  }));
161
161
  }
162
162
  static create(e) {
163
163
  return new R(e || {});
164
164
  }
165
165
  renderMicStream(e) {
166
- var i;
167
- const t = new AudioContext(), o = t.createMediaStreamSource(e), r = t.createAnalyser();
168
- o.connect(r), this.options.continuousWaveform && (r.fftSize = 32);
169
- const s = r.frequencyBinCount, a = new Float32Array(s);
170
- let u = 0;
171
- this.wavesurfer && ((i = this.originalOptions) !== null && i !== void 0 || (this.originalOptions = Object.assign({}, this.wavesurfer.options)), this.wavesurfer.options.interact = !1, this.options.scrollingWaveform && (this.wavesurfer.options.cursorWidth = 0));
172
- const l = setInterval(() => {
173
- var d, f, g, c;
166
+ var t;
167
+ const i = new AudioContext(), s = i.createMediaStreamSource(e), r = i.createAnalyser();
168
+ s.connect(r), this.options.continuousWaveform && (r.fftSize = 32);
169
+ const o = r.frequencyBinCount, a = new Float32Array(o);
170
+ let d = 0;
171
+ this.wavesurfer && ((t = this.originalOptions) !== null && t !== void 0 || (this.originalOptions = Object.assign({}, this.wavesurfer.options)), this.wavesurfer.options.interact = !1, this.options.scrollingWaveform && (this.wavesurfer.options.cursorWidth = 0));
172
+ const h = setInterval(() => {
173
+ var l, m, p, g;
174
174
  if (!this.isWaveformPaused) {
175
175
  if (r.getFloatTimeDomainData(a), this.options.scrollingWaveform) {
176
- const v = Math.floor((this.options.scrollingWaveformWindow || 0) * t.sampleRate), h = Math.min(v, this.dataWindow ? this.dataWindow.length + s : s), p = new Float32Array(v);
176
+ const u = Math.floor((this.options.scrollingWaveformWindow || 0) * i.sampleRate), c = Math.min(u, this.dataWindow ? this.dataWindow.length + o : o), f = new Float32Array(u);
177
177
  if (this.dataWindow) {
178
- const D = Math.max(0, v - this.dataWindow.length);
179
- p.set(this.dataWindow.slice(-h + s), D);
178
+ const D = Math.max(0, u - this.dataWindow.length);
179
+ f.set(this.dataWindow.slice(-c + o), D);
180
180
  }
181
- p.set(a, v - s), this.dataWindow = p;
181
+ f.set(a, u - o), this.dataWindow = f;
182
182
  } else if (this.options.continuousWaveform) {
183
183
  if (!this.dataWindow) {
184
- const h = this.options.continuousWaveformDuration ? Math.round(100 * this.options.continuousWaveformDuration) : ((f = (d = this.wavesurfer) === null || d === void 0 ? void 0 : d.getWidth()) !== null && f !== void 0 ? f : 0) * window.devicePixelRatio;
185
- this.dataWindow = new Float32Array(h);
184
+ const c = this.options.continuousWaveformDuration ? Math.round(100 * this.options.continuousWaveformDuration) : ((m = (l = this.wavesurfer) === null || l === void 0 ? void 0 : l.getWidth()) !== null && m !== void 0 ? m : 0) * window.devicePixelRatio;
185
+ this.dataWindow = new Float32Array(c);
186
186
  }
187
- let v = 0;
188
- for (let h = 0; h < s; h++) {
189
- const p = Math.abs(a[h]);
190
- p > v && (v = p);
187
+ let u = 0;
188
+ for (let c = 0; c < o; c++) {
189
+ const f = Math.abs(a[c]);
190
+ f > u && (u = f);
191
191
  }
192
- if (u + 1 > this.dataWindow.length) {
193
- const h = new Float32Array(2 * this.dataWindow.length);
194
- h.set(this.dataWindow, 0), this.dataWindow = h;
192
+ if (d + 1 > this.dataWindow.length) {
193
+ const c = new Float32Array(2 * this.dataWindow.length);
194
+ c.set(this.dataWindow, 0), this.dataWindow = c;
195
195
  }
196
- this.dataWindow[u] = v, u++;
196
+ this.dataWindow[d] = u, d++;
197
197
  } else this.dataWindow = a;
198
198
  if (this.wavesurfer) {
199
- const v = ((c = (g = this.dataWindow) === null || g === void 0 ? void 0 : g.length) !== null && c !== void 0 ? c : 0) / 100;
200
- this.wavesurfer.load("", [this.dataWindow], this.options.scrollingWaveform ? this.options.scrollingWaveformWindow : v).then(() => {
199
+ const u = ((g = (p = this.dataWindow) === null || p === void 0 ? void 0 : p.length) !== null && g !== void 0 ? g : 0) / 100;
200
+ this.wavesurfer.load("", [this.dataWindow], this.options.scrollingWaveform ? this.options.scrollingWaveformWindow : u).then(() => {
201
201
  this.wavesurfer && this.options.continuousWaveform && (this.wavesurfer.setTime(this.getDuration() / 1e3), this.wavesurfer.options.minPxPerSec || this.wavesurfer.setOptions({ minPxPerSec: this.wavesurfer.getWidth() / this.wavesurfer.getDuration() }));
202
- }).catch((h) => {
203
- console.error("Error rendering real-time recording data:", h);
202
+ }).catch((c) => {
203
+ console.error("Error rendering real-time recording data:", c);
204
204
  });
205
205
  }
206
206
  }
207
207
  }, 10);
208
208
  return { onDestroy: () => {
209
- clearInterval(l), o?.disconnect(), t?.close();
209
+ clearInterval(h), s?.disconnect(), i?.close();
210
210
  }, onEnd: () => {
211
- this.isWaveformPaused = !0, clearInterval(l), this.stopMic();
211
+ this.isWaveformPaused = !0, clearInterval(h), this.stopMic();
212
212
  } };
213
213
  }
214
214
  startMic(e) {
215
215
  return W(this, void 0, void 0, function* () {
216
- let i;
216
+ let t;
217
217
  try {
218
- i = yield navigator.mediaDevices.getUserMedia({ audio: !e?.deviceId || { deviceId: e.deviceId } });
218
+ t = yield navigator.mediaDevices.getUserMedia({ audio: !e?.deviceId || { deviceId: e.deviceId } });
219
219
  } catch (r) {
220
220
  throw new Error("Error accessing the microphone: " + r.message);
221
221
  }
222
- const { onDestroy: t, onEnd: o } = this.renderMicStream(i);
223
- return this.subscriptions.push(this.once("destroy", t)), this.subscriptions.push(this.once("record-end", o)), this.stream = i, i;
222
+ const { onDestroy: i, onEnd: s } = this.renderMicStream(t);
223
+ return this.subscriptions.push(this.once("destroy", i)), this.subscriptions.push(this.once("record-end", s)), this.stream = t, t;
224
224
  });
225
225
  }
226
226
  stopMic() {
@@ -228,20 +228,20 @@ class R extends B {
228
228
  }
229
229
  startRecording(e) {
230
230
  return W(this, void 0, void 0, function* () {
231
- const i = this.stream || (yield this.startMic(e));
231
+ const t = this.stream || (yield this.startMic(e));
232
232
  this.dataWindow = null;
233
- const t = this.mediaRecorder || new MediaRecorder(i, { mimeType: this.options.mimeType || F.find((s) => MediaRecorder.isTypeSupported(s)), audioBitsPerSecond: this.options.audioBitsPerSecond });
234
- this.mediaRecorder = t, this.stopRecording();
235
- const o = [];
236
- t.ondataavailable = (s) => {
237
- s.data.size > 0 && o.push(s.data), this.emit("record-data-available", s.data);
233
+ const i = this.mediaRecorder || new MediaRecorder(t, { mimeType: this.options.mimeType || F.find((o) => MediaRecorder.isTypeSupported(o)), audioBitsPerSecond: this.options.audioBitsPerSecond });
234
+ this.mediaRecorder = i, this.stopRecording();
235
+ const s = [];
236
+ i.ondataavailable = (o) => {
237
+ o.data.size > 0 && s.push(o.data), this.emit("record-data-available", o.data);
238
238
  };
239
- const r = (s) => {
239
+ const r = (o) => {
240
240
  var a;
241
- const u = new Blob(o, { type: t.mimeType });
242
- this.emit(s, u), this.options.renderRecordedAudio && (this.applyOriginalOptionsIfNeeded(), (a = this.wavesurfer) === null || a === void 0 || a.load(URL.createObjectURL(u)));
241
+ const d = new Blob(s, { type: i.mimeType });
242
+ this.emit(o, d), this.options.renderRecordedAudio && (this.applyOriginalOptionsIfNeeded(), (a = this.wavesurfer) === null || a === void 0 || a.load(URL.createObjectURL(d)));
243
243
  };
244
- t.onpause = () => r("record-pause"), t.onstop = () => r("record-end"), t.start(this.options.mediaRecorderTimeslice), this.lastStartTime = performance.now(), this.lastDuration = 0, this.duration = 0, this.isWaveformPaused = !1, this.timer.start(), this.emit("record-start");
244
+ i.onpause = () => r("record-pause"), i.onstop = () => r("record-end"), i.start(this.options.mediaRecorderTimeslice), this.lastStartTime = performance.now(), this.lastDuration = 0, this.duration = 0, this.isWaveformPaused = !1, this.timer.start(), this.emit("record-start");
245
245
  });
246
246
  }
247
247
  getDuration() {
@@ -264,8 +264,8 @@ class R extends B {
264
264
  this.isActive() && ((e = this.mediaRecorder) === null || e === void 0 || e.stop(), this.timer.stop());
265
265
  }
266
266
  pauseRecording() {
267
- var e, i;
268
- this.isRecording() && (this.isWaveformPaused = !0, (e = this.mediaRecorder) === null || e === void 0 || e.requestData(), (i = this.mediaRecorder) === null || i === void 0 || i.pause(), this.timer.stop(), this.lastDuration = this.duration);
267
+ var e, t;
268
+ this.isRecording() && (this.isWaveformPaused = !0, (e = this.mediaRecorder) === null || e === void 0 || e.requestData(), (t = this.mediaRecorder) === null || t === void 0 || t.pause(), this.timer.stop(), this.lastDuration = this.duration);
269
269
  }
270
270
  resumeRecording() {
271
271
  var e;
@@ -273,7 +273,7 @@ class R extends B {
273
273
  }
274
274
  static getAvailableAudioDevices() {
275
275
  return W(this, void 0, void 0, function* () {
276
- return navigator.mediaDevices.enumerateDevices().then((e) => e.filter((i) => i.kind === "audioinput"));
276
+ return navigator.mediaDevices.enumerateDevices().then((e) => e.filter((t) => t.kind === "audioinput"));
277
277
  });
278
278
  }
279
279
  destroy() {
@@ -283,47 +283,50 @@ class R extends B {
283
283
  this.wavesurfer && this.originalOptions && (this.wavesurfer.setOptions(this.originalOptions), delete this.originalOptions);
284
284
  }
285
285
  }
286
- const q = ({ containerRef: n, options: e }) => {
287
- const { waveSurfer: i } = P({ containerRef: n, options: e }), t = m(null), o = m(0), r = m(!1), s = m(!1), a = y(() => [
288
- Math.floor(o.value % 36e5 / 6e4),
286
+ const q = ({ containerRef: n, options: e, recordPluginOptions: t }) => {
287
+ const { waveSurfer: i } = P({ containerRef: n, options: e }), s = v(null), r = v(0), o = v(!1), a = v(!1), d = y(() => [
288
+ Math.floor(r.value % 36e5 / 6e4),
289
289
  // minutes
290
- Math.floor(o.value % 6e4 / 1e3)
290
+ Math.floor(r.value % 6e4 / 1e3)
291
291
  // seconds
292
- ].map((c) => c < 10 ? "0" + c : c).join(":")), u = y(() => r.value || !s.value), l = () => {
293
- t.value && t.value?.on("record-progress", (c) => {
294
- o.value = c;
292
+ ].map((u) => u < 10 ? "0" + u : u).join(":")), h = y(() => o.value || !a.value), l = () => {
293
+ s.value && s.value?.on("record-progress", (u) => {
294
+ r.value = u;
295
295
  });
296
- }, d = () => {
297
- if (t.value?.isRecording() || t.value?.isPaused()) {
298
- t.value?.stopRecording(), r.value = !1, s.value = !0;
296
+ }, m = () => {
297
+ if (s.value?.isRecording() || s.value?.isPaused()) {
298
+ s.value?.stopRecording(), o.value = !1, a.value = !0;
299
299
  return;
300
300
  }
301
- t.value?.startRecording(), r.value = !0, s.value = !1, l();
302
- }, f = () => new Promise((c) => {
303
- let v;
304
- (t.value?.isRecording() || t.value?.isPaused()) && (t.value?.stopRecording(), r.value = !1, s.value = !1), t.value?.on("record-end", (h) => {
305
- v = h, c(v);
301
+ s.value?.startRecording(), o.value = !0, a.value = !1, l();
302
+ }, p = () => new Promise((u) => {
303
+ let c;
304
+ (s.value?.isRecording() || s.value?.isPaused()) && (s.value?.stopRecording(), o.value = !1, a.value = !1), s.value?.on("record-end", (f) => {
305
+ c = f, u(c);
306
306
  });
307
307
  }), g = () => {
308
- if (t.value?.isPaused()) {
309
- t.value?.resumeRecording(), r.value = !0, s.value = !1;
308
+ if (s.value?.isPaused()) {
309
+ s.value?.resumeRecording(), o.value = !0, a.value = !1;
310
310
  return;
311
311
  }
312
- r.value = !1, s.value = !0, t.value?.pauseRecording();
312
+ o.value = !1, a.value = !0, s.value?.pauseRecording();
313
313
  };
314
314
  return w(() => {
315
- const c = i.value?.registerPlugin(R.create({ renderRecordedAudio: !1 }));
316
- c && (t.value = c);
315
+ const u = i.value?.registerPlugin(R.create({
316
+ renderRecordedAudio: !1,
317
+ ...t
318
+ }));
319
+ u && (s.value = u);
317
320
  }), {
318
321
  waveSurfer: i,
319
- waveSurferRecorder: t,
320
- currentTime: a,
321
- startRecording: d,
322
- stopRecording: f,
322
+ waveSurferRecorder: s,
323
+ currentTime: d,
324
+ startRecording: m,
325
+ stopRecording: p,
323
326
  pauseRecording: g,
324
- isRecording: r,
325
- isPaused: s,
326
- isPauseResume: u
327
+ isRecording: o,
328
+ isPaused: a,
329
+ isPauseResume: h
327
330
  };
328
331
  };
329
332
  export {
@@ -1,6 +1,6 @@
1
1
  import { default as RecordPlugin } from 'wavesurfer.js/dist/plugins/record.js';
2
- import { WaveSurferIns } from '../types';
3
- export declare const useWaveSurferRecorder: ({ containerRef, options }: WaveSurferIns) => {
2
+ import { UseWaveSurferRecorder } from '../types';
3
+ export declare const useWaveSurferRecorder: ({ containerRef, options, recordPluginOptions }: UseWaveSurferRecorder) => {
4
4
  waveSurfer: import('vue').Ref<{
5
5
  options: {
6
6
  container: HTMLElement | string;
@@ -2,9 +2,28 @@ import { WaveSurferOptions } from 'wavesurfer.js';
2
2
  import { Ref } from 'vue';
3
3
  import { useWaveSurferInstance } from '../composables/useWaveSurferInstance';
4
4
  import { useWaveSurferState } from '../composables/useWaveSurferState';
5
+ import { RecordPluginOptions } from 'wavesurfer.js/dist/plugins/record';
6
+ import { ZoomPluginOptions } from 'wavesurfer.js/dist/plugins/zoom';
7
+ import { TimelinePluginOptions } from 'wavesurfer.js/dist/plugins/timeline';
8
+ import { HoverPluginOptions } from 'wavesurfer.js/dist/plugins/hover';
9
+ import { SpectrogramPluginOptions } from 'wavesurfer.js/dist/plugins/spectrogram';
10
+ import { EnvelopePluginOptions } from 'wavesurfer.js/dist/plugins/envelope';
11
+ import { MinimapPluginOptions } from 'wavesurfer.js/dist/plugins/minimap';
5
12
  export type PartialWaveSurferOptions = Partial<Omit<WaveSurferOptions, 'container'>>;
6
13
  export type WaveSurferIns = {
7
14
  containerRef: Ref<HTMLElement | null>;
8
15
  options: PartialWaveSurferOptions;
9
16
  };
10
17
  export type UseWaveSurfer = ReturnType<typeof useWaveSurferInstance> & ReturnType<typeof useWaveSurferState>;
18
+ export type Plugins = {
19
+ regions: any;
20
+ timeline: TimelinePluginOptions;
21
+ zoom: ZoomPluginOptions;
22
+ minimap: MinimapPluginOptions;
23
+ envelope: EnvelopePluginOptions;
24
+ spectrogram: SpectrogramPluginOptions;
25
+ hover: HoverPluginOptions;
26
+ };
27
+ export type UseWaveSurferRecorder = WaveSurferIns & {
28
+ recordPluginOptions?: RecordPluginOptions;
29
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Meer Sagor",
3
3
  "name": "@meersagor/wavesurfer-vue",
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "description": "Vue3 component for wavesurfer.js",
6
6
  "private": false,
7
7
  "type": "module",