wavesurfer.js 7.5.6 → 7.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base-plugin.d.ts +7 -2
- package/dist/base-plugin.js +6 -2
- package/dist/dom.d.ts +13 -0
- package/dist/dom.js +33 -0
- package/dist/event-emitter.d.ts +3 -8
- package/dist/event-emitter.js +8 -11
- package/dist/plugins/base-plugin.d.ts +7 -2
- package/dist/plugins/dom.d.ts +13 -0
- package/dist/plugins/envelope.cjs +1 -1
- package/dist/plugins/envelope.esm.js +1 -1
- package/dist/plugins/envelope.js +1 -1
- package/dist/plugins/envelope.min.js +1 -1
- package/dist/plugins/event-emitter.d.ts +3 -8
- package/dist/plugins/hover.cjs +1 -1
- package/dist/plugins/hover.esm.js +1 -1
- package/dist/plugins/hover.js +1 -1
- package/dist/plugins/hover.min.js +1 -1
- 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/record.cjs +1 -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/regions.cjs +1 -1
- package/dist/plugins/regions.esm.js +1 -1
- package/dist/plugins/regions.js +1 -1
- package/dist/plugins/regions.min.js +1 -1
- package/dist/plugins/spectrogram.cjs +1 -1
- package/dist/plugins/spectrogram.esm.js +1 -1
- package/dist/plugins/spectrogram.js +1 -1
- package/dist/plugins/spectrogram.min.js +1 -1
- package/dist/plugins/timeline.cjs +1 -1
- 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/webaudio.d.ts +8 -0
- package/dist/plugins/zoom.cjs +1 -1
- 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/types.d.ts +278 -0
- package/dist/wavesurfer.cjs +1 -1
- package/dist/wavesurfer.d.ts +5 -91
- package/dist/wavesurfer.esm.js +1 -1
- package/dist/wavesurfer.js +1 -1
- package/dist/wavesurfer.min.js +1 -1
- package/dist/webaudio.d.ts +8 -0
- package/dist/webaudio.js +15 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e
|
|
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.Spectrogram=e())}(this,(function(){"use strict";function t(t,e,s,i){return new(s||(s=Promise))((function(a,r){function n(t){try{h(i.next(t))}catch(t){r(t)}}function o(t){try{h(i.throw(t))}catch(t){r(t)}}function h(t){var e;t.done?a(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(n,o)}h((i=i.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class e{constructor(){this.listeners={}}on(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.un(t,s),this.un(t,e)};return this.on(t,s),s}return()=>this.un(t,e)}un(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 s extends e{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()))}}function i(t,e){const s=e.xmlns?document.createElementNS(e.xmlns,t):document.createElement(t);for(const[t,a]of Object.entries(e))if("children"===t)for(const[t,a]of Object.entries(e))"string"==typeof a?s.appendChild(document.createTextNode(a)):s.appendChild(i(t,a));else"style"===t?Object.assign(s.style,a):"textContent"===t?s.textContent=a:s.setAttribute(t,a.toString());return s}function a(t,e,s){const a=i(t,e||{});return null==s||s.appendChild(a),a}function r(t,e,s,i){switch(this.bufferSize=t,this.sampleRate=e,this.bandwidth=2/t*(e/2),this.sinTable=new Float32Array(t),this.cosTable=new Float32Array(t),this.windowValues=new Float32Array(t),this.reverseTable=new Uint32Array(t),this.peakBand=0,this.peak=0,s){case"bartlett":for(a=0;a<t;a++)this.windowValues[a]=2/(t-1)*((t-1)/2-Math.abs(a-(t-1)/2));break;case"bartlettHann":for(a=0;a<t;a++)this.windowValues[a]=.62-.48*Math.abs(a/(t-1)-.5)-.38*Math.cos(2*Math.PI*a/(t-1));break;case"blackman":for(i=i||.16,a=0;a<t;a++)this.windowValues[a]=(1-i)/2-.5*Math.cos(2*Math.PI*a/(t-1))+i/2*Math.cos(4*Math.PI*a/(t-1));break;case"cosine":for(a=0;a<t;a++)this.windowValues[a]=Math.cos(Math.PI*a/(t-1)-Math.PI/2);break;case"gauss":for(i=i||.25,a=0;a<t;a++)this.windowValues[a]=Math.pow(Math.E,-.5*Math.pow((a-(t-1)/2)/(i*(t-1)/2),2));break;case"hamming":for(a=0;a<t;a++)this.windowValues[a]=.54-.46*Math.cos(2*Math.PI*a/(t-1));break;case"hann":case void 0:for(a=0;a<t;a++)this.windowValues[a]=.5*(1-Math.cos(2*Math.PI*a/(t-1)));break;case"lanczoz":for(a=0;a<t;a++)this.windowValues[a]=Math.sin(Math.PI*(2*a/(t-1)-1))/(Math.PI*(2*a/(t-1)-1));break;case"rectangular":for(a=0;a<t;a++)this.windowValues[a]=1;break;case"triangular":for(a=0;a<t;a++)this.windowValues[a]=2/t*(t/2-Math.abs(a-(t-1)/2));break;default:throw Error("No such window function '"+s+"'")}for(var a,r=1,n=t>>1;r<t;){for(a=0;a<r;a++)this.reverseTable[a+r]=this.reverseTable[a]+n;r<<=1,n>>=1}for(a=0;a<t;a++)this.sinTable[a]=Math.sin(-Math.PI/a),this.cosTable[a]=Math.cos(-Math.PI/a);this.calculateSpectrum=function(t){var e,s,i,a=this.bufferSize,r=this.cosTable,n=this.sinTable,o=this.reverseTable,h=new Float32Array(a),l=new Float32Array(a),c=2/this.bufferSize,f=Math.sqrt,u=new Float32Array(a/2),p=Math.floor(Math.log(a)/Math.LN2);if(Math.pow(2,p)!==a)throw"Invalid buffer size, must be a power of 2.";if(a!==t.length)throw"Supplied buffer is not the same size as defined FFT. FFT Size: "+a+" Buffer Size: "+t.length;for(var d,w,b,g,M,v,m,y,x=1,S=0;S<a;S++)h[S]=t[o[S]]*this.windowValues[o[S]],l[S]=0;for(;x<a;){d=r[x],w=n[x],b=1,g=0;for(var q=0;q<x;q++){for(S=q;S<a;)v=b*h[M=S+x]-g*l[M],m=b*l[M]+g*h[M],h[M]=h[S]-v,l[M]=l[S]-m,h[S]+=v,l[S]+=m,S+=x<<1;b=(y=b)*d-g*w,g=y*w+g*d}x<<=1}S=0;for(var C=a/2;S<C;S++)(i=c*f((e=h[S])*e+(s=l[S])*s))>this.peak&&(this.peakBand=S,this.peak=i),u[S]=i;return u}}class n extends s{static create(t){return new n(t||{})}constructor(t){if(super(t),this.frequenciesDataUrl=t.frequenciesDataUrl,this.container="string"==typeof t.container?document.querySelector(t.container):t.container,t.colorMap){if(t.colorMap.length<256)throw new Error("Colormap must contain 256 elements");for(let e=0;e<t.colorMap.length;e++){if(4!==t.colorMap[e].length)throw new Error("ColorMap entries must contain 4 values")}this.colorMap=t.colorMap}else{this.colorMap=[];for(let t=0;t<256;t++){const e=(255-t)/256;this.colorMap.push([e,e,e,1])}}this.fftSamples=t.fftSamples||512,this.height=t.height||this.fftSamples/2,this.noverlap=t.noverlap,this.windowFunc=t.windowFunc,this.alpha=t.alpha,this.frequencyMin=t.frequencyMin||0,this.frequencyMax=t.frequencyMax||0,this.createWrapper(),this.createCanvas()}onInit(){this.container=this.container||this.wavesurfer.getWrapper(),this.container.appendChild(this.wrapper),this.wavesurfer.options.fillParent&&Object.assign(this.wrapper.style,{width:"100%",overflowX:"hidden",overflowY:"hidden"}),this.subscriptions.push(this.wavesurfer.on("redraw",(()=>this.render())))}destroy(){this.unAll(),this.wavesurfer.un("ready",this._onReady),this.wavesurfer.un("redraw",this._onRender),this.wavesurfer=null,this.util=null,this.options=null,this.wrapper&&(this.wrapper.remove(),this.wrapper=null),super.destroy()}loadFrequenciesData(e){return t(this,void 0,void 0,(function*(){const t=yield fetch(e);if(!t.ok)throw new Error("Unable to fetch frequencies data");const s=yield t.json();this.drawSpectrogram(s)}))}createWrapper(){this.wrapper=a("div",{style:{display:"block",position:"relative",userSelect:"none"}}),this.options.labels&&(this.labelsEl=a("canvas",{part:"spec-labels",style:{position:"absolute",zIndex:9,width:"55px",height:"100%"}},this.wrapper)),this.wrapper.addEventListener("click",this._onWrapperClick)}createCanvas(){this.canvas=a("canvas",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",zIndex:4}},this.wrapper),this.spectrCc=this.canvas.getContext("2d")}render(){var t;if(this.frequenciesDataUrl)this.loadFrequenciesData(this.frequenciesDataUrl);else{const e=null===(t=this.wavesurfer)||void 0===t?void 0:t.getDecodedData();e&&this.drawSpectrogram(this.getFrequencies(e))}}drawSpectrogram(t){isNaN(t[0][0])||(t=[t]),this.wrapper.style.height=this.height*t.length+"px",this.width=this.wavesurfer.getWrapper().offsetWidth,this.canvas.width=this.width,this.canvas.height=this.height*t.length;const e=this.spectrCc,s=this.height,i=this.width,a=this.buffer.sampleRate/2,r=this.frequencyMin,n=this.frequencyMax;if(e){for(let o=0;o<t.length;o++){const h=this.resample(t[o]),l=new ImageData(i,s);for(let t=0;t<h.length;t++)for(let e=0;e<h[t].length;e++){const a=this.colorMap[h[t][e]],r=4*((s-e)*i+t);l.data[r]=255*a[0],l.data[r+1]=255*a[1],l.data[r+2]=255*a[2],l.data[r+3]=255*a[3]}createImageBitmap(l).then((t=>{e.drawImage(t,0,s*(1-n/a),i,s*(n-r)/a,0,s*o,i,s)}))}this.options.labels&&this.loadLabels(this.options.labelsBackground,"12px","12px","",this.options.labelsColor,this.options.labelsHzColor||this.options.labelsColor,"center","#specLabels",t.length),this.emit("ready")}}getFrequencies(t){var e,s;const i=this.fftSamples,a=(null!==(e=this.options.splitChannels)&&void 0!==e?e:null===(s=this.wavesurfer)||void 0===s?void 0:s.options.splitChannels)?t.numberOfChannels:1;if(this.frequencyMax=this.frequencyMax||t.sampleRate/2,!t)return;this.buffer=t;const n=t.sampleRate,o=[];let h=this.noverlap;if(!h){const e=t.length/this.canvas.width;h=Math.max(0,Math.round(i-e))}const l=new r(i,n,this.windowFunc,this.alpha);for(let e=0;e<a;e++){const s=t.getChannelData(e),a=[];let r=0;for(;r+i<s.length;){const t=s.slice(r,r+i),e=l.calculateSpectrum(t),n=new Uint8Array(i/2);for(let t=0;t<i/2;t++)n[t]=Math.max(-255,45*Math.log10(e[t]));a.push(n),r+=i-h}o.push(a)}return o}freqType(t){return t>=1e3?(t/1e3).toFixed(1):Math.round(t)}unitType(t){return t>=1e3?"KHz":"Hz"}loadLabels(t,e,s,i,a,r,n,o,h){t=t||"rgba(68,68,68,0)",e=e||"12px",s=s||"12px",i=i||"Helvetica",a=a||"#fff",r=r||"#fff",n=n||"center";const l=this.height||512,c=l/256*5,f=this.frequencyMin,u=(this.frequencyMax-f)/c,p=this.labelsEl.getContext("2d"),d=window.devicePixelRatio;if(this.labelsEl.height=this.height*h*d,this.labelsEl.width=55*d,p.scale(d,d),p)for(let o=0;o<h;o++){let h;for(p.fillStyle=t,p.fillRect(0,o*l,55,(1+o)*l),p.fill(),h=0;h<=c;h++){p.textAlign=n,p.textBaseline="middle";const t=f+u*h,c=this.freqType(t),d=this.unitType(t),w=16;let b;b=0==h?(1+o)*l+h-10:(1+o)*l-50*h+2,p.fillStyle=r,p.font=s+" "+i,p.fillText(d,w+24,b),p.fillStyle=a,p.font=e+" "+i,p.fillText(c,w,b)}}}resample(t){const e=this.width,s=[],i=1/t.length,a=1/e;let r;for(r=0;r<e;r++){const e=new Array(t[0].length);let n;for(n=0;n<t.length;n++){const s=n*i,o=s+i,h=r*a,l=h+a,c=o<=h||l<=s?0:Math.min(Math.max(o,h),Math.max(l,s))-Math.max(Math.min(o,h),Math.min(l,s));let f;if(c>0)for(f=0;f<t[0].length;f++)null==e[f]&&(e[f]=0),e[f]+=c/a*t[n][f]}const o=new Uint8Array(t[0].length);let h;for(h=0;h<t[0].length;h++)o[h]=e[h];s.push(o)}return s}}return n}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";class t{constructor(){this.listeners={}
|
|
1
|
+
"use strict";class t{constructor(){this.listeners={}}on(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.un(t,i),this.un(t,e)};return this.on(t,i),i}return()=>this.un(t,e)}un(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()))}}function i(t,e){const n=e.xmlns?document.createElementNS(e.xmlns,t):document.createElement(t);for(const[t,s]of Object.entries(e))if("children"===t)for(const[t,s]of Object.entries(e))"string"==typeof s?n.appendChild(document.createTextNode(s)):n.appendChild(i(t,s));else"style"===t?Object.assign(n.style,s):"textContent"===t?n.textContent=s:n.setAttribute(t,s.toString());return n}function n(t,e,n){const s=i(t,e||{});return null==n||n.appendChild(s),s}const s={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 o extends e{constructor(t){super(t||{}),this.options=Object.assign({},s,t),this.timelineWrapper=this.initTimelineWrapper()}static create(t){return new o(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(){return n("div",{part:"timeline-wrapper",style:{pointerEvents:"none"}})}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,s,o,r,l;const a=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,h=this.timelineWrapper.scrollWidth/a,p=null!==(s=this.options.timeInterval)&&void 0!==s?s:this.defaultTimeInterval(h),c=null!==(o=this.options.primaryLabelInterval)&&void 0!==o?o:this.defaultPrimaryLabelInterval(h),u=this.options.primaryLabelSpacing,d=null!==(r=this.options.secondaryLabelInterval)&&void 0!==r?r:this.defaultSecondaryLabelInterval(h),f=this.options.secondaryLabelSpacing,m="beforebegin"===this.options.insertPosition,y=n("div",{style:Object.assign({height:`${this.options.height}px`,overflow:"hidden",fontSize:this.options.height/2+"px",whiteSpace:"nowrap"},m?{position:"absolute",top:"0",left:"0",right:"0",zIndex:"2"}:{position:"relative"})});"string"==typeof this.options.style?y.setAttribute("style",y.getAttribute("style")+this.options.style):"object"==typeof this.options.style&&Object.assign(y.style,this.options.style);const v=n("div",{style:{width:"0",height:"50%",display:"flex",flexDirection:"column",justifyContent:m?"flex-start":"flex-end",top:m?"0":"auto",bottom:m?"auto":"0",overflow:"visible",borderLeft:"1px solid currentColor",opacity:`${null!==(l=this.options.secondaryLabelOpacity)&&void 0!==l?l:.25}`,position:"absolute",zIndex:"1"}});for(let t=0,e=0;t<a;t+=p,e++){const i=v.cloneNode(),n=Math.round(100*t)/100%c==0||u&&e%u==0,s=Math.round(100*t)/100%d==0||f&&e%f==0;(n||s)&&(i.style.height="100%",i.style.textIndent="3px",i.textContent=this.options.formatTimeCallback(t),n&&(i.style.opacity="1"));const o=n?"primary":s?"secondary":"tick";i.setAttribute("part",`timeline-notch timeline-notch-${o}`),i.style.left=t*h+"px",y.appendChild(i)}this.timelineWrapper.innerHTML="",this.timelineWrapper.appendChild(y),this.emit("ready")}}module.exports=o;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
class t{constructor(){this.listeners={}
|
|
1
|
+
class t{constructor(){this.listeners={}}on(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.un(t,i),this.un(t,e)};return this.on(t,i),i}return()=>this.un(t,e)}un(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()))}}function i(t,e){const n=e.xmlns?document.createElementNS(e.xmlns,t):document.createElement(t);for(const[t,s]of Object.entries(e))if("children"===t)for(const[t,s]of Object.entries(e))"string"==typeof s?n.appendChild(document.createTextNode(s)):n.appendChild(i(t,s));else"style"===t?Object.assign(n.style,s):"textContent"===t?n.textContent=s:n.setAttribute(t,s.toString());return n}function n(t,e,n){const s=i(t,e||{});return null==n||n.appendChild(s),s}const s={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 o extends e{constructor(t){super(t||{}),this.options=Object.assign({},s,t),this.timelineWrapper=this.initTimelineWrapper()}static create(t){return new o(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(){return n("div",{part:"timeline-wrapper",style:{pointerEvents:"none"}})}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,s,o,r,l;const a=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,h=this.timelineWrapper.scrollWidth/a,p=null!==(s=this.options.timeInterval)&&void 0!==s?s:this.defaultTimeInterval(h),c=null!==(o=this.options.primaryLabelInterval)&&void 0!==o?o:this.defaultPrimaryLabelInterval(h),d=this.options.primaryLabelSpacing,u=null!==(r=this.options.secondaryLabelInterval)&&void 0!==r?r:this.defaultSecondaryLabelInterval(h),f=this.options.secondaryLabelSpacing,m="beforebegin"===this.options.insertPosition,y=n("div",{style:Object.assign({height:`${this.options.height}px`,overflow:"hidden",fontSize:this.options.height/2+"px",whiteSpace:"nowrap"},m?{position:"absolute",top:"0",left:"0",right:"0",zIndex:"2"}:{position:"relative"})});"string"==typeof this.options.style?y.setAttribute("style",y.getAttribute("style")+this.options.style):"object"==typeof this.options.style&&Object.assign(y.style,this.options.style);const v=n("div",{style:{width:"0",height:"50%",display:"flex",flexDirection:"column",justifyContent:m?"flex-start":"flex-end",top:m?"0":"auto",bottom:m?"auto":"0",overflow:"visible",borderLeft:"1px solid currentColor",opacity:`${null!==(l=this.options.secondaryLabelOpacity)&&void 0!==l?l:.25}`,position:"absolute",zIndex:"1"}});for(let t=0,e=0;t<a;t+=p,e++){const i=v.cloneNode(),n=Math.round(100*t)/100%c==0||d&&e%d==0,s=Math.round(100*t)/100%u==0||f&&e%f==0;(n||s)&&(i.style.height="100%",i.style.textIndent="3px",i.textContent=this.options.formatTimeCallback(t),n&&(i.style.opacity="1"));const o=n?"primary":s?"secondary":"tick";i.setAttribute("part",`timeline-notch timeline-notch-${o}`),i.style.left=t*h+"px",y.appendChild(i)}this.timelineWrapper.innerHTML="",this.timelineWrapper.appendChild(y),this.emit("ready")}}export{o as default};
|
package/dist/plugins/timeline.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class t{constructor(){this.listeners={}
|
|
1
|
+
class t{constructor(){this.listeners={}}on(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.un(t,i),this.un(t,e)};return this.on(t,i),i}return()=>this.un(t,e)}un(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()))}}function i(t,e){const n=e.xmlns?document.createElementNS(e.xmlns,t):document.createElement(t);for(const[t,s]of Object.entries(e))if("children"===t)for(const[t,s]of Object.entries(e))"string"==typeof s?n.appendChild(document.createTextNode(s)):n.appendChild(i(t,s));else"style"===t?Object.assign(n.style,s):"textContent"===t?n.textContent=s:n.setAttribute(t,s.toString());return n}function n(t,e,n){const s=i(t,e||{});return null==n||n.appendChild(s),s}const s={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 o extends e{constructor(t){super(t||{}),this.options=Object.assign({},s,t),this.timelineWrapper=this.initTimelineWrapper()}static create(t){return new o(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(){return n("div",{part:"timeline-wrapper",style:{pointerEvents:"none"}})}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,s,o,r,l;const a=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,h=this.timelineWrapper.scrollWidth/a,p=null!==(s=this.options.timeInterval)&&void 0!==s?s:this.defaultTimeInterval(h),c=null!==(o=this.options.primaryLabelInterval)&&void 0!==o?o:this.defaultPrimaryLabelInterval(h),d=this.options.primaryLabelSpacing,u=null!==(r=this.options.secondaryLabelInterval)&&void 0!==r?r:this.defaultSecondaryLabelInterval(h),f=this.options.secondaryLabelSpacing,m="beforebegin"===this.options.insertPosition,y=n("div",{style:Object.assign({height:`${this.options.height}px`,overflow:"hidden",fontSize:this.options.height/2+"px",whiteSpace:"nowrap"},m?{position:"absolute",top:"0",left:"0",right:"0",zIndex:"2"}:{position:"relative"})});"string"==typeof this.options.style?y.setAttribute("style",y.getAttribute("style")+this.options.style):"object"==typeof this.options.style&&Object.assign(y.style,this.options.style);const v=n("div",{style:{width:"0",height:"50%",display:"flex",flexDirection:"column",justifyContent:m?"flex-start":"flex-end",top:m?"0":"auto",bottom:m?"auto":"0",overflow:"visible",borderLeft:"1px solid currentColor",opacity:`${null!==(l=this.options.secondaryLabelOpacity)&&void 0!==l?l:.25}`,position:"absolute",zIndex:"1"}});for(let t=0,e=0;t<a;t+=p,e++){const i=v.cloneNode(),n=Math.round(100*t)/100%c==0||d&&e%d==0,s=Math.round(100*t)/100%u==0||f&&e%f==0;(n||s)&&(i.style.height="100%",i.style.textIndent="3px",i.textContent=this.options.formatTimeCallback(t),n&&(i.style.opacity="1"));const o=n?"primary":s?"secondary":"tick";i.setAttribute("part",`timeline-notch timeline-notch-${o}`),i.style.left=t*h+"px",y.appendChild(i)}this.timelineWrapper.innerHTML="",this.timelineWrapper.appendChild(y),this.emit("ready")}}export{o 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={}
|
|
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={}}on(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.un(t,i),this.un(t,e)};return this.on(t,i),i}return()=>this.un(t,e)}un(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()))}}function i(t,e){const n=e.xmlns?document.createElementNS(e.xmlns,t):document.createElement(t);for(const[t,s]of Object.entries(e))if("children"===t)for(const[t,s]of Object.entries(e))"string"==typeof s?n.appendChild(document.createTextNode(s)):n.appendChild(i(t,s));else"style"===t?Object.assign(n.style,s):"textContent"===t?n.textContent=s:n.setAttribute(t,s.toString());return n}function n(t,e,n){const s=i(t,e||{});return null==n||n.appendChild(s),s}const s={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 o extends e{constructor(t){super(t||{}),this.options=Object.assign({},s,t),this.timelineWrapper=this.initTimelineWrapper()}static create(t){return new o(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(){return n("div",{part:"timeline-wrapper",style:{pointerEvents:"none"}})}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,s,o,r,l;const a=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,h=this.timelineWrapper.scrollWidth/a,p=null!==(s=this.options.timeInterval)&&void 0!==s?s:this.defaultTimeInterval(h),u=null!==(o=this.options.primaryLabelInterval)&&void 0!==o?o:this.defaultPrimaryLabelInterval(h),d=this.options.primaryLabelSpacing,c=null!==(r=this.options.secondaryLabelInterval)&&void 0!==r?r:this.defaultSecondaryLabelInterval(h),f=this.options.secondaryLabelSpacing,m="beforebegin"===this.options.insertPosition,y=n("div",{style:Object.assign({height:`${this.options.height}px`,overflow:"hidden",fontSize:this.options.height/2+"px",whiteSpace:"nowrap"},m?{position:"absolute",top:"0",left:"0",right:"0",zIndex:"2"}:{position:"relative"})});"string"==typeof this.options.style?y.setAttribute("style",y.getAttribute("style")+this.options.style):"object"==typeof this.options.style&&Object.assign(y.style,this.options.style);const v=n("div",{style:{width:"0",height:"50%",display:"flex",flexDirection:"column",justifyContent:m?"flex-start":"flex-end",top:m?"0":"auto",bottom:m?"auto":"0",overflow:"visible",borderLeft:"1px solid currentColor",opacity:`${null!==(l=this.options.secondaryLabelOpacity)&&void 0!==l?l:.25}`,position:"absolute",zIndex:"1"}});for(let t=0,e=0;t<a;t+=p,e++){const i=v.cloneNode(),n=Math.round(100*t)/100%u==0||d&&e%d==0,s=Math.round(100*t)/100%c==0||f&&e%f==0;(n||s)&&(i.style.height="100%",i.style.textIndent="3px",i.textContent=this.options.formatTimeCallback(t),n&&(i.style.opacity="1"));const o=n?"primary":s?"secondary":"tick";i.setAttribute("part",`timeline-notch timeline-notch-${o}`),i.style.left=t*h+"px",y.appendChild(i)}this.timelineWrapper.innerHTML="",this.timelineWrapper.appendChild(y),this.emit("ready")}}return o}));
|
|
@@ -26,6 +26,12 @@ declare class WebAudioPlayer extends EventEmitter<WebAudioPlayerEvents> {
|
|
|
26
26
|
paused: boolean;
|
|
27
27
|
crossOrigin: string | null;
|
|
28
28
|
constructor(audioContext?: AudioContext);
|
|
29
|
+
/** Subscribe to an event. Returns an unsubscribe function. */
|
|
30
|
+
addEventListener: <EventName extends keyof WebAudioPlayerEvents>(event: EventName, listener: (...args: WebAudioPlayerEvents[EventName]) => void, options?: {
|
|
31
|
+
once?: boolean | undefined;
|
|
32
|
+
} | undefined) => () => void;
|
|
33
|
+
/** Unsubscribe from an event */
|
|
34
|
+
removeEventListener: <EventName extends keyof WebAudioPlayerEvents>(event: EventName, listener: (...args: WebAudioPlayerEvents[EventName]) => void) => void;
|
|
29
35
|
load(): Promise<void>;
|
|
30
36
|
get src(): string;
|
|
31
37
|
set src(value: string);
|
|
@@ -46,5 +52,7 @@ declare class WebAudioPlayer extends EventEmitter<WebAudioPlayerEvents> {
|
|
|
46
52
|
set muted(value: boolean);
|
|
47
53
|
/** Get the GainNode used to play the audio. Can be used to attach filters. */
|
|
48
54
|
getGainNode(): GainNode;
|
|
55
|
+
/** Get decoded audio */
|
|
56
|
+
getChannelData(): Float32Array[];
|
|
49
57
|
}
|
|
50
58
|
export default WebAudioPlayer;
|
package/dist/plugins/zoom.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";class t{constructor(){this.listeners={}
|
|
1
|
+
"use strict";class t{constructor(){this.listeners={}}on(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.un(t,s),this.un(t,e)};return this.on(t,s),s}return()=>this.un(t,e)}un(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.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class t{constructor(){this.listeners={}
|
|
1
|
+
class t{constructor(){this.listeners={}}on(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.un(t,s),this.un(t,e)};return this.on(t,s),s}return()=>this.un(t,e)}un(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 t{constructor(){this.listeners={}
|
|
1
|
+
class t{constructor(){this.listeners={}}on(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.un(t,s),this.un(t,e)};return this.on(t,s),s}return()=>this.un(t,e)}un(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
|
|
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.Zoom=e())}(this,(function(){"use strict";class t{constructor(){this.listeners={}}on(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.un(t,s),this.un(t,e)};return this.on(t,s),s}return()=>this.un(t,e)}un(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()}}return i}));
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
type GeneralEventTypes = {
|
|
2
|
+
[EventName: string]: unknown[];
|
|
3
|
+
};
|
|
4
|
+
type EventListener<EventTypes extends GeneralEventTypes, EventName extends keyof EventTypes> = (...args: EventTypes[EventName]) => void;
|
|
5
|
+
/** A simple event emitter that can be used to listen to and emit events. */
|
|
6
|
+
declare class EventEmitter<EventTypes extends GeneralEventTypes> {
|
|
7
|
+
private listeners;
|
|
8
|
+
/** Subscribe to an event. Returns an unsubscribe function. */
|
|
9
|
+
on<EventName extends keyof EventTypes>(event: EventName, listener: EventListener<EventTypes, EventName>, options?: {
|
|
10
|
+
once?: boolean;
|
|
11
|
+
}): () => void;
|
|
12
|
+
/** Unsubscribe from an event */
|
|
13
|
+
un<EventName extends keyof EventTypes>(event: EventName, listener: EventListener<EventTypes, EventName>): void;
|
|
14
|
+
/** Subscribe to an event only once */
|
|
15
|
+
once<EventName extends keyof EventTypes>(event: EventName, listener: EventListener<EventTypes, EventName>): () => void;
|
|
16
|
+
/** Clear all events */
|
|
17
|
+
unAll(): void;
|
|
18
|
+
/** Emit an event */
|
|
19
|
+
protected emit<EventName extends keyof EventTypes>(eventName: EventName, ...args: EventTypes[EventName]): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type BasePluginEvents = {
|
|
23
|
+
destroy: [];
|
|
24
|
+
};
|
|
25
|
+
type GenericPlugin = BasePlugin<BasePluginEvents, unknown>;
|
|
26
|
+
/** Base class for wavesurfer plugins */
|
|
27
|
+
declare class BasePlugin<EventTypes extends BasePluginEvents, Options> extends EventEmitter<EventTypes> {
|
|
28
|
+
protected wavesurfer?: WaveSurfer;
|
|
29
|
+
protected subscriptions: (() => void)[];
|
|
30
|
+
protected options: Options;
|
|
31
|
+
/** Create a plugin instance */
|
|
32
|
+
constructor(options: Options);
|
|
33
|
+
/** Called after this.wavesurfer is available */
|
|
34
|
+
protected onInit(): void;
|
|
35
|
+
/** Do not call directly, only called by WavesSurfer internally */
|
|
36
|
+
_init(wavesurfer: WaveSurfer): void;
|
|
37
|
+
/** Destroy the plugin and unsubscribe from all events */
|
|
38
|
+
destroy(): void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type PlayerOptions = {
|
|
42
|
+
media?: HTMLMediaElement;
|
|
43
|
+
mediaControls?: boolean;
|
|
44
|
+
autoplay?: boolean;
|
|
45
|
+
playbackRate?: number;
|
|
46
|
+
};
|
|
47
|
+
declare class Player<T extends GeneralEventTypes> extends EventEmitter<T> {
|
|
48
|
+
protected media: HTMLMediaElement;
|
|
49
|
+
private isExternalMedia;
|
|
50
|
+
constructor(options: PlayerOptions);
|
|
51
|
+
protected onMediaEvent(event: keyof HTMLMediaElementEventMap, callback: () => void, options?: AddEventListenerOptions): () => void;
|
|
52
|
+
protected onceMediaEvent(event: keyof HTMLMediaElementEventMap, callback: () => void): () => void;
|
|
53
|
+
protected getSrc(): string;
|
|
54
|
+
private revokeSrc;
|
|
55
|
+
protected setSrc(url: string, blob?: Blob): void;
|
|
56
|
+
protected destroy(): void;
|
|
57
|
+
protected setMediaElement(element: HTMLMediaElement): void;
|
|
58
|
+
/** Start playing the audio */
|
|
59
|
+
play(): Promise<void>;
|
|
60
|
+
/** Pause the audio */
|
|
61
|
+
pause(): void;
|
|
62
|
+
/** Check if the audio is playing */
|
|
63
|
+
isPlaying(): boolean;
|
|
64
|
+
/** Jumpt to a specific time in the audio (in seconds) */
|
|
65
|
+
setTime(time: number): void;
|
|
66
|
+
/** Get the duration of the audio in seconds */
|
|
67
|
+
getDuration(): number;
|
|
68
|
+
/** Get the current audio position in seconds */
|
|
69
|
+
getCurrentTime(): number;
|
|
70
|
+
/** Get the audio volume */
|
|
71
|
+
getVolume(): number;
|
|
72
|
+
/** Set the audio volume */
|
|
73
|
+
setVolume(volume: number): void;
|
|
74
|
+
/** Get the audio muted state */
|
|
75
|
+
getMuted(): boolean;
|
|
76
|
+
/** Mute or unmute the audio */
|
|
77
|
+
setMuted(muted: boolean): void;
|
|
78
|
+
/** Get the playback speed */
|
|
79
|
+
getPlaybackRate(): number;
|
|
80
|
+
/** Set the playback speed, pass an optional false to NOT preserve the pitch */
|
|
81
|
+
setPlaybackRate(rate: number, preservePitch?: boolean): void;
|
|
82
|
+
/** Get the HTML media element */
|
|
83
|
+
getMediaElement(): HTMLMediaElement;
|
|
84
|
+
/** Set a sink id to change the audio output device */
|
|
85
|
+
setSinkId(sinkId: string): Promise<void>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
type WaveSurferOptions = {
|
|
89
|
+
/** Required: an HTML element or selector where the waveform will be rendered */
|
|
90
|
+
container: HTMLElement | string;
|
|
91
|
+
/** The height of the waveform in pixels, or "auto" to fill the container height */
|
|
92
|
+
height?: number | 'auto';
|
|
93
|
+
/** The width of the waveform in pixels or any CSS value; defaults to 100% */
|
|
94
|
+
width?: number | string;
|
|
95
|
+
/** The color of the waveform */
|
|
96
|
+
waveColor?: string | string[] | CanvasGradient;
|
|
97
|
+
/** The color of the progress mask */
|
|
98
|
+
progressColor?: string | string[] | CanvasGradient;
|
|
99
|
+
/** The color of the playpack cursor */
|
|
100
|
+
cursorColor?: string;
|
|
101
|
+
/** The cursor width */
|
|
102
|
+
cursorWidth?: number;
|
|
103
|
+
/** If set, the waveform will be rendered with bars like this: ▁ ▂ ▇ ▃ ▅ ▂ */
|
|
104
|
+
barWidth?: number;
|
|
105
|
+
/** Spacing between bars in pixels */
|
|
106
|
+
barGap?: number;
|
|
107
|
+
/** Rounded borders for bars */
|
|
108
|
+
barRadius?: number;
|
|
109
|
+
/** A vertical scaling factor for the waveform */
|
|
110
|
+
barHeight?: number;
|
|
111
|
+
/** Vertical bar alignment */
|
|
112
|
+
barAlign?: 'top' | 'bottom';
|
|
113
|
+
/** Minimum pixels per second of audio (i.e. the zoom level) */
|
|
114
|
+
minPxPerSec?: number;
|
|
115
|
+
/** Stretch the waveform to fill the container, true by default */
|
|
116
|
+
fillParent?: boolean;
|
|
117
|
+
/** Audio URL */
|
|
118
|
+
url?: string;
|
|
119
|
+
/** Pre-computed audio data, arrays of floats for each channel */
|
|
120
|
+
peaks?: Array<Float32Array | number[]>;
|
|
121
|
+
/** Pre-computed audio duration in seconds */
|
|
122
|
+
duration?: number;
|
|
123
|
+
/** Use an existing media element instead of creating one */
|
|
124
|
+
media?: HTMLMediaElement;
|
|
125
|
+
/** Whether to show default audio element controls */
|
|
126
|
+
mediaControls?: boolean;
|
|
127
|
+
/** Play the audio on load */
|
|
128
|
+
autoplay?: boolean;
|
|
129
|
+
/** Pass false to disable clicks on the waveform */
|
|
130
|
+
interact?: boolean;
|
|
131
|
+
/** Allow to drag the cursor to seek to a new position */
|
|
132
|
+
dragToSeek?: boolean;
|
|
133
|
+
/** Hide the scrollbar */
|
|
134
|
+
hideScrollbar?: boolean;
|
|
135
|
+
/** Audio rate, i.e. the playback speed */
|
|
136
|
+
audioRate?: number;
|
|
137
|
+
/** Automatically scroll the container to keep the current position in viewport */
|
|
138
|
+
autoScroll?: boolean;
|
|
139
|
+
/** If autoScroll is enabled, keep the cursor in the center of the waveform during playback */
|
|
140
|
+
autoCenter?: boolean;
|
|
141
|
+
/** Decoding sample rate. Doesn't affect the playback. Defaults to 8000 */
|
|
142
|
+
sampleRate?: number;
|
|
143
|
+
/** Render each audio channel as a separate waveform */
|
|
144
|
+
splitChannels?: Partial<WaveSurferOptions>[];
|
|
145
|
+
/** Stretch the waveform to the full height */
|
|
146
|
+
normalize?: boolean;
|
|
147
|
+
/** The list of plugins to initialize on start */
|
|
148
|
+
plugins?: GenericPlugin[];
|
|
149
|
+
/** Custom render function */
|
|
150
|
+
renderFunction?: (peaks: Array<Float32Array | number[]>, ctx: CanvasRenderingContext2D) => void;
|
|
151
|
+
/** Options to pass to the fetch method */
|
|
152
|
+
fetchParams?: RequestInit;
|
|
153
|
+
/** Playback "backend" to use, defaults to MediaElement */
|
|
154
|
+
backend?: 'WebAudio' | 'MediaElement';
|
|
155
|
+
};
|
|
156
|
+
declare const defaultOptions: {
|
|
157
|
+
waveColor: string;
|
|
158
|
+
progressColor: string;
|
|
159
|
+
cursorWidth: number;
|
|
160
|
+
minPxPerSec: number;
|
|
161
|
+
fillParent: boolean;
|
|
162
|
+
interact: boolean;
|
|
163
|
+
dragToSeek: boolean;
|
|
164
|
+
autoScroll: boolean;
|
|
165
|
+
autoCenter: boolean;
|
|
166
|
+
sampleRate: number;
|
|
167
|
+
};
|
|
168
|
+
type WaveSurferEvents = {
|
|
169
|
+
/** When audio starts loading */
|
|
170
|
+
load: [url: string];
|
|
171
|
+
/** During audio loading */
|
|
172
|
+
loading: [percent: number];
|
|
173
|
+
/** When the audio has been decoded */
|
|
174
|
+
decode: [duration: number];
|
|
175
|
+
/** When the audio is both decoded and can play */
|
|
176
|
+
ready: [duration: number];
|
|
177
|
+
/** When a waveform is drawn */
|
|
178
|
+
redraw: [];
|
|
179
|
+
/** When the audio starts playing */
|
|
180
|
+
play: [];
|
|
181
|
+
/** When the audio pauses */
|
|
182
|
+
pause: [];
|
|
183
|
+
/** When the audio finishes playing */
|
|
184
|
+
finish: [];
|
|
185
|
+
/** On audio position change, fires continuously during playback */
|
|
186
|
+
timeupdate: [currentTime: number];
|
|
187
|
+
/** An alias of timeupdate but only when the audio is playing */
|
|
188
|
+
audioprocess: [currentTime: number];
|
|
189
|
+
/** When the user seeks to a new position */
|
|
190
|
+
seeking: [currentTime: number];
|
|
191
|
+
/** When the user interacts with the waveform (i.g. clicks or drags on it) */
|
|
192
|
+
interaction: [newTime: number];
|
|
193
|
+
/** When the user clicks on the waveform */
|
|
194
|
+
click: [relativeX: number, relativeY: number];
|
|
195
|
+
/** When the user double-clicks on the waveform */
|
|
196
|
+
dblclick: [relativeX: number, relativeY: number];
|
|
197
|
+
/** When the user drags the cursor */
|
|
198
|
+
drag: [relativeX: number];
|
|
199
|
+
/** When the waveform is scrolled (panned) */
|
|
200
|
+
scroll: [visibleStartTime: number, visibleEndTime: number];
|
|
201
|
+
/** When the zoom level changes */
|
|
202
|
+
zoom: [minPxPerSec: number];
|
|
203
|
+
/** Just before the waveform is destroyed so you can clean up your events */
|
|
204
|
+
destroy: [];
|
|
205
|
+
};
|
|
206
|
+
declare class WaveSurfer extends Player<WaveSurferEvents> {
|
|
207
|
+
options: WaveSurferOptions & typeof defaultOptions;
|
|
208
|
+
private renderer;
|
|
209
|
+
private timer;
|
|
210
|
+
private plugins;
|
|
211
|
+
private decodedData;
|
|
212
|
+
protected subscriptions: Array<() => void>;
|
|
213
|
+
protected mediaSubscriptions: Array<() => void>;
|
|
214
|
+
/** Create a new WaveSurfer instance */
|
|
215
|
+
static create(options: WaveSurferOptions): WaveSurfer;
|
|
216
|
+
/** Create a new WaveSurfer instance */
|
|
217
|
+
constructor(options: WaveSurferOptions);
|
|
218
|
+
private initTimerEvents;
|
|
219
|
+
private initPlayerEvents;
|
|
220
|
+
private initRendererEvents;
|
|
221
|
+
private initPlugins;
|
|
222
|
+
private unsubscribePlayerEvents;
|
|
223
|
+
/** Set new wavesurfer options and re-render it */
|
|
224
|
+
setOptions(options: Partial<WaveSurferOptions>): void;
|
|
225
|
+
/** Register a wavesurfer.js plugin */
|
|
226
|
+
registerPlugin<T extends GenericPlugin>(plugin: T): T;
|
|
227
|
+
/** For plugins only: get the waveform wrapper div */
|
|
228
|
+
getWrapper(): HTMLElement;
|
|
229
|
+
/** Get the current scroll position in pixels */
|
|
230
|
+
getScroll(): number;
|
|
231
|
+
/** Get all registered plugins */
|
|
232
|
+
getActivePlugins(): GenericPlugin[];
|
|
233
|
+
private loadAudio;
|
|
234
|
+
/** Load an audio file by URL, with optional pre-decoded audio data */
|
|
235
|
+
load(url: string, channelData?: WaveSurferOptions['peaks'], duration?: number): Promise<void>;
|
|
236
|
+
/** Load an audio blob */
|
|
237
|
+
loadBlob(blob: Blob, channelData?: WaveSurferOptions['peaks'], duration?: number): Promise<void>;
|
|
238
|
+
/** Zoom the waveform by a given pixels-per-second factor */
|
|
239
|
+
zoom(minPxPerSec: number): void;
|
|
240
|
+
/** Get the decoded audio data */
|
|
241
|
+
getDecodedData(): AudioBuffer | null;
|
|
242
|
+
/** Get decoded peaks */
|
|
243
|
+
exportPeaks({ channels, maxLength, precision }?: {
|
|
244
|
+
channels?: number | undefined;
|
|
245
|
+
maxLength?: number | undefined;
|
|
246
|
+
precision?: number | undefined;
|
|
247
|
+
}): Array<number[]>;
|
|
248
|
+
/** Get the duration of the audio in seconds */
|
|
249
|
+
getDuration(): number;
|
|
250
|
+
/** Toggle if the waveform should react to clicks */
|
|
251
|
+
toggleInteraction(isInteractive: boolean): void;
|
|
252
|
+
/** Seek to a percentage of audio as [0..1] (0 = beginning, 1 = end) */
|
|
253
|
+
seekTo(progress: number): void;
|
|
254
|
+
/** Play or pause the audio */
|
|
255
|
+
playPause(): Promise<void>;
|
|
256
|
+
/** Stop the audio and go to the beginning */
|
|
257
|
+
stop(): void;
|
|
258
|
+
/** Skip N or -N seconds from the current position */
|
|
259
|
+
skip(seconds: number): void;
|
|
260
|
+
/** Empty the waveform */
|
|
261
|
+
empty(): void;
|
|
262
|
+
/** Set HTML media element */
|
|
263
|
+
setMediaElement(element: HTMLMediaElement): void;
|
|
264
|
+
/**
|
|
265
|
+
* Export the waveform image as a data-URI or a blob.
|
|
266
|
+
*
|
|
267
|
+
* @param format The format of the exported image, can be `image/png`, `image/jpeg`, `image/webp` or any other format supported by the browser.
|
|
268
|
+
* @param quality The quality of the exported image, for `image/jpeg` or `image/webp`. Must be between 0 and 1.
|
|
269
|
+
* @param type The type of the exported image, can be `dataURL` (default) or `blob`.
|
|
270
|
+
* @returns A promise that resolves with an array of data-URLs or blobs, one for each canvas element.
|
|
271
|
+
*/
|
|
272
|
+
exportImage(format: string, quality: number, type: 'dataURL'): Promise<string[]>;
|
|
273
|
+
exportImage(format: string, quality: number, type: 'blob'): Promise<Blob[]>;
|
|
274
|
+
/** Unmount wavesurfer */
|
|
275
|
+
destroy(): void;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export { type WaveSurferEvents, type WaveSurferOptions, WaveSurfer as default };
|