wavesurfer.js 7.9.9 → 7.10.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.
Files changed (52) hide show
  1. package/README.md +3 -47
  2. package/dist/base-plugin.d.ts +1 -0
  3. package/dist/base-plugin.js +9 -0
  4. package/dist/fft.d.ts +54 -0
  5. package/dist/fft.js +341 -0
  6. package/dist/plugins/envelope.cjs +1 -1
  7. package/dist/plugins/envelope.esm.js +1 -1
  8. package/dist/plugins/envelope.js +1 -1
  9. package/dist/plugins/envelope.min.js +1 -1
  10. package/dist/plugins/hover.cjs +1 -1
  11. package/dist/plugins/hover.esm.js +1 -1
  12. package/dist/plugins/hover.js +1 -1
  13. package/dist/plugins/hover.min.js +1 -1
  14. package/dist/plugins/minimap.cjs +1 -1
  15. package/dist/plugins/minimap.esm.js +1 -1
  16. package/dist/plugins/minimap.js +1 -1
  17. package/dist/plugins/minimap.min.js +1 -1
  18. package/dist/plugins/record.cjs +1 -1
  19. package/dist/plugins/record.esm.js +1 -1
  20. package/dist/plugins/record.js +1 -1
  21. package/dist/plugins/record.min.js +1 -1
  22. package/dist/plugins/regions.cjs +1 -1
  23. package/dist/plugins/regions.esm.js +1 -1
  24. package/dist/plugins/regions.js +1 -1
  25. package/dist/plugins/regions.min.js +1 -1
  26. package/dist/plugins/spectrogram-windowed.cjs +1 -0
  27. package/dist/plugins/spectrogram-windowed.d.ts +138 -0
  28. package/dist/plugins/spectrogram-windowed.esm.js +1 -0
  29. package/dist/plugins/spectrogram-windowed.js +1 -0
  30. package/dist/plugins/spectrogram-windowed.min.js +1 -0
  31. package/dist/plugins/spectrogram-worker.d.ts +5 -0
  32. package/dist/plugins/spectrogram-worker.js +85 -0
  33. package/dist/plugins/spectrogram.cjs +1 -1
  34. package/dist/plugins/spectrogram.d.ts +41 -24
  35. package/dist/plugins/spectrogram.esm.js +1 -1
  36. package/dist/plugins/spectrogram.js +1 -1
  37. package/dist/plugins/spectrogram.min.js +1 -1
  38. package/dist/plugins/timeline.cjs +1 -1
  39. package/dist/plugins/timeline.esm.js +1 -1
  40. package/dist/plugins/timeline.js +1 -1
  41. package/dist/plugins/timeline.min.js +1 -1
  42. package/dist/plugins/zoom.cjs +1 -1
  43. package/dist/plugins/zoom.esm.js +1 -1
  44. package/dist/plugins/zoom.js +1 -1
  45. package/dist/plugins/zoom.min.js +1 -1
  46. package/dist/types.d.ts +3 -0
  47. package/dist/wavesurfer.cjs +1 -1
  48. package/dist/wavesurfer.d.ts +2 -0
  49. package/dist/wavesurfer.esm.js +1 -1
  50. package/dist/wavesurfer.js +9 -0
  51. package/dist/wavesurfer.min.js +1 -1
  52. package/package.json +6 -5
@@ -1 +1 @@
1
- function t(t,e,s,r){return new(s||(s=Promise))((function(i,a){function n(t){try{o(r.next(t))}catch(t){a(t)}}function h(t){try{o(r.throw(t))}catch(t){a(t)}}function o(t){var e;t.done?i(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(n,h)}o((r=r.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 r(t,e){const s=e.xmlns?document.createElementNS(e.xmlns,t):document.createElement(t);for(const[t,i]of Object.entries(e))if("children"===t&&i)for(const[t,e]of Object.entries(i))e instanceof Node?s.appendChild(e):"string"==typeof e?s.appendChild(document.createTextNode(e)):s.appendChild(r(t,e));else"style"===t?Object.assign(s.style,i):"textContent"===t?s.textContent=i:s.setAttribute(t,i.toString());return s}function i(t,e,s){const i=r(t,e||{});return null==s||s.appendChild(i),i}function a(t,e,s,r){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(i=0;i<t;i++)this.windowValues[i]=2/(t-1)*((t-1)/2-Math.abs(i-(t-1)/2));break;case"bartlettHann":for(i=0;i<t;i++)this.windowValues[i]=.62-.48*Math.abs(i/(t-1)-.5)-.38*Math.cos(2*Math.PI*i/(t-1));break;case"blackman":for(r=r||.16,i=0;i<t;i++)this.windowValues[i]=(1-r)/2-.5*Math.cos(2*Math.PI*i/(t-1))+r/2*Math.cos(4*Math.PI*i/(t-1));break;case"cosine":for(i=0;i<t;i++)this.windowValues[i]=Math.cos(Math.PI*i/(t-1)-Math.PI/2);break;case"gauss":for(r=r||.25,i=0;i<t;i++)this.windowValues[i]=Math.pow(Math.E,-.5*Math.pow((i-(t-1)/2)/(r*(t-1)/2),2));break;case"hamming":for(i=0;i<t;i++)this.windowValues[i]=.54-.46*Math.cos(2*Math.PI*i/(t-1));break;case"hann":case void 0:for(i=0;i<t;i++)this.windowValues[i]=.5*(1-Math.cos(2*Math.PI*i/(t-1)));break;case"lanczoz":for(i=0;i<t;i++)this.windowValues[i]=Math.sin(Math.PI*(2*i/(t-1)-1))/(Math.PI*(2*i/(t-1)-1));break;case"rectangular":for(i=0;i<t;i++)this.windowValues[i]=1;break;case"triangular":for(i=0;i<t;i++)this.windowValues[i]=2/t*(t/2-Math.abs(i-(t-1)/2));break;default:throw Error("No such window function '"+s+"'")}for(var i,a=1,n=t>>1;a<t;){for(i=0;i<a;i++)this.reverseTable[i+a]=this.reverseTable[i]+n;a<<=1,n>>=1}for(i=0;i<t;i++)this.sinTable[i]=Math.sin(-Math.PI/i),this.cosTable[i]=Math.cos(-Math.PI/i);this.calculateSpectrum=function(t){var e,s,r,i=this.bufferSize,a=this.cosTable,n=this.sinTable,h=this.reverseTable,o=new Float32Array(i),l=new Float32Array(i),c=2/this.bufferSize,u=Math.sqrt,f=new Float32Array(i/2),p=Math.floor(Math.log(i)/Math.LN2);if(Math.pow(2,p)!==i)throw"Invalid buffer size, must be a power of 2.";if(i!==t.length)throw"Supplied buffer is not the same size as defined FFT. FFT Size: "+i+" Buffer Size: "+t.length;for(var d,w,g,b,M,m,v,y,T=1,k=0;k<i;k++)o[k]=t[h[k]]*this.windowValues[h[k]],l[k]=0;for(;T<i;){d=a[T],w=n[T],g=1,b=0;for(var z=0;z<T;z++){for(k=z;k<i;)m=g*o[M=k+T]-b*l[M],v=g*l[M]+b*o[M],o[M]=o[k]-m,l[M]=l[k]-v,o[k]+=m,l[k]+=v,k+=T<<1;g=(y=g)*d-b*w,b=y*w+b*d}T<<=1}k=0;for(var F=i/2;k<F;k++)(r=c*u((e=o[k])*e+(s=l[k])*s))>this.peak&&(this.peakBand=k,this.peak=r),f[k]=r;return f}}const n=1e3*Math.log(10)/107.939;class h extends s{static create(t){return new h(t||{})}constructor(t){var e,s;if(super(t),this.frequenciesDataUrl=t.frequenciesDataUrl,this.container="string"==typeof t.container?document.querySelector(t.container):t.container,t.colorMap&&"string"!=typeof 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 switch(this.colorMap=t.colorMap||"roseus",this.colorMap){case"gray":this.colorMap=[];for(let t=0;t<256;t++){const e=(255-t)/256;this.colorMap.push([e,e,e,1])}break;case"igray":this.colorMap=[];for(let t=0;t<256;t++){const e=t/256;this.colorMap.push([e,e,e,1])}break;case"roseus":this.colorMap=[[.004528,.004341,.004307,1],[.005625,.006156,.00601,1],[.006628,.008293,.008161,1],[.007551,.010738,.01079,1],[.008382,.013482,.013941,1],[.009111,.01652,.017662,1],[.009727,.019846,.022009,1],[.010223,.023452,.027035,1],[.010593,.027331,.032799,1],[.010833,.031475,.039361,1],[.010941,.035875,.046415,1],[.010918,.04052,.053597,1],[.010768,.045158,.060914,1],[.010492,.049708,.068367,1],[.010098,.054171,.075954,1],[.009594,.058549,.083672,1],[.008989,.06284,.091521,1],[.008297,.067046,.099499,1],[.00753,.071165,.107603,1],[.006704,.075196,.11583,1],[.005838,.07914,.124178,1],[.004949,.082994,.132643,1],[.004062,.086758,.141223,1],[.003198,.09043,.149913,1],[.002382,.09401,.158711,1],[.001643,.097494,.167612,1],[.001009,.100883,.176612,1],[514e-6,.104174,.185704,1],[187e-6,.107366,.194886,1],[66e-6,.110457,.204151,1],[186e-6,.113445,.213496,1],[587e-6,.116329,.222914,1],[.001309,.119106,.232397,1],[.002394,.121776,.241942,1],[.003886,.124336,.251542,1],[.005831,.126784,.261189,1],[.008276,.12912,.270876,1],[.011268,.131342,.280598,1],[.014859,.133447,.290345,1],[.0191,.135435,.300111,1],[.024043,.137305,.309888,1],[.029742,.139054,.319669,1],[.036252,.140683,.329441,1],[.043507,.142189,.339203,1],[.050922,.143571,.348942,1],[.058432,.144831,.358649,1],[.066041,.145965,.368319,1],[.073744,.146974,.377938,1],[.081541,.147858,.387501,1],[.089431,.148616,.396998,1],[.097411,.149248,.406419,1],[.105479,.149754,.415755,1],[.113634,.150134,.424998,1],[.121873,.150389,.434139,1],[.130192,.150521,.443167,1],[.138591,.150528,.452075,1],[.147065,.150413,.460852,1],[.155614,.150175,.469493,1],[.164232,.149818,.477985,1],[.172917,.149343,.486322,1],[.181666,.148751,.494494,1],[.190476,.148046,.502493,1],[.199344,.147229,.510313,1],[.208267,.146302,.517944,1],[.217242,.145267,.52538,1],[.226264,.144131,.532613,1],[.235331,.142894,.539635,1],[.24444,.141559,.546442,1],[.253587,.140131,.553026,1],[.262769,.138615,.559381,1],[.271981,.137016,.5655,1],[.281222,.135335,.571381,1],[.290487,.133581,.577017,1],[.299774,.131757,.582404,1],[.30908,.129867,.587538,1],[.318399,.12792,.592415,1],[.32773,.125921,.597032,1],[.337069,.123877,.601385,1],[.346413,.121793,.605474,1],[.355758,.119678,.609295,1],[.365102,.11754,.612846,1],[.374443,.115386,.616127,1],[.383774,.113226,.619138,1],[.393096,.111066,.621876,1],[.402404,.108918,.624343,1],[.411694,.106794,.62654,1],[.420967,.104698,.628466,1],[.430217,.102645,.630123,1],[.439442,.100647,.631513,1],[.448637,.098717,.632638,1],[.457805,.096861,.633499,1],[.46694,.095095,.6341,1],[.47604,.093433,.634443,1],[.485102,.091885,.634532,1],[.494125,.090466,.63437,1],[.503104,.08919,.633962,1],[.512041,.088067,.633311,1],[.520931,.087108,.63242,1],[.529773,.086329,.631297,1],[.538564,.085738,.629944,1],[.547302,.085346,.628367,1],[.555986,.085162,.626572,1],[.564615,.08519,.624563,1],[.573187,.085439,.622345,1],[.581698,.085913,.619926,1],[.590149,.086615,.617311,1],[.598538,.087543,.614503,1],[.606862,.0887,.611511,1],[.61512,.090084,.608343,1],[.623312,.09169,.605001,1],[.631438,.093511,.601489,1],[.639492,.095546,.597821,1],[.647476,.097787,.593999,1],[.655389,.100226,.590028,1],[.66323,.102856,.585914,1],[.670995,.105669,.581667,1],[.678686,.108658,.577291,1],[.686302,.111813,.57279,1],[.69384,.115129,.568175,1],[.7013,.118597,.563449,1],[.708682,.122209,.558616,1],[.715984,.125959,.553687,1],[.723206,.12984,.548666,1],[.730346,.133846,.543558,1],[.737406,.13797,.538366,1],[.744382,.142209,.533101,1],[.751274,.146556,.527767,1],[.758082,.151008,.522369,1],[.764805,.155559,.516912,1],[.771443,.160206,.511402,1],[.777995,.164946,.505845,1],[.784459,.169774,.500246,1],[.790836,.174689,.494607,1],[.797125,.179688,.488935,1],[.803325,.184767,.483238,1],[.809435,.189925,.477518,1],[.815455,.19516,.471781,1],[.821384,.200471,.466028,1],[.827222,.205854,.460267,1],[.832968,.211308,.454505,1],[.838621,.216834,.448738,1],[.844181,.222428,.442979,1],[.849647,.22809,.43723,1],[.855019,.233819,.431491,1],[.860295,.239613,.425771,1],[.865475,.245471,.420074,1],[.870558,.251393,.414403,1],[.875545,.25738,.408759,1],[.880433,.263427,.403152,1],[.885223,.269535,.397585,1],[.889913,.275705,.392058,1],[.894503,.281934,.386578,1],[.898993,.288222,.381152,1],[.903381,.294569,.375781,1],[.907667,.300974,.370469,1],[.911849,.307435,.365223,1],[.915928,.313953,.360048,1],[.919902,.320527,.354948,1],[.923771,.327155,.349928,1],[.927533,.333838,.344994,1],[.931188,.340576,.340149,1],[.934736,.347366,.335403,1],[.938175,.354207,.330762,1],[.941504,.361101,.326229,1],[.944723,.368045,.321814,1],[.947831,.375039,.317523,1],[.950826,.382083,.313364,1],[.953709,.389175,.309345,1],[.956478,.396314,.305477,1],[.959133,.403499,.301766,1],[.961671,.410731,.298221,1],[.964093,.418008,.294853,1],[.966399,.425327,.291676,1],[.968586,.43269,.288696,1],[.970654,.440095,.285926,1],[.972603,.44754,.28338,1],[.974431,.455025,.281067,1],[.976139,.462547,.279003,1],[.977725,.470107,.277198,1],[.979188,.477703,.275666,1],[.980529,.485332,.274422,1],[.981747,.492995,.273476,1],[.98284,.50069,.272842,1],[.983808,.508415,.272532,1],[.984653,.516168,.27256,1],[.985373,.523948,.272937,1],[.985966,.531754,.273673,1],[.986436,.539582,.274779,1],[.98678,.547434,.276264,1],[.986998,.555305,.278135,1],[.987091,.563195,.280401,1],[.987061,.5711,.283066,1],[.986907,.579019,.286137,1],[.986629,.58695,.289615,1],[.986229,.594891,.293503,1],[.985709,.602839,.297802,1],[.985069,.610792,.302512,1],[.98431,.618748,.307632,1],[.983435,.626704,.313159,1],[.982445,.634657,.319089,1],[.981341,.642606,.32542,1],[.98013,.650546,.332144,1],[.978812,.658475,.339257,1],[.977392,.666391,.346753,1],[.97587,.67429,.354625,1],[.974252,.68217,.362865,1],[.972545,.690026,.371466,1],[.97075,.697856,.380419,1],[.968873,.705658,.389718,1],[.966921,.713426,.399353,1],[.964901,.721157,.409313,1],[.962815,.728851,.419594,1],[.960677,.7365,.430181,1],[.95849,.744103,.44107,1],[.956263,.751656,.452248,1],[.954009,.759153,.463702,1],[.951732,.766595,.475429,1],[.949445,.773974,.487414,1],[.947158,.781289,.499647,1],[.944885,.788535,.512116,1],[.942634,.795709,.524811,1],[.940423,.802807,.537717,1],[.938261,.809825,.550825,1],[.936163,.81676,.564121,1],[.934146,.823608,.577591,1],[.932224,.830366,.59122,1],[.930412,.837031,.604997,1],[.928727,.843599,.618904,1],[.927187,.850066,.632926,1],[.925809,.856432,.647047,1],[.92461,.862691,.661249,1],[.923607,.868843,.675517,1],[.92282,.874884,.689832,1],[.922265,.880812,.704174,1],[.921962,.886626,.718523,1],[.92193,.892323,.732859,1],[.922183,.897903,.747163,1],[.922741,.903364,.76141,1],[.92362,.908706,.77558,1],[.924837,.913928,.789648,1],[.926405,.919031,.80359,1],[.92834,.924015,.817381,1],[.930655,.928881,.830995,1],[.93336,.933631,.844405,1],[.936466,.938267,.857583,1],[.939982,.942791,.870499,1],[.943914,.947207,.883122,1],[.948267,.951519,.895421,1],[.953044,.955732,.907359,1],[.958246,.959852,.918901,1],[.963869,.963887,.930004,1],[.969909,.967845,.940623,1],[.976355,.971737,.950704,1],[.983195,.97558,.960181,1],[.990402,.979395,.968966,1],[.99793,.983217,.97692,1]];break;default:throw Error("No such colormap '"+this.colorMap+"'")}this.fftSamples=t.fftSamples||512,this.height=t.height||200,this.noverlap=t.noverlap||null,this.windowFunc=t.windowFunc||"hann",this.alpha=t.alpha,this.frequencyMin=t.frequencyMin||0,this.frequencyMax=t.frequencyMax||0,this.gainDB=null!==(e=t.gainDB)&&void 0!==e?e:20,this.rangeDB=null!==(s=t.rangeDB)&&void 0!==s?s:80,this.scale=t.scale||"mel",this.numMelFilters=this.fftSamples/2,this.numLogFilters=this.fftSamples/2,this.numBarkFilters=this.fftSamples/2,this.numErbFilters=this.fftSamples/2,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("decode",(()=>{this.buffer=void 0,this.frequencies=void 0})),this.wavesurfer.on("redraw",(()=>this.render())))}destroy(){this.unAll(),this.wavesurfer.un("ready",this._onReady),this.wavesurfer.un("redraw",this._onRender),this.buffer=void 0,this.frequencies=void 0,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.frequencies=s,this.drawSpectrogram(s)}))}createWrapper(){this.wrapper=i("div",{style:{display:"block",position:"relative",userSelect:"none"}}),this.options.labels&&(this.labelsEl=i("canvas",{part:"spec-labels",style:{position:"absolute",zIndex:9,width:"55px",height:"100%"}},this.wrapper)),this.wrapper.addEventListener("click",this._onWrapperClick)}createCanvas(){this.canvas=i("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.frequencies&&this.buffer===e||(this.frequencies=this.getFrequencies(e)),this.drawSpectrogram(this.frequencies))}}drawSpectrogram(t){isNaN(t[0][0])||(t=[t]),this.wrapper.style.height=this.height*t.length+"px",this.canvas.width=this.getWidth(),this.canvas.height=this.height*t.length;const e=this.spectrCc,s=this.height,r=this.getWidth(),i=this.buffer.sampleRate/2,a=this.frequencyMin,n=this.frequencyMax;if(e){if(n>i){const i=this.colorMap[this.colorMap.length-1];e.fillStyle=`rgba(${i[0]}, ${i[1]}, ${i[2]}, ${i[3]})`,e.fillRect(0,0,r,s*t.length)}for(let h=0;h<t.length;h++){const o=this.resample(t[h]),l=o[0].length,c=new ImageData(r,l);for(let t=0;t<o.length;t++)for(let e=0;e<o[t].length;e++){const s=this.colorMap[o[t][e]],i=4*((l-e-1)*r+t);c.data[i]=255*s[0],c.data[i+1]=255*s[1],c.data[i+2]=255*s[2],c.data[i+3]=255*s[3]}const u=this.hzToScale(a)/this.hzToScale(i),f=this.hzToScale(n)/this.hzToScale(i),p=Math.min(1,f);createImageBitmap(c,0,Math.round(l*(1-p)),r,Math.round(l*(p-u))).then((t=>{e.drawImage(t,0,s*(h+1-p/f),r,s*p/f)}))}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")}}createFilterBank(t,e,s,r){const i=s(0),a=s(e/2),n=Array.from({length:t},(()=>Array(this.fftSamples/2+1).fill(0))),h=e/this.fftSamples;for(let e=0;e<t;e++){let s=r(i+e/t*(a-i)),o=Math.floor(s/h),l=o*h,c=(s-l)/((o+1)*h-l);n[e][o]=1-c,n[e][o+1]=c}return n}hzToMel(t){return 2595*Math.log10(1+t/700)}melToHz(t){return 700*(Math.pow(10,t/2595)-1)}createMelFilterBank(t,e){return this.createFilterBank(t,e,this.hzToMel,this.melToHz)}hzToLog(t){return Math.log10(Math.max(1,t))}logToHz(t){return Math.pow(10,t)}createLogFilterBank(t,e){return this.createFilterBank(t,e,this.hzToLog,this.logToHz)}hzToBark(t){let e=26.81*t/(1960+t)-.53;return e<2&&(e+=.15*(2-e)),e>20.1&&(e+=.22*(e-20.1)),e}barkToHz(t){return t<2&&(t=(t-.3)/.85),t>20.1&&(t=(t+4.422)/1.22),(t+.53)/(26.28-t)*1960}createBarkFilterBank(t,e){return this.createFilterBank(t,e,this.hzToBark,this.barkToHz)}hzToErb(t){return n*Math.log10(1+.00437*t)}erbToHz(t){return(Math.pow(10,t/n)-1)/.00437}createErbFilterBank(t,e){return this.createFilterBank(t,e,this.hzToErb,this.erbToHz)}hzToScale(t){switch(this.scale){case"mel":return this.hzToMel(t);case"logarithmic":return this.hzToLog(t);case"bark":return this.hzToBark(t);case"erb":return this.hzToErb(t)}return t}scaleToHz(t){switch(this.scale){case"mel":return this.melToHz(t);case"logarithmic":return this.logToHz(t);case"bark":return this.barkToHz(t);case"erb":return this.erbToHz(t)}return t}applyFilterBank(t,e){const s=e.length,r=Float32Array.from({length:s},(()=>0));for(let i=0;i<s;i++)for(let s=0;s<t.length;s++)r[i]+=t[s]*e[i][s];return r}getWidth(){return this.wavesurfer.getWrapper().offsetWidth}getFrequencies(t){var e,s;const r=this.fftSamples,i=(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,h=[];let o=this.noverlap;if(!o){const e=t.length/this.canvas.width;o=Math.max(0,Math.round(r-e))}const l=new a(r,n,this.windowFunc,this.alpha);let c;switch(this.scale){case"mel":c=this.createFilterBank(this.numMelFilters,n,this.hzToMel,this.melToHz);break;case"logarithmic":c=this.createFilterBank(this.numLogFilters,n,this.hzToLog,this.logToHz);break;case"bark":c=this.createFilterBank(this.numBarkFilters,n,this.hzToBark,this.barkToHz);break;case"erb":c=this.createFilterBank(this.numErbFilters,n,this.hzToErb,this.erbToHz)}for(let e=0;e<i;e++){const s=t.getChannelData(e),i=[];let a=0;for(;a+r<s.length;){const t=s.slice(a,a+r),e=new Uint8Array(r/2);let n=l.calculateSpectrum(t);c&&(n=this.applyFilterBank(n,c));for(let t=0;t<r/2;t++){const s=n[t]>1e-12?n[t]:1e-12,r=20*Math.log10(s);r<-this.gainDB-this.rangeDB?e[t]=0:r>-this.gainDB?e[t]=255:e[t]=(r+this.gainDB)/this.rangeDB*255+256}i.push(e),a+=r-o}h.push(i)}return this.frequencies=h,h}freqType(t){return t>=1e3?(t/1e3).toFixed(1):Math.round(t)}unitType(t){return t>=1e3?"kHz":"Hz"}getLabelFrequency(t,e){const s=this.hzToScale(this.frequencyMin),r=this.hzToScale(this.frequencyMax);return this.scaleToHz(s+t/e*(r-s))}loadLabels(t,e,s,r,i,a,n,h,o){t=t||"rgba(68,68,68,0)",e=e||"12px",s=s||"12px",r=r||"Helvetica",i=i||"#fff",a=a||"#fff",n=n||"center";const l=this.height||512,c=l/256*5;this.frequencyMin;this.frequencyMax;const u=this.labelsEl.getContext("2d"),f=window.devicePixelRatio;if(this.labelsEl.height=this.height*o*f,this.labelsEl.width=55*f,u.scale(f,f),u)for(let h=0;h<o;h++){let o;for(u.fillStyle=t,u.fillRect(0,h*l,55,(1+h)*l),u.fill(),o=0;o<=c;o++){u.textAlign=n,u.textBaseline="middle";const t=this.getLabelFrequency(o,c),f=this.freqType(t),p=this.unitType(t),d=16;let w=(1+h)*l-o/c*l;w=Math.min(Math.max(w,h*l+10),(1+h)*l-10),u.fillStyle=a,u.font=s+" "+r,u.fillText(p,d+24,w),u.fillStyle=i,u.font=e+" "+r,u.fillText(f,d,w)}}}resample(t){const e=this.getWidth(),s=[],r=1/t.length,i=1/e;let a;for(a=0;a<e;a++){const e=new Array(t[0].length);let n;for(n=0;n<t.length;n++){const s=n*r,h=s+r,o=a*i,l=o+i,c=Math.max(0,Math.min(h,l)-Math.max(s,o));let u;if(c>0)for(u=0;u<t[0].length;u++)null==e[u]&&(e[u]=0),e[u]+=c/i*t[n][u]}const h=new Uint8Array(t[0].length);let o;for(o=0;o<t[0].length;o++)h[o]=e[o];s.push(h)}return s}}export{h as default};
1
+ function e(e,t,s,i){return new(s||(s=Promise))((function(r,n){function a(e){try{l(i.next(e))}catch(e){n(e)}}function o(e){try{l(i.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(a,o)}l((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t=1e3*Math.log(10)/107.939;function s(e){return 2595*Math.log10(1+e/700)}function i(e){return 700*(Math.pow(10,e/2595)-1)}function r(e){return Math.log10(Math.max(1,e))}function n(e){return Math.pow(10,e)}function a(e){let t=26.81*e/(1960+e)-.53;return t<2&&(t+=.15*(2-t)),t>20.1&&(t+=.22*(t-20.1)),t}function o(e){return e<2&&(e=(e-.3)/.85),e>20.1&&(e=(e+4.422)/1.22),(e+.53)/(26.28-e)*1960}function l(e){return t*Math.log10(1+.00437*e)}function h(e){return(Math.pow(10,e/t)-1)/.00437}function c(e,t){switch(t){case"mel":return s(e);case"logarithmic":return r(e);case"bark":return a(e);case"erb":return l(e);default:return e}}function d(e,t,s,i,r){const n=i(0),a=i(s/2),o=Array.from({length:e},(()=>Array(t/2+1).fill(0))),l=s/t;for(let t=0;t<e;t++){let s=r(n+t/e*(a-n)),i=Math.floor(s/l),h=i*l,c=(s-h)/((i+1)*l-h);o[t][i]=1-c,o[t][i+1]=c}return o}function u(e,t){const s=t.length,i=Float32Array.from({length:s},(()=>0));for(let r=0;r<s;r++)for(let s=0;s<e.length;s++)i[r]+=e[s]*t[r][s];return i}const p={gray:()=>{const e=[];for(let t=0;t<256;t++){const s=(255-t)/256;e.push([s,s,s,1])}return e},igray:()=>{const e=[];for(let t=0;t<256;t++){const s=t/256;e.push([s,s,s,1])}return e},roseus:()=>[[.004528,.004341,.004307,1],[.005625,.006156,.00601,1],[.006628,.008293,.008161,1],[.007551,.010738,.01079,1],[.008382,.013482,.013941,1],[.009111,.01652,.017662,1],[.009727,.019846,.022009,1],[.010223,.023452,.027035,1],[.010593,.027331,.032799,1],[.010833,.031475,.039361,1],[.010941,.035875,.046415,1],[.010918,.04052,.053597,1],[.010768,.045158,.060914,1],[.010492,.049708,.068367,1],[.010098,.054171,.075954,1],[.009594,.058549,.083672,1],[.008989,.06284,.091521,1],[.008297,.067046,.099499,1],[.00753,.071165,.107603,1],[.006704,.075196,.11583,1],[.005838,.07914,.124178,1],[.004949,.082994,.132643,1],[.004062,.086758,.141223,1],[.003198,.09043,.149913,1],[.002382,.09401,.158711,1],[.001643,.097494,.167612,1],[.001009,.100883,.176612,1],[514e-6,.104174,.185704,1],[187e-6,.107366,.194886,1],[66e-6,.110457,.204151,1],[186e-6,.113445,.213496,1],[587e-6,.116329,.222914,1],[.001309,.119106,.232397,1],[.002394,.121776,.241942,1],[.003886,.124336,.251542,1],[.005831,.126784,.261189,1],[.008276,.12912,.270876,1],[.011268,.131342,.280598,1],[.014859,.133447,.290345,1],[.0191,.135435,.300111,1],[.024043,.137305,.309888,1],[.029742,.139054,.319669,1],[.036252,.140683,.329441,1],[.043507,.142189,.339203,1],[.050922,.143571,.348942,1],[.058432,.144831,.358649,1],[.066041,.145965,.368319,1],[.073744,.146974,.377938,1],[.081541,.147858,.387501,1],[.089431,.148616,.396998,1],[.097411,.149248,.406419,1],[.105479,.149754,.415755,1],[.113634,.150134,.424998,1],[.121873,.150389,.434139,1],[.130192,.150521,.443167,1],[.138591,.150528,.452075,1],[.147065,.150413,.460852,1],[.155614,.150175,.469493,1],[.164232,.149818,.477985,1],[.172917,.149343,.486322,1],[.181666,.148751,.494494,1],[.190476,.148046,.502493,1],[.199344,.147229,.510313,1],[.208267,.146302,.517944,1],[.217242,.145267,.52538,1],[.226264,.144131,.532613,1],[.235331,.142894,.539635,1],[.24444,.141559,.546442,1],[.253587,.140131,.553026,1],[.262769,.138615,.559381,1],[.271981,.137016,.5655,1],[.281222,.135335,.571381,1],[.290487,.133581,.577017,1],[.299774,.131757,.582404,1],[.30908,.129867,.587538,1],[.318399,.12792,.592415,1],[.32773,.125921,.597032,1],[.337069,.123877,.601385,1],[.346413,.121793,.605474,1],[.355758,.119678,.609295,1],[.365102,.11754,.612846,1],[.374443,.115386,.616127,1],[.383774,.113226,.619138,1],[.393096,.111066,.621876,1],[.402404,.108918,.624343,1],[.411694,.106794,.62654,1],[.420967,.104698,.628466,1],[.430217,.102645,.630123,1],[.439442,.100647,.631513,1],[.448637,.098717,.632638,1],[.457805,.096861,.633499,1],[.46694,.095095,.6341,1],[.47604,.093433,.634443,1],[.485102,.091885,.634532,1],[.494125,.090466,.63437,1],[.503104,.08919,.633962,1],[.512041,.088067,.633311,1],[.520931,.087108,.63242,1],[.529773,.086329,.631297,1],[.538564,.085738,.629944,1],[.547302,.085346,.628367,1],[.555986,.085162,.626572,1],[.564615,.08519,.624563,1],[.573187,.085439,.622345,1],[.581698,.085913,.619926,1],[.590149,.086615,.617311,1],[.598538,.087543,.614503,1],[.606862,.0887,.611511,1],[.61512,.090084,.608343,1],[.623312,.09169,.605001,1],[.631438,.093511,.601489,1],[.639492,.095546,.597821,1],[.647476,.097787,.593999,1],[.655389,.100226,.590028,1],[.66323,.102856,.585914,1],[.670995,.105669,.581667,1],[.678686,.108658,.577291,1],[.686302,.111813,.57279,1],[.69384,.115129,.568175,1],[.7013,.118597,.563449,1],[.708682,.122209,.558616,1],[.715984,.125959,.553687,1],[.723206,.12984,.548666,1],[.730346,.133846,.543558,1],[.737406,.13797,.538366,1],[.744382,.142209,.533101,1],[.751274,.146556,.527767,1],[.758082,.151008,.522369,1],[.764805,.155559,.516912,1],[.771443,.160206,.511402,1],[.777995,.164946,.505845,1],[.784459,.169774,.500246,1],[.790836,.174689,.494607,1],[.797125,.179688,.488935,1],[.803325,.184767,.483238,1],[.809435,.189925,.477518,1],[.815455,.19516,.471781,1],[.821384,.200471,.466028,1],[.827222,.205854,.460267,1],[.832968,.211308,.454505,1],[.838621,.216834,.448738,1],[.844181,.222428,.442979,1],[.849647,.22809,.43723,1],[.855019,.233819,.431491,1],[.860295,.239613,.425771,1],[.865475,.245471,.420074,1],[.870558,.251393,.414403,1],[.875545,.25738,.408759,1],[.880433,.263427,.403152,1],[.885223,.269535,.397585,1],[.889913,.275705,.392058,1],[.894503,.281934,.386578,1],[.898993,.288222,.381152,1],[.903381,.294569,.375781,1],[.907667,.300974,.370469,1],[.911849,.307435,.365223,1],[.915928,.313953,.360048,1],[.919902,.320527,.354948,1],[.923771,.327155,.349928,1],[.927533,.333838,.344994,1],[.931188,.340576,.340149,1],[.934736,.347366,.335403,1],[.938175,.354207,.330762,1],[.941504,.361101,.326229,1],[.944723,.368045,.321814,1],[.947831,.375039,.317523,1],[.950826,.382083,.313364,1],[.953709,.389175,.309345,1],[.956478,.396314,.305477,1],[.959133,.403499,.301766,1],[.961671,.410731,.298221,1],[.964093,.418008,.294853,1],[.966399,.425327,.291676,1],[.968586,.43269,.288696,1],[.970654,.440095,.285926,1],[.972603,.44754,.28338,1],[.974431,.455025,.281067,1],[.976139,.462547,.279003,1],[.977725,.470107,.277198,1],[.979188,.477703,.275666,1],[.980529,.485332,.274422,1],[.981747,.492995,.273476,1],[.98284,.50069,.272842,1],[.983808,.508415,.272532,1],[.984653,.516168,.27256,1],[.985373,.523948,.272937,1],[.985966,.531754,.273673,1],[.986436,.539582,.274779,1],[.98678,.547434,.276264,1],[.986998,.555305,.278135,1],[.987091,.563195,.280401,1],[.987061,.5711,.283066,1],[.986907,.579019,.286137,1],[.986629,.58695,.289615,1],[.986229,.594891,.293503,1],[.985709,.602839,.297802,1],[.985069,.610792,.302512,1],[.98431,.618748,.307632,1],[.983435,.626704,.313159,1],[.982445,.634657,.319089,1],[.981341,.642606,.32542,1],[.98013,.650546,.332144,1],[.978812,.658475,.339257,1],[.977392,.666391,.346753,1],[.97587,.67429,.354625,1],[.974252,.68217,.362865,1],[.972545,.690026,.371466,1],[.97075,.697856,.380419,1],[.968873,.705658,.389718,1],[.966921,.713426,.399353,1],[.964901,.721157,.409313,1],[.962815,.728851,.419594,1],[.960677,.7365,.430181,1],[.95849,.744103,.44107,1],[.956263,.751656,.452248,1],[.954009,.759153,.463702,1],[.951732,.766595,.475429,1],[.949445,.773974,.487414,1],[.947158,.781289,.499647,1],[.944885,.788535,.512116,1],[.942634,.795709,.524811,1],[.940423,.802807,.537717,1],[.938261,.809825,.550825,1],[.936163,.81676,.564121,1],[.934146,.823608,.577591,1],[.932224,.830366,.59122,1],[.930412,.837031,.604997,1],[.928727,.843599,.618904,1],[.927187,.850066,.632926,1],[.925809,.856432,.647047,1],[.92461,.862691,.661249,1],[.923607,.868843,.675517,1],[.92282,.874884,.689832,1],[.922265,.880812,.704174,1],[.921962,.886626,.718523,1],[.92193,.892323,.732859,1],[.922183,.897903,.747163,1],[.922741,.903364,.76141,1],[.92362,.908706,.77558,1],[.924837,.913928,.789648,1],[.926405,.919031,.80359,1],[.92834,.924015,.817381,1],[.930655,.928881,.830995,1],[.93336,.933631,.844405,1],[.936466,.938267,.857583,1],[.939982,.942791,.870499,1],[.943914,.947207,.883122,1],[.948267,.951519,.895421,1],[.953044,.955732,.907359,1],[.958246,.959852,.918901,1],[.963869,.963887,.930004,1],[.969909,.967845,.940623,1],[.976355,.971737,.950704,1],[.983195,.97558,.960181,1],[.990402,.979395,.968966,1],[.99793,.983217,.97692,1]]};function m(e){return e>=1e3?(e/1e3).toFixed(1):Math.round(e).toString()}function f(e){return e>=1e3?"kHz":"Hz"}function b(e,t,s,r,a){const l=c(s,a);return function(e,t){switch(t){case"mel":return i(e);case"logarithmic":return n(e);case"bark":return o(e);case"erb":return h(e);default:return e}}(l+e/t*(c(r,a)-l),a)}function y(e,t,s,i){switch(this.bufferSize=e,this.sampleRate=t,this.bandwidth=2/e*(t/2),this.sinTable=new Float32Array(e),this.cosTable=new Float32Array(e),this.windowValues=new Float32Array(e),this.reverseTable=new Uint32Array(e),this.peakBand=0,this.peak=0,s){case"bartlett":for(r=0;r<e;r++)this.windowValues[r]=2/(e-1)*((e-1)/2-Math.abs(r-(e-1)/2));break;case"bartlettHann":for(r=0;r<e;r++)this.windowValues[r]=.62-.48*Math.abs(r/(e-1)-.5)-.38*Math.cos(2*Math.PI*r/(e-1));break;case"blackman":for(i=i||.16,r=0;r<e;r++)this.windowValues[r]=(1-i)/2-.5*Math.cos(2*Math.PI*r/(e-1))+i/2*Math.cos(4*Math.PI*r/(e-1));break;case"cosine":for(r=0;r<e;r++)this.windowValues[r]=Math.cos(Math.PI*r/(e-1)-Math.PI/2);break;case"gauss":for(i=i||.25,r=0;r<e;r++)this.windowValues[r]=Math.pow(Math.E,-.5*Math.pow((r-(e-1)/2)/(i*(e-1)/2),2));break;case"hamming":for(r=0;r<e;r++)this.windowValues[r]=.54-.46*Math.cos(2*Math.PI*r/(e-1));break;case"hann":case void 0:for(r=0;r<e;r++)this.windowValues[r]=.5*(1-Math.cos(2*Math.PI*r/(e-1)));break;case"lanczoz":for(r=0;r<e;r++)this.windowValues[r]=Math.sin(Math.PI*(2*r/(e-1)-1))/(Math.PI*(2*r/(e-1)-1));break;case"rectangular":for(r=0;r<e;r++)this.windowValues[r]=1;break;case"triangular":for(r=0;r<e;r++)this.windowValues[r]=2/e*(e/2-Math.abs(r-(e-1)/2));break;default:throw Error("No such window function '"+s+"'")}for(var r,n=1,a=e>>1;n<e;){for(r=0;r<n;r++)this.reverseTable[r+n]=this.reverseTable[r]+a;n<<=1,a>>=1}for(r=0;r<e;r++)this.sinTable[r]=Math.sin(-Math.PI/r),this.cosTable[r]=Math.cos(-Math.PI/r);this.calculateSpectrum=function(e){var t,s,i,r=this.bufferSize,n=this.cosTable,a=this.sinTable,o=this.reverseTable,l=new Float32Array(r),h=new Float32Array(r),c=2/this.bufferSize,d=Math.sqrt,u=new Float32Array(r/2),p=Math.floor(Math.log(r)/Math.LN2);if(Math.pow(2,p)!==r)throw"Invalid buffer size, must be a power of 2.";if(r!==e.length)throw"Supplied buffer is not the same size as defined FFT. FFT Size: "+r+" Buffer Size: "+e.length;for(var m,f,b,y,M,w,v,g,W=1,Z=0;Z<r;Z++)l[Z]=e[o[Z]]*this.windowValues[o[Z]],h[Z]=0;for(;W<r;){m=n[W],f=a[W],b=1,y=0;for(var S=0;S<W;S++){for(Z=S;Z<r;)w=b*l[M=Z+W]-y*h[M],v=b*h[M]+y*l[M],l[M]=l[Z]-w,h[M]=h[Z]-v,l[Z]+=w,h[Z]+=v,Z+=W<<1;b=(g=b)*m-y*f,y=g*f+y*m}W<<=1}Z=0;for(var x=r/2;Z<x;Z++)(i=c*d((t=l[Z])*t+(s=h[Z])*s))>this.peak&&(this.peakBand=Z,this.peak=i),u[Z]=i;return u}}class M{constructor(){this.listeners={}}on(e,t,s){if(this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e].add(t),null==s?void 0:s.once){const s=()=>{this.un(e,s),this.un(e,t)};return this.on(e,s),s}return()=>this.un(e,t)}un(e,t){var s;null===(s=this.listeners[e])||void 0===s||s.delete(t)}once(e,t){return this.on(e,t,{once:!0})}unAll(){this.listeners={}}emit(e,...t){this.listeners[e]&&this.listeners[e].forEach((e=>e(...t)))}}class w extends M{constructor(e){super(),this.subscriptions=[],this.isDestroyed=!1,this.options=e}onInit(){}_init(e){this.isDestroyed&&(this.subscriptions=[],this.isDestroyed=!1),this.wavesurfer=e,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((e=>e())),this.subscriptions=[],this.isDestroyed=!0,this.wavesurfer=void 0}}function v(e,t){const s=t.xmlns?document.createElementNS(t.xmlns,e):document.createElement(e);for(const[e,i]of Object.entries(t))if("children"===e&&i)for(const[e,t]of Object.entries(i))t instanceof Node?s.appendChild(t):"string"==typeof t?s.appendChild(document.createTextNode(t)):s.appendChild(v(e,t));else"style"===e?Object.assign(s.style,i):"textContent"===e?s.textContent=i:s.setAttribute(e,i.toString());return s}function g(e,t,s){const i=v(e,t||{});return null==s||s.appendChild(i),i}var W=null;try{var Z="undefined"!=typeof module&&"function"==typeof module.require&&module.require("worker_threads")||"function"==typeof __non_webpack_require__&&__non_webpack_require__("worker_threads")||"function"==typeof require&&require("worker_threads");W=Z.Worker}catch(e){}function S(e,t,s){var i=function(e){return Buffer.from(e,"base64").toString("utf8")}(e),r=i.indexOf("\n",10)+1,n=i.substring(r)+"";return function(e){return new W(n,Object.assign({},e,{eval:!0}))}}function x(e,t,s){var i=function(e){return atob(e)}(e),r=i.indexOf("\n",10)+1,n=i.substring(r)+"",a=new Blob([n],{type:"application/javascript"});return URL.createObjectURL(a)}var X="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0);function k(e,t,s){return X?S(e):function(e){var t;return function(s){return t=t||x(e),new Worker(t,s)}}(e)}var G=k("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwohZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7Y29uc3QgdD0xZTMqTWF0aC5sb2coMTApLzEwNy45Mzk7ZnVuY3Rpb24gZSh0KXtyZXR1cm4gMjU5NSpNYXRoLmxvZzEwKDErdC83MDApfWZ1bmN0aW9uIGEodCl7cmV0dXJuIDcwMCooTWF0aC5wb3coMTAsdC8yNTk1KS0xKX1mdW5jdGlvbiByKHQpe3JldHVybiBNYXRoLmxvZzEwKE1hdGgubWF4KDEsdCkpfWZ1bmN0aW9uIHModCl7cmV0dXJuIE1hdGgucG93KDEwLHQpfWZ1bmN0aW9uIG4odCl7bGV0IGU9MjYuODEqdC8oMTk2MCt0KS0uNTM7cmV0dXJuIGU8MiYmKGUrPS4xNSooMi1lKSksZT4yMC4xJiYoZSs9LjIyKihlLTIwLjEpKSxlfWZ1bmN0aW9uIG8odCl7cmV0dXJuIHQ8MiYmKHQ9KHQtLjMpLy44NSksdD4yMC4xJiYodD0odCs0LjQyMikvMS4yMiksKHQrLjUzKS8oMjYuMjgtdCkqMTk2MH1mdW5jdGlvbiBpKGUpe3JldHVybiB0Kk1hdGgubG9nMTAoMSsuMDA0MzcqZSl9ZnVuY3Rpb24gaChlKXtyZXR1cm4oTWF0aC5wb3coMTAsZS90KS0xKS8uMDA0Mzd9ZnVuY3Rpb24gbCh0LGUsYSxyLHMpe2NvbnN0IG49cigwKSxvPXIoYS8yKSxpPUFycmF5LmZyb20oe2xlbmd0aDp0fSwoKCk9PkFycmF5KGUvMisxKS5maWxsKDApKSksaD1hL2U7Zm9yKGxldCBlPTA7ZTx0O2UrKyl7bGV0IGE9cyhuK2UvdCooby1uKSkscj1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1hdGgubWluKFMseik7Y29uc3QgQj1NYXRoLm1heCg2NCwuMjUqcCkscT1NYXRoLm1heChCLHAtUykseD1bXTtmb3IobGV0IGU9MDtlPEE7ZSsrKXtjb25zdCBhPXRbZV0scj1bXTtmb3IobGV0IHQ9STt0K3A8Vjt0Kz1xKXtjb25zdCBlPWEuc2xpY2UodCx0K3ApO2xldCBzPWYuY2FsY3VsYXRlU3BlY3RydW0oZSk7UCYmKHM9YyhzLFApKTtjb25zdCBuPW5ldyBVaW50OEFycmF5KHMubGVuZ3RoKSxvPVQrRjtmb3IobGV0IHQ9MDt0PHMubGVuZ3RoO3QrKyl7Y29uc3QgZT1zW3RdPjFlLTEyP3NbdF06MWUtMTIsYT0yMCpNYXRoLmxvZzEwKGUpO25bdF09YTwtbz8wOmE+LVQ/MjU1Ok1hdGgucm91bmQoKGErVCkvRioyNTUpfXIucHVzaChuKX14LnB1c2gocil9cmV0dXJuIHh9KGIsZCksTT17dHlwZToiZnJlcXVlbmNpZXNSZXN1bHQiLGlkOncscmVzdWx0OnR9O3NlbGYucG9zdE1lc3NhZ2UoTSl9Y2F0Y2godCl7Y29uc3QgZT17dHlwZToiZnJlcXVlbmNpZXNSZXN1bHQiLGlkOncsZXJyb3I6dCBpbnN0YW5jZW9mIEVycm9yP3QubWVzc2FnZTpTdHJpbmcodCl9O3NlbGYucG9zdE1lc3NhZ2UoZSl9fX0oKTsKLy8jIHNvdXJjZU1hcHBpbmdVUkw9c3BlY3Ryb2dyYW0td29ya2VyLmpzLm1hcAoK");class T extends w{static create(e){return new T(e||{})}constructor(e){var t,s;if(super(e),this.canvases=[],this.useWebWorker=!1,this.worker=null,this.workerPromises=new Map,this.cachedFrequencies=null,this.cachedResampledData=null,this.cachedBuffer=null,this.cachedWidth=0,this.renderTimeout=null,this.isRendering=!1,this.lastZoomLevel=0,this.renderThrottleMs=50,this.zoomThreshold=.05,this.drawnCanvases={},this.pendingBitmaps=new Set,this.isScrollable=!1,this.scrollUnsubscribe=null,this.frequenciesDataUrl=e.frequenciesDataUrl,this.frequenciesDataUrl&&!e.sampleRate)throw new Error("sampleRate option is required when using frequenciesDataUrl");this.container="string"==typeof e.container?document.querySelector(e.container):e.container,this.useWebWorker=!0===e.useWebWorker,this.colorMap=function(e="roseus"){if(e&&"string"!=typeof e){if(e.length<256)throw new Error("Colormap must contain 256 elements");for(let t=0;t<e.length;t++)if(4!==e[t].length)throw new Error("ColorMap entries must contain 4 values");return e}const t=p[e];if(!t)throw Error("No such colormap '"+e+"'");return t()}(e.colorMap),this.fftSamples=e.fftSamples||512,this.height=e.height||200,this.noverlap=e.noverlap||null,this.windowFunc=e.windowFunc||"hann",this.alpha=e.alpha,this.frequencyMin=e.frequencyMin||0,this.frequencyMax=e.frequencyMax||0,this.gainDB=null!==(t=e.gainDB)&&void 0!==t?t:20,this.rangeDB=null!==(s=e.rangeDB)&&void 0!==s?s:80,this.scale=e.scale||"mel",this.numMelFilters=this.fftSamples/2,this.numLogFilters=this.fftSamples/2,this.numBarkFilters=this.fftSamples/2,this.numErbFilters=this.fftSamples/2,e.maxCanvasWidth&&(T.MAX_CANVAS_WIDTH=e.maxCanvasWidth),this.renderThrottleMs=50,this.zoomThreshold=.05,this.createWrapper(),this.createCanvas(),this.useWebWorker&&this.initializeWorker()}initializeWorker(){if("undefined"!=typeof window&&"undefined"!=typeof Worker)try{this.worker=new G,this.worker.onmessage=e=>{const{type:t,id:s,result:i,error:r}=e.data;if("frequenciesResult"===t){const e=this.workerPromises.get(s);e&&(this.workerPromises.delete(s),r?e.reject(new Error(r)):e.resolve(i))}},this.worker.onerror=e=>{console.warn("Spectrogram worker error, falling back to main thread:",e),this.worker=null}}catch(e){console.warn("Failed to initialize worker, falling back to main thread:",e),this.worker=null}else console.warn("Worker not available in this environment, using main thread calculation")}onInit(){this.wrapper||this.createWrapper(),this.canvasContainer||this.createCanvas(),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.throttledRender()))),this.wavesurfer.getDecodedData()&&setTimeout((()=>{this.throttledRender()}),0)}destroy(){this.unAll(),this.wavesurfer&&("function"==typeof this._onReady&&this.wavesurfer.un("ready",this._onReady),"function"==typeof this._onRender&&this.wavesurfer.un("redraw",this._onRender)),this.renderTimeout&&(clearTimeout(this.renderTimeout),this.renderTimeout=null),this.scrollUnsubscribe&&(this.scrollUnsubscribe(),this.scrollUnsubscribe=null),this.pendingBitmaps.clear(),this.worker&&(this.worker.terminate(),this.worker=null),this.cachedFrequencies=null,this.cachedResampledData=null,this.cachedBuffer=null,this.clearCanvases(),this.canvasContainer&&(this.canvasContainer.remove(),this.canvasContainer=null),this.wrapper&&(this.wrapper.remove(),this.wrapper=null),this.labelsEl&&(this.labelsEl.remove(),this.labelsEl=null),this.container=null,this.isRendering=!1,this.lastZoomLevel=0,this.wavesurfer=null,this.util=null,this.options=null,super.destroy()}loadFrequenciesData(t){return e(this,void 0,void 0,(function*(){const e=yield fetch(t);if(!e.ok)throw new Error("Unable to fetch frequencies data");const s=yield e.json();this.drawSpectrogram(s)}))}clearCache(){this.cachedFrequencies=null,this.cachedResampledData=null,this.cachedBuffer=null,this.cachedWidth=0,this.lastZoomLevel=0}createWrapper(){var e,t;this.wrapper=g("div",{style:{display:"block",position:"relative",userSelect:"none"}}),this.options.labels&&(this.labelsEl=g("canvas",{part:"spec-labels",style:{position:"absolute",zIndex:9,width:"55px",height:"100%"}},this.wrapper)),this._onWrapperClick=(e=this.wrapper,t=this.emit.bind(this),s=>{const i=e.getBoundingClientRect(),r=s.clientX-i.left,n=i.width;t("click",r/n)}),this.wrapper.addEventListener("click",this._onWrapperClick)}createCanvas(){this.canvasContainer=g("div",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",zIndex:4}},this.wrapper)}createSingleCanvas(e,t,s){const i=g("canvas",{style:{position:"absolute",left:`${Math.round(s)}px`,top:"0",width:`${e}px`,height:`${t}px`,zIndex:4}});return i.width=Math.round(e),i.height=Math.round(t),this.canvasContainer.appendChild(i),i}clearCanvases(){this.canvases.forEach((e=>e.remove())),this.canvases=[],this.drawnCanvases={}}clearExcessCanvases(){Object.keys(this.drawnCanvases).length>T.MAX_NODES&&this.clearCanvases()}throttledRender(){var e;if(this.renderTimeout&&clearTimeout(this.renderTimeout),this.isRendering)return;const t=(null===(e=this.wavesurfer)||void 0===e?void 0:e.options.minPxPerSec)||0;Math.abs(t-this.lastZoomLevel)/Math.max(t,this.lastZoomLevel,1)<this.zoomThreshold&&this.cachedFrequencies?this.renderTimeout=window.setTimeout((()=>{this.fastRender()}),this.renderThrottleMs):this.renderTimeout=window.setTimeout((()=>{this.render()}),this.renderThrottleMs)}render(){return e(this,void 0,void 0,(function*(){var e,t;if(!this.isRendering){this.isRendering=!0;try{if(this.frequenciesDataUrl)yield this.loadFrequenciesData(this.frequenciesDataUrl);else{const t=null===(e=this.wavesurfer)||void 0===e?void 0:e.getDecodedData();if(t)if(this.cachedBuffer===t&&this.cachedFrequencies)this.drawSpectrogram(this.cachedFrequencies);else{const e=yield this.getFrequencies(t);this.cachedFrequencies=e,this.cachedBuffer=t,this.drawSpectrogram(e)}}this.lastZoomLevel=(null===(t=this.wavesurfer)||void 0===t?void 0:t.options.minPxPerSec)||0}finally{this.isRendering=!1}}}))}fastRender(){var e;if(!this.isRendering&&this.cachedFrequencies){this.isRendering=!0;try{this.drawSpectrogram(this.cachedFrequencies),this.lastZoomLevel=(null===(e=this.wavesurfer)||void 0===e?void 0:e.options.minPxPerSec)||0}finally{this.isRendering=!1}}}drawSpectrogram(e){var t,s,i;isNaN(e[0][0])||(e=[e]),this.clearCanvases();const r=this.height*e.length;this.wrapper.style.height=r+"px";const n=this.getWidth(),a=Math.min(T.MAX_CANVAS_WIDTH,n);if(0===n||0===r)return;const o=Math.ceil(n/a);let l;const h=(null===(t=e[0])||void 0===t?void 0:t.length)||0;n!==h?this.cachedResampledData&&this.cachedWidth===n?l=this.cachedResampledData:(l=this.efficientResample(e,n),this.cachedResampledData=l,this.cachedWidth=n):l=e;const c=(null===(s=this.buffer)||void 0===s?void 0:s.sampleRate)?this.buffer.sampleRate/2:(this.options.sampleRate||0)/2,d=this.frequencyMin,u=this.frequencyMax,p=u>c,m=p?this.colorMap[this.colorMap.length-1]:null,f=e=>{if(e<0||e>=o)return;if(this.drawnCanvases[e])return;this.drawnCanvases[e]=!0;const t=e*a,s=Math.min(a,n-t);if(s<=0)return;const i=this.createSingleCanvas(s,r,t);this.canvases.push(i);const h=i.getContext("2d");if(h){p&&m&&(h.fillStyle=`rgba(${255*m[0]}, ${255*m[1]}, ${255*m[2]}, ${m[3]})`,h.fillRect(0,0,s,r));for(let e=0;e<l.length;e++)this.drawSpectrogramSegment(l[e],h,s,this.height,e*this.height,t,n,c,d,u)}};if(this.isScrollable=n>this.getWrapperWidth(),this.scrollUnsubscribe&&(this.scrollUnsubscribe(),this.scrollUnsubscribe=null),!this.isScrollable||o<=3)for(let e=0;e<o;e++)f(e);else{const e=()=>{var e;const t=null===(e=this.wavesurfer)||void 0===e?void 0:e.getWrapper();if(!t)return;const s=t.scrollLeft||0,i=t.clientWidth||0,r=Math.max(0,s-.5*i),a=Math.min(n,s+1.5*i),l=Math.floor(r/n*o),h=Math.min(Math.ceil(a/n*o),o-1);Object.keys(this.drawnCanvases).length>T.MAX_NODES&&this.clearExcessCanvases();for(let e=l;e<=h;e++)f(e)};e();let t=null;const s=()=>{t&&clearTimeout(t),t=window.setTimeout(e,16)},r=null===(i=this.wavesurfer)||void 0===i?void 0:i.getWrapper();r&&(r.addEventListener("scroll",s,{passive:!0}),this.scrollUnsubscribe=()=>{r.removeEventListener("scroll",s),t&&clearTimeout(t)})}this.options.labels&&this.loadLabels(this.options.labelsBackground,"12px","12px","",this.options.labelsColor,this.options.labelsHzColor||this.options.labelsColor,"center","#specLabels",e.length),this.emit("ready")}drawSpectrogramSegment(e,t,s,i,r,n,a,o,l,h){const d=e[0].length,u=Math.floor(n/a*e.length),p=Math.min(Math.ceil((n+s)/a*e.length),e.length),m=e.slice(u,p);if(0===m.length)return;const f=m.length,b=new ImageData(f,d),y=b.data;this.fillImageDataQuality(y,m,f,d);const M=c(l,this.scale)/c(o,this.scale),w=c(h,this.scale)/c(o,this.scale),v=Math.min(1,w),g=createImageBitmap(b,0,Math.round(d*(1-v)),f,Math.round(d*(v-M)));this.pendingBitmaps.add(g),g.then((e=>{if(this.pendingBitmaps.delete(g),t.canvas.parentNode){const n=i*v/w,a=r+i*(1-v/w);t.drawImage(e,0,a,s,n),"close"in e&&e.close()}})).catch((e=>{this.pendingBitmaps.delete(g)}))}getWidth(){return this.wavesurfer.getWrapper().offsetWidth}getWrapperWidth(){var e,t;return(null===(t=null===(e=this.wavesurfer)||void 0===e?void 0:e.getWrapper())||void 0===t?void 0:t.clientWidth)||0}calculateFrequenciesWithWorker(t){return e(this,void 0,void 0,(function*(){var e,s;if(!this.worker)throw new Error("Worker not available");const i=this.fftSamples,r=(null!==(e=this.options.splitChannels)&&void 0!==e?e:null===(s=this.wavesurfer)||void 0===s?void 0:s.options.splitChannels)?t.numberOfChannels:1;let n=this.noverlap;if(!n){const e=this.getWidth(),s=t.length/e;n=Math.max(0,Math.round(i-s))}const a=[];for(let e=0;e<r;e++)a.push(t.getChannelData(e));const o=`${Date.now()}_${Math.random()}`,l=new Promise(((e,t)=>{this.workerPromises.set(o,{resolve:e,reject:t}),setTimeout((()=>{this.workerPromises.has(o)&&(this.workerPromises.delete(o),t(new Error("Worker timeout")))}),3e4)}));return this.worker.postMessage({type:"calculateFrequencies",id:o,audioData:a,options:{startTime:0,endTime:t.duration,sampleRate:t.sampleRate,fftSamples:this.fftSamples,windowFunc:this.windowFunc,alpha:this.alpha,noverlap:n,scale:this.scale,gainDB:this.gainDB,rangeDB:this.rangeDB,splitChannels:this.options.splitChannels||!1}}),l}))}getFrequencies(t){return e(this,void 0,void 0,(function*(){var e,c;if(this.frequencyMax=this.frequencyMax||t.sampleRate/2,this.buffer=t,!t)return[];if(this.useWebWorker&&this.worker)try{return yield this.calculateFrequenciesWithWorker(t)}catch(e){console.warn("Worker calculation failed, falling back to main thread:",e)}const p=this.fftSamples,m=(null!==(e=this.options.splitChannels)&&void 0!==e?e:null===(c=this.wavesurfer)||void 0===c?void 0:c.options.splitChannels)?t.numberOfChannels:1,f=t.sampleRate,b=[];let M=this.noverlap;if(!M){const e=this.getWidth(),s=t.length/e;M=Math.max(0,Math.round(p-s))}let w=M||Math.max(0,Math.round(.5*p));const v=.5*p;w=Math.min(w,v);const g=Math.max(64,.25*p),W=Math.max(g,p-w),Z=new y(p,f,this.windowFunc,this.alpha),S=this.fftSamples/2,x=function(e,t,c,u){switch(e){case"mel":return d(t,c,u,s,i);case"logarithmic":return d(t,c,u,r,n);case"bark":return d(t,c,u,a,o);case"erb":return d(t,c,u,l,h);default:return null}}(this.scale,S,this.fftSamples,f);for(let e=0;e<m;e++){const s=t.getChannelData(e),i=[];for(let e=0;e+p<s.length;e+=W){const t=s.slice(e,e+p);let r=Z.calculateSpectrum(t);x&&(r=u(r,x));const n=new Uint8Array(r.length),a=this.gainDB+this.rangeDB;for(let e=0;e<r.length;e++){const t=r[e]>1e-12?r[e]:1e-12,s=20*Math.log10(t);s<-a?n[e]=0:s>-this.gainDB?n[e]=255:n[e]=Math.round((s+this.gainDB)/this.rangeDB*255)}i.push(n)}b.push(i)}return b}))}loadLabels(e,t,s,i,r,n,a,o,l){e=e||"rgba(68,68,68,0)",t=t||"12px",s=s||"12px",i=i||"Helvetica",r=r||"#fff",n=n||"#fff",a=a||"center";const h=this.height||512,c=h/256*5;this.frequencyMin;this.frequencyMax;const d=this.labelsEl.getContext("2d"),u=window.devicePixelRatio;if(this.labelsEl.height=this.height*l*u,this.labelsEl.width=55*u,d.scale(u,u),d)for(let o=0;o<l;o++){let l;for(d.fillStyle=e,d.fillRect(0,o*h,55,(1+o)*h),d.fill(),l=0;l<=c;l++){d.textAlign=a,d.textBaseline="middle";const e=b(l,c,this.frequencyMin,this.frequencyMax,this.scale),u=m(e),p=f(e),y=16;let M=(1+o)*h-l/c*h;M=Math.min(Math.max(M,o*h+10),(1+o)*h-10),d.fillStyle=n,d.font=s+" "+i,d.fillText(p,y+24,M),d.fillStyle=r,d.font=t+" "+i,d.fillText(u,y,M)}}}efficientResample(e,t){return e.map((e=>this.resampleChannel(e,t)))}resampleChannel(e,t){var s;const i=e.length,r=(null===(s=e[0])||void 0===s?void 0:s.length)||0;if(i===t||0===t)return e;const n=i/t,a=new Array(t);if(n>=1)for(let s=0;s<t;s++){const t=Math.floor(s*n),o=Math.min(Math.ceil((s+1)*n),i),l=o-t,h=new Uint8Array(r);if(1===l)h.set(e[t]);else for(let s=0;s<r;s++){let i=0;for(let r=t;r<o;r++)i+=e[r][s];h[s]=Math.round(i/l)}a[s]=h}else for(let s=0;s<t;s++){const t=s*n,o=Math.floor(t),l=Math.min(o+1,i-1),h=t-o,c=new Uint8Array(r);if(0===h||o===l)c.set(e[o]);else{const t=e[o],s=e[l],i=1-h;for(let e=0;e<r;e++)c[e]=Math.round(t[e]*i+s[e]*h)}a[s]=c}return a}fillImageDataQuality(e,t,s,i){const r=this.colorMap;for(let n=0;n<s;n++){const a=t[n];for(let t=0;t<i;t++){const o=r[a[t]],l=4*((i-t-1)*s+n);e[l]=255*o[0],e[l+1]=255*o[1],e[l+2]=255*o[2],e[l+3]=255*o[3]}}}}T.MAX_CANVAS_WIDTH=3e4,T.MAX_NODES=10;export{T as default};
@@ -1 +1 @@
1
- function t(t,e,s,r){return new(s||(s=Promise))((function(i,a){function n(t){try{o(r.next(t))}catch(t){a(t)}}function h(t){try{o(r.throw(t))}catch(t){a(t)}}function o(t){var e;t.done?i(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(n,h)}o((r=r.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 r(t,e){const s=e.xmlns?document.createElementNS(e.xmlns,t):document.createElement(t);for(const[t,i]of Object.entries(e))if("children"===t&&i)for(const[t,e]of Object.entries(i))e instanceof Node?s.appendChild(e):"string"==typeof e?s.appendChild(document.createTextNode(e)):s.appendChild(r(t,e));else"style"===t?Object.assign(s.style,i):"textContent"===t?s.textContent=i:s.setAttribute(t,i.toString());return s}function i(t,e,s){const i=r(t,e||{});return null==s||s.appendChild(i),i}function a(t,e,s,r){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(i=0;i<t;i++)this.windowValues[i]=2/(t-1)*((t-1)/2-Math.abs(i-(t-1)/2));break;case"bartlettHann":for(i=0;i<t;i++)this.windowValues[i]=.62-.48*Math.abs(i/(t-1)-.5)-.38*Math.cos(2*Math.PI*i/(t-1));break;case"blackman":for(r=r||.16,i=0;i<t;i++)this.windowValues[i]=(1-r)/2-.5*Math.cos(2*Math.PI*i/(t-1))+r/2*Math.cos(4*Math.PI*i/(t-1));break;case"cosine":for(i=0;i<t;i++)this.windowValues[i]=Math.cos(Math.PI*i/(t-1)-Math.PI/2);break;case"gauss":for(r=r||.25,i=0;i<t;i++)this.windowValues[i]=Math.pow(Math.E,-.5*Math.pow((i-(t-1)/2)/(r*(t-1)/2),2));break;case"hamming":for(i=0;i<t;i++)this.windowValues[i]=.54-.46*Math.cos(2*Math.PI*i/(t-1));break;case"hann":case void 0:for(i=0;i<t;i++)this.windowValues[i]=.5*(1-Math.cos(2*Math.PI*i/(t-1)));break;case"lanczoz":for(i=0;i<t;i++)this.windowValues[i]=Math.sin(Math.PI*(2*i/(t-1)-1))/(Math.PI*(2*i/(t-1)-1));break;case"rectangular":for(i=0;i<t;i++)this.windowValues[i]=1;break;case"triangular":for(i=0;i<t;i++)this.windowValues[i]=2/t*(t/2-Math.abs(i-(t-1)/2));break;default:throw Error("No such window function '"+s+"'")}for(var i,a=1,n=t>>1;a<t;){for(i=0;i<a;i++)this.reverseTable[i+a]=this.reverseTable[i]+n;a<<=1,n>>=1}for(i=0;i<t;i++)this.sinTable[i]=Math.sin(-Math.PI/i),this.cosTable[i]=Math.cos(-Math.PI/i);this.calculateSpectrum=function(t){var e,s,r,i=this.bufferSize,a=this.cosTable,n=this.sinTable,h=this.reverseTable,o=new Float32Array(i),l=new Float32Array(i),c=2/this.bufferSize,u=Math.sqrt,f=new Float32Array(i/2),p=Math.floor(Math.log(i)/Math.LN2);if(Math.pow(2,p)!==i)throw"Invalid buffer size, must be a power of 2.";if(i!==t.length)throw"Supplied buffer is not the same size as defined FFT. FFT Size: "+i+" Buffer Size: "+t.length;for(var d,w,g,b,M,m,v,y,T=1,k=0;k<i;k++)o[k]=t[h[k]]*this.windowValues[h[k]],l[k]=0;for(;T<i;){d=a[T],w=n[T],g=1,b=0;for(var z=0;z<T;z++){for(k=z;k<i;)m=g*o[M=k+T]-b*l[M],v=g*l[M]+b*o[M],o[M]=o[k]-m,l[M]=l[k]-v,o[k]+=m,l[k]+=v,k+=T<<1;g=(y=g)*d-b*w,b=y*w+b*d}T<<=1}k=0;for(var F=i/2;k<F;k++)(r=c*u((e=o[k])*e+(s=l[k])*s))>this.peak&&(this.peakBand=k,this.peak=r),f[k]=r;return f}}const n=1e3*Math.log(10)/107.939;class h extends s{static create(t){return new h(t||{})}constructor(t){var e,s;if(super(t),this.frequenciesDataUrl=t.frequenciesDataUrl,this.container="string"==typeof t.container?document.querySelector(t.container):t.container,t.colorMap&&"string"!=typeof 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 switch(this.colorMap=t.colorMap||"roseus",this.colorMap){case"gray":this.colorMap=[];for(let t=0;t<256;t++){const e=(255-t)/256;this.colorMap.push([e,e,e,1])}break;case"igray":this.colorMap=[];for(let t=0;t<256;t++){const e=t/256;this.colorMap.push([e,e,e,1])}break;case"roseus":this.colorMap=[[.004528,.004341,.004307,1],[.005625,.006156,.00601,1],[.006628,.008293,.008161,1],[.007551,.010738,.01079,1],[.008382,.013482,.013941,1],[.009111,.01652,.017662,1],[.009727,.019846,.022009,1],[.010223,.023452,.027035,1],[.010593,.027331,.032799,1],[.010833,.031475,.039361,1],[.010941,.035875,.046415,1],[.010918,.04052,.053597,1],[.010768,.045158,.060914,1],[.010492,.049708,.068367,1],[.010098,.054171,.075954,1],[.009594,.058549,.083672,1],[.008989,.06284,.091521,1],[.008297,.067046,.099499,1],[.00753,.071165,.107603,1],[.006704,.075196,.11583,1],[.005838,.07914,.124178,1],[.004949,.082994,.132643,1],[.004062,.086758,.141223,1],[.003198,.09043,.149913,1],[.002382,.09401,.158711,1],[.001643,.097494,.167612,1],[.001009,.100883,.176612,1],[514e-6,.104174,.185704,1],[187e-6,.107366,.194886,1],[66e-6,.110457,.204151,1],[186e-6,.113445,.213496,1],[587e-6,.116329,.222914,1],[.001309,.119106,.232397,1],[.002394,.121776,.241942,1],[.003886,.124336,.251542,1],[.005831,.126784,.261189,1],[.008276,.12912,.270876,1],[.011268,.131342,.280598,1],[.014859,.133447,.290345,1],[.0191,.135435,.300111,1],[.024043,.137305,.309888,1],[.029742,.139054,.319669,1],[.036252,.140683,.329441,1],[.043507,.142189,.339203,1],[.050922,.143571,.348942,1],[.058432,.144831,.358649,1],[.066041,.145965,.368319,1],[.073744,.146974,.377938,1],[.081541,.147858,.387501,1],[.089431,.148616,.396998,1],[.097411,.149248,.406419,1],[.105479,.149754,.415755,1],[.113634,.150134,.424998,1],[.121873,.150389,.434139,1],[.130192,.150521,.443167,1],[.138591,.150528,.452075,1],[.147065,.150413,.460852,1],[.155614,.150175,.469493,1],[.164232,.149818,.477985,1],[.172917,.149343,.486322,1],[.181666,.148751,.494494,1],[.190476,.148046,.502493,1],[.199344,.147229,.510313,1],[.208267,.146302,.517944,1],[.217242,.145267,.52538,1],[.226264,.144131,.532613,1],[.235331,.142894,.539635,1],[.24444,.141559,.546442,1],[.253587,.140131,.553026,1],[.262769,.138615,.559381,1],[.271981,.137016,.5655,1],[.281222,.135335,.571381,1],[.290487,.133581,.577017,1],[.299774,.131757,.582404,1],[.30908,.129867,.587538,1],[.318399,.12792,.592415,1],[.32773,.125921,.597032,1],[.337069,.123877,.601385,1],[.346413,.121793,.605474,1],[.355758,.119678,.609295,1],[.365102,.11754,.612846,1],[.374443,.115386,.616127,1],[.383774,.113226,.619138,1],[.393096,.111066,.621876,1],[.402404,.108918,.624343,1],[.411694,.106794,.62654,1],[.420967,.104698,.628466,1],[.430217,.102645,.630123,1],[.439442,.100647,.631513,1],[.448637,.098717,.632638,1],[.457805,.096861,.633499,1],[.46694,.095095,.6341,1],[.47604,.093433,.634443,1],[.485102,.091885,.634532,1],[.494125,.090466,.63437,1],[.503104,.08919,.633962,1],[.512041,.088067,.633311,1],[.520931,.087108,.63242,1],[.529773,.086329,.631297,1],[.538564,.085738,.629944,1],[.547302,.085346,.628367,1],[.555986,.085162,.626572,1],[.564615,.08519,.624563,1],[.573187,.085439,.622345,1],[.581698,.085913,.619926,1],[.590149,.086615,.617311,1],[.598538,.087543,.614503,1],[.606862,.0887,.611511,1],[.61512,.090084,.608343,1],[.623312,.09169,.605001,1],[.631438,.093511,.601489,1],[.639492,.095546,.597821,1],[.647476,.097787,.593999,1],[.655389,.100226,.590028,1],[.66323,.102856,.585914,1],[.670995,.105669,.581667,1],[.678686,.108658,.577291,1],[.686302,.111813,.57279,1],[.69384,.115129,.568175,1],[.7013,.118597,.563449,1],[.708682,.122209,.558616,1],[.715984,.125959,.553687,1],[.723206,.12984,.548666,1],[.730346,.133846,.543558,1],[.737406,.13797,.538366,1],[.744382,.142209,.533101,1],[.751274,.146556,.527767,1],[.758082,.151008,.522369,1],[.764805,.155559,.516912,1],[.771443,.160206,.511402,1],[.777995,.164946,.505845,1],[.784459,.169774,.500246,1],[.790836,.174689,.494607,1],[.797125,.179688,.488935,1],[.803325,.184767,.483238,1],[.809435,.189925,.477518,1],[.815455,.19516,.471781,1],[.821384,.200471,.466028,1],[.827222,.205854,.460267,1],[.832968,.211308,.454505,1],[.838621,.216834,.448738,1],[.844181,.222428,.442979,1],[.849647,.22809,.43723,1],[.855019,.233819,.431491,1],[.860295,.239613,.425771,1],[.865475,.245471,.420074,1],[.870558,.251393,.414403,1],[.875545,.25738,.408759,1],[.880433,.263427,.403152,1],[.885223,.269535,.397585,1],[.889913,.275705,.392058,1],[.894503,.281934,.386578,1],[.898993,.288222,.381152,1],[.903381,.294569,.375781,1],[.907667,.300974,.370469,1],[.911849,.307435,.365223,1],[.915928,.313953,.360048,1],[.919902,.320527,.354948,1],[.923771,.327155,.349928,1],[.927533,.333838,.344994,1],[.931188,.340576,.340149,1],[.934736,.347366,.335403,1],[.938175,.354207,.330762,1],[.941504,.361101,.326229,1],[.944723,.368045,.321814,1],[.947831,.375039,.317523,1],[.950826,.382083,.313364,1],[.953709,.389175,.309345,1],[.956478,.396314,.305477,1],[.959133,.403499,.301766,1],[.961671,.410731,.298221,1],[.964093,.418008,.294853,1],[.966399,.425327,.291676,1],[.968586,.43269,.288696,1],[.970654,.440095,.285926,1],[.972603,.44754,.28338,1],[.974431,.455025,.281067,1],[.976139,.462547,.279003,1],[.977725,.470107,.277198,1],[.979188,.477703,.275666,1],[.980529,.485332,.274422,1],[.981747,.492995,.273476,1],[.98284,.50069,.272842,1],[.983808,.508415,.272532,1],[.984653,.516168,.27256,1],[.985373,.523948,.272937,1],[.985966,.531754,.273673,1],[.986436,.539582,.274779,1],[.98678,.547434,.276264,1],[.986998,.555305,.278135,1],[.987091,.563195,.280401,1],[.987061,.5711,.283066,1],[.986907,.579019,.286137,1],[.986629,.58695,.289615,1],[.986229,.594891,.293503,1],[.985709,.602839,.297802,1],[.985069,.610792,.302512,1],[.98431,.618748,.307632,1],[.983435,.626704,.313159,1],[.982445,.634657,.319089,1],[.981341,.642606,.32542,1],[.98013,.650546,.332144,1],[.978812,.658475,.339257,1],[.977392,.666391,.346753,1],[.97587,.67429,.354625,1],[.974252,.68217,.362865,1],[.972545,.690026,.371466,1],[.97075,.697856,.380419,1],[.968873,.705658,.389718,1],[.966921,.713426,.399353,1],[.964901,.721157,.409313,1],[.962815,.728851,.419594,1],[.960677,.7365,.430181,1],[.95849,.744103,.44107,1],[.956263,.751656,.452248,1],[.954009,.759153,.463702,1],[.951732,.766595,.475429,1],[.949445,.773974,.487414,1],[.947158,.781289,.499647,1],[.944885,.788535,.512116,1],[.942634,.795709,.524811,1],[.940423,.802807,.537717,1],[.938261,.809825,.550825,1],[.936163,.81676,.564121,1],[.934146,.823608,.577591,1],[.932224,.830366,.59122,1],[.930412,.837031,.604997,1],[.928727,.843599,.618904,1],[.927187,.850066,.632926,1],[.925809,.856432,.647047,1],[.92461,.862691,.661249,1],[.923607,.868843,.675517,1],[.92282,.874884,.689832,1],[.922265,.880812,.704174,1],[.921962,.886626,.718523,1],[.92193,.892323,.732859,1],[.922183,.897903,.747163,1],[.922741,.903364,.76141,1],[.92362,.908706,.77558,1],[.924837,.913928,.789648,1],[.926405,.919031,.80359,1],[.92834,.924015,.817381,1],[.930655,.928881,.830995,1],[.93336,.933631,.844405,1],[.936466,.938267,.857583,1],[.939982,.942791,.870499,1],[.943914,.947207,.883122,1],[.948267,.951519,.895421,1],[.953044,.955732,.907359,1],[.958246,.959852,.918901,1],[.963869,.963887,.930004,1],[.969909,.967845,.940623,1],[.976355,.971737,.950704,1],[.983195,.97558,.960181,1],[.990402,.979395,.968966,1],[.99793,.983217,.97692,1]];break;default:throw Error("No such colormap '"+this.colorMap+"'")}this.fftSamples=t.fftSamples||512,this.height=t.height||200,this.noverlap=t.noverlap||null,this.windowFunc=t.windowFunc||"hann",this.alpha=t.alpha,this.frequencyMin=t.frequencyMin||0,this.frequencyMax=t.frequencyMax||0,this.gainDB=null!==(e=t.gainDB)&&void 0!==e?e:20,this.rangeDB=null!==(s=t.rangeDB)&&void 0!==s?s:80,this.scale=t.scale||"mel",this.numMelFilters=this.fftSamples/2,this.numLogFilters=this.fftSamples/2,this.numBarkFilters=this.fftSamples/2,this.numErbFilters=this.fftSamples/2,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("decode",(()=>{this.buffer=void 0,this.frequencies=void 0})),this.wavesurfer.on("redraw",(()=>this.render())))}destroy(){this.unAll(),this.wavesurfer.un("ready",this._onReady),this.wavesurfer.un("redraw",this._onRender),this.buffer=void 0,this.frequencies=void 0,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.frequencies=s,this.drawSpectrogram(s)}))}createWrapper(){this.wrapper=i("div",{style:{display:"block",position:"relative",userSelect:"none"}}),this.options.labels&&(this.labelsEl=i("canvas",{part:"spec-labels",style:{position:"absolute",zIndex:9,width:"55px",height:"100%"}},this.wrapper)),this.wrapper.addEventListener("click",this._onWrapperClick)}createCanvas(){this.canvas=i("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.frequencies&&this.buffer===e||(this.frequencies=this.getFrequencies(e)),this.drawSpectrogram(this.frequencies))}}drawSpectrogram(t){isNaN(t[0][0])||(t=[t]),this.wrapper.style.height=this.height*t.length+"px",this.canvas.width=this.getWidth(),this.canvas.height=this.height*t.length;const e=this.spectrCc,s=this.height,r=this.getWidth(),i=this.buffer.sampleRate/2,a=this.frequencyMin,n=this.frequencyMax;if(e){if(n>i){const i=this.colorMap[this.colorMap.length-1];e.fillStyle=`rgba(${i[0]}, ${i[1]}, ${i[2]}, ${i[3]})`,e.fillRect(0,0,r,s*t.length)}for(let h=0;h<t.length;h++){const o=this.resample(t[h]),l=o[0].length,c=new ImageData(r,l);for(let t=0;t<o.length;t++)for(let e=0;e<o[t].length;e++){const s=this.colorMap[o[t][e]],i=4*((l-e-1)*r+t);c.data[i]=255*s[0],c.data[i+1]=255*s[1],c.data[i+2]=255*s[2],c.data[i+3]=255*s[3]}const u=this.hzToScale(a)/this.hzToScale(i),f=this.hzToScale(n)/this.hzToScale(i),p=Math.min(1,f);createImageBitmap(c,0,Math.round(l*(1-p)),r,Math.round(l*(p-u))).then((t=>{e.drawImage(t,0,s*(h+1-p/f),r,s*p/f)}))}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")}}createFilterBank(t,e,s,r){const i=s(0),a=s(e/2),n=Array.from({length:t},(()=>Array(this.fftSamples/2+1).fill(0))),h=e/this.fftSamples;for(let e=0;e<t;e++){let s=r(i+e/t*(a-i)),o=Math.floor(s/h),l=o*h,c=(s-l)/((o+1)*h-l);n[e][o]=1-c,n[e][o+1]=c}return n}hzToMel(t){return 2595*Math.log10(1+t/700)}melToHz(t){return 700*(Math.pow(10,t/2595)-1)}createMelFilterBank(t,e){return this.createFilterBank(t,e,this.hzToMel,this.melToHz)}hzToLog(t){return Math.log10(Math.max(1,t))}logToHz(t){return Math.pow(10,t)}createLogFilterBank(t,e){return this.createFilterBank(t,e,this.hzToLog,this.logToHz)}hzToBark(t){let e=26.81*t/(1960+t)-.53;return e<2&&(e+=.15*(2-e)),e>20.1&&(e+=.22*(e-20.1)),e}barkToHz(t){return t<2&&(t=(t-.3)/.85),t>20.1&&(t=(t+4.422)/1.22),(t+.53)/(26.28-t)*1960}createBarkFilterBank(t,e){return this.createFilterBank(t,e,this.hzToBark,this.barkToHz)}hzToErb(t){return n*Math.log10(1+.00437*t)}erbToHz(t){return(Math.pow(10,t/n)-1)/.00437}createErbFilterBank(t,e){return this.createFilterBank(t,e,this.hzToErb,this.erbToHz)}hzToScale(t){switch(this.scale){case"mel":return this.hzToMel(t);case"logarithmic":return this.hzToLog(t);case"bark":return this.hzToBark(t);case"erb":return this.hzToErb(t)}return t}scaleToHz(t){switch(this.scale){case"mel":return this.melToHz(t);case"logarithmic":return this.logToHz(t);case"bark":return this.barkToHz(t);case"erb":return this.erbToHz(t)}return t}applyFilterBank(t,e){const s=e.length,r=Float32Array.from({length:s},(()=>0));for(let i=0;i<s;i++)for(let s=0;s<t.length;s++)r[i]+=t[s]*e[i][s];return r}getWidth(){return this.wavesurfer.getWrapper().offsetWidth}getFrequencies(t){var e,s;const r=this.fftSamples,i=(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,h=[];let o=this.noverlap;if(!o){const e=t.length/this.canvas.width;o=Math.max(0,Math.round(r-e))}const l=new a(r,n,this.windowFunc,this.alpha);let c;switch(this.scale){case"mel":c=this.createFilterBank(this.numMelFilters,n,this.hzToMel,this.melToHz);break;case"logarithmic":c=this.createFilterBank(this.numLogFilters,n,this.hzToLog,this.logToHz);break;case"bark":c=this.createFilterBank(this.numBarkFilters,n,this.hzToBark,this.barkToHz);break;case"erb":c=this.createFilterBank(this.numErbFilters,n,this.hzToErb,this.erbToHz)}for(let e=0;e<i;e++){const s=t.getChannelData(e),i=[];let a=0;for(;a+r<s.length;){const t=s.slice(a,a+r),e=new Uint8Array(r/2);let n=l.calculateSpectrum(t);c&&(n=this.applyFilterBank(n,c));for(let t=0;t<r/2;t++){const s=n[t]>1e-12?n[t]:1e-12,r=20*Math.log10(s);r<-this.gainDB-this.rangeDB?e[t]=0:r>-this.gainDB?e[t]=255:e[t]=(r+this.gainDB)/this.rangeDB*255+256}i.push(e),a+=r-o}h.push(i)}return this.frequencies=h,h}freqType(t){return t>=1e3?(t/1e3).toFixed(1):Math.round(t)}unitType(t){return t>=1e3?"kHz":"Hz"}getLabelFrequency(t,e){const s=this.hzToScale(this.frequencyMin),r=this.hzToScale(this.frequencyMax);return this.scaleToHz(s+t/e*(r-s))}loadLabels(t,e,s,r,i,a,n,h,o){t=t||"rgba(68,68,68,0)",e=e||"12px",s=s||"12px",r=r||"Helvetica",i=i||"#fff",a=a||"#fff",n=n||"center";const l=this.height||512,c=l/256*5;this.frequencyMin;this.frequencyMax;const u=this.labelsEl.getContext("2d"),f=window.devicePixelRatio;if(this.labelsEl.height=this.height*o*f,this.labelsEl.width=55*f,u.scale(f,f),u)for(let h=0;h<o;h++){let o;for(u.fillStyle=t,u.fillRect(0,h*l,55,(1+h)*l),u.fill(),o=0;o<=c;o++){u.textAlign=n,u.textBaseline="middle";const t=this.getLabelFrequency(o,c),f=this.freqType(t),p=this.unitType(t),d=16;let w=(1+h)*l-o/c*l;w=Math.min(Math.max(w,h*l+10),(1+h)*l-10),u.fillStyle=a,u.font=s+" "+r,u.fillText(p,d+24,w),u.fillStyle=i,u.font=e+" "+r,u.fillText(f,d,w)}}}resample(t){const e=this.getWidth(),s=[],r=1/t.length,i=1/e;let a;for(a=0;a<e;a++){const e=new Array(t[0].length);let n;for(n=0;n<t.length;n++){const s=n*r,h=s+r,o=a*i,l=o+i,c=Math.max(0,Math.min(h,l)-Math.max(s,o));let u;if(c>0)for(u=0;u<t[0].length;u++)null==e[u]&&(e[u]=0),e[u]+=c/i*t[n][u]}const h=new Uint8Array(t[0].length);let o;for(o=0;o<t[0].length;o++)h[o]=e[o];s.push(h)}return s}}export{h as default};
1
+ function e(e,t,s,i){return new(s||(s=Promise))((function(r,n){function a(e){try{l(i.next(e))}catch(e){n(e)}}function o(e){try{l(i.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(a,o)}l((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t=1e3*Math.log(10)/107.939;function s(e){return 2595*Math.log10(1+e/700)}function i(e){return 700*(Math.pow(10,e/2595)-1)}function r(e){return Math.log10(Math.max(1,e))}function n(e){return Math.pow(10,e)}function a(e){let t=26.81*e/(1960+e)-.53;return t<2&&(t+=.15*(2-t)),t>20.1&&(t+=.22*(t-20.1)),t}function o(e){return e<2&&(e=(e-.3)/.85),e>20.1&&(e=(e+4.422)/1.22),(e+.53)/(26.28-e)*1960}function l(e){return t*Math.log10(1+.00437*e)}function h(e){return(Math.pow(10,e/t)-1)/.00437}function c(e,t){switch(t){case"mel":return s(e);case"logarithmic":return r(e);case"bark":return a(e);case"erb":return l(e);default:return e}}function d(e,t,s,i,r){const n=i(0),a=i(s/2),o=Array.from({length:e},(()=>Array(t/2+1).fill(0))),l=s/t;for(let t=0;t<e;t++){let s=r(n+t/e*(a-n)),i=Math.floor(s/l),h=i*l,c=(s-h)/((i+1)*l-h);o[t][i]=1-c,o[t][i+1]=c}return o}function u(e,t){const s=t.length,i=Float32Array.from({length:s},(()=>0));for(let r=0;r<s;r++)for(let s=0;s<e.length;s++)i[r]+=e[s]*t[r][s];return i}const p={gray:()=>{const e=[];for(let t=0;t<256;t++){const s=(255-t)/256;e.push([s,s,s,1])}return e},igray:()=>{const e=[];for(let t=0;t<256;t++){const s=t/256;e.push([s,s,s,1])}return e},roseus:()=>[[.004528,.004341,.004307,1],[.005625,.006156,.00601,1],[.006628,.008293,.008161,1],[.007551,.010738,.01079,1],[.008382,.013482,.013941,1],[.009111,.01652,.017662,1],[.009727,.019846,.022009,1],[.010223,.023452,.027035,1],[.010593,.027331,.032799,1],[.010833,.031475,.039361,1],[.010941,.035875,.046415,1],[.010918,.04052,.053597,1],[.010768,.045158,.060914,1],[.010492,.049708,.068367,1],[.010098,.054171,.075954,1],[.009594,.058549,.083672,1],[.008989,.06284,.091521,1],[.008297,.067046,.099499,1],[.00753,.071165,.107603,1],[.006704,.075196,.11583,1],[.005838,.07914,.124178,1],[.004949,.082994,.132643,1],[.004062,.086758,.141223,1],[.003198,.09043,.149913,1],[.002382,.09401,.158711,1],[.001643,.097494,.167612,1],[.001009,.100883,.176612,1],[514e-6,.104174,.185704,1],[187e-6,.107366,.194886,1],[66e-6,.110457,.204151,1],[186e-6,.113445,.213496,1],[587e-6,.116329,.222914,1],[.001309,.119106,.232397,1],[.002394,.121776,.241942,1],[.003886,.124336,.251542,1],[.005831,.126784,.261189,1],[.008276,.12912,.270876,1],[.011268,.131342,.280598,1],[.014859,.133447,.290345,1],[.0191,.135435,.300111,1],[.024043,.137305,.309888,1],[.029742,.139054,.319669,1],[.036252,.140683,.329441,1],[.043507,.142189,.339203,1],[.050922,.143571,.348942,1],[.058432,.144831,.358649,1],[.066041,.145965,.368319,1],[.073744,.146974,.377938,1],[.081541,.147858,.387501,1],[.089431,.148616,.396998,1],[.097411,.149248,.406419,1],[.105479,.149754,.415755,1],[.113634,.150134,.424998,1],[.121873,.150389,.434139,1],[.130192,.150521,.443167,1],[.138591,.150528,.452075,1],[.147065,.150413,.460852,1],[.155614,.150175,.469493,1],[.164232,.149818,.477985,1],[.172917,.149343,.486322,1],[.181666,.148751,.494494,1],[.190476,.148046,.502493,1],[.199344,.147229,.510313,1],[.208267,.146302,.517944,1],[.217242,.145267,.52538,1],[.226264,.144131,.532613,1],[.235331,.142894,.539635,1],[.24444,.141559,.546442,1],[.253587,.140131,.553026,1],[.262769,.138615,.559381,1],[.271981,.137016,.5655,1],[.281222,.135335,.571381,1],[.290487,.133581,.577017,1],[.299774,.131757,.582404,1],[.30908,.129867,.587538,1],[.318399,.12792,.592415,1],[.32773,.125921,.597032,1],[.337069,.123877,.601385,1],[.346413,.121793,.605474,1],[.355758,.119678,.609295,1],[.365102,.11754,.612846,1],[.374443,.115386,.616127,1],[.383774,.113226,.619138,1],[.393096,.111066,.621876,1],[.402404,.108918,.624343,1],[.411694,.106794,.62654,1],[.420967,.104698,.628466,1],[.430217,.102645,.630123,1],[.439442,.100647,.631513,1],[.448637,.098717,.632638,1],[.457805,.096861,.633499,1],[.46694,.095095,.6341,1],[.47604,.093433,.634443,1],[.485102,.091885,.634532,1],[.494125,.090466,.63437,1],[.503104,.08919,.633962,1],[.512041,.088067,.633311,1],[.520931,.087108,.63242,1],[.529773,.086329,.631297,1],[.538564,.085738,.629944,1],[.547302,.085346,.628367,1],[.555986,.085162,.626572,1],[.564615,.08519,.624563,1],[.573187,.085439,.622345,1],[.581698,.085913,.619926,1],[.590149,.086615,.617311,1],[.598538,.087543,.614503,1],[.606862,.0887,.611511,1],[.61512,.090084,.608343,1],[.623312,.09169,.605001,1],[.631438,.093511,.601489,1],[.639492,.095546,.597821,1],[.647476,.097787,.593999,1],[.655389,.100226,.590028,1],[.66323,.102856,.585914,1],[.670995,.105669,.581667,1],[.678686,.108658,.577291,1],[.686302,.111813,.57279,1],[.69384,.115129,.568175,1],[.7013,.118597,.563449,1],[.708682,.122209,.558616,1],[.715984,.125959,.553687,1],[.723206,.12984,.548666,1],[.730346,.133846,.543558,1],[.737406,.13797,.538366,1],[.744382,.142209,.533101,1],[.751274,.146556,.527767,1],[.758082,.151008,.522369,1],[.764805,.155559,.516912,1],[.771443,.160206,.511402,1],[.777995,.164946,.505845,1],[.784459,.169774,.500246,1],[.790836,.174689,.494607,1],[.797125,.179688,.488935,1],[.803325,.184767,.483238,1],[.809435,.189925,.477518,1],[.815455,.19516,.471781,1],[.821384,.200471,.466028,1],[.827222,.205854,.460267,1],[.832968,.211308,.454505,1],[.838621,.216834,.448738,1],[.844181,.222428,.442979,1],[.849647,.22809,.43723,1],[.855019,.233819,.431491,1],[.860295,.239613,.425771,1],[.865475,.245471,.420074,1],[.870558,.251393,.414403,1],[.875545,.25738,.408759,1],[.880433,.263427,.403152,1],[.885223,.269535,.397585,1],[.889913,.275705,.392058,1],[.894503,.281934,.386578,1],[.898993,.288222,.381152,1],[.903381,.294569,.375781,1],[.907667,.300974,.370469,1],[.911849,.307435,.365223,1],[.915928,.313953,.360048,1],[.919902,.320527,.354948,1],[.923771,.327155,.349928,1],[.927533,.333838,.344994,1],[.931188,.340576,.340149,1],[.934736,.347366,.335403,1],[.938175,.354207,.330762,1],[.941504,.361101,.326229,1],[.944723,.368045,.321814,1],[.947831,.375039,.317523,1],[.950826,.382083,.313364,1],[.953709,.389175,.309345,1],[.956478,.396314,.305477,1],[.959133,.403499,.301766,1],[.961671,.410731,.298221,1],[.964093,.418008,.294853,1],[.966399,.425327,.291676,1],[.968586,.43269,.288696,1],[.970654,.440095,.285926,1],[.972603,.44754,.28338,1],[.974431,.455025,.281067,1],[.976139,.462547,.279003,1],[.977725,.470107,.277198,1],[.979188,.477703,.275666,1],[.980529,.485332,.274422,1],[.981747,.492995,.273476,1],[.98284,.50069,.272842,1],[.983808,.508415,.272532,1],[.984653,.516168,.27256,1],[.985373,.523948,.272937,1],[.985966,.531754,.273673,1],[.986436,.539582,.274779,1],[.98678,.547434,.276264,1],[.986998,.555305,.278135,1],[.987091,.563195,.280401,1],[.987061,.5711,.283066,1],[.986907,.579019,.286137,1],[.986629,.58695,.289615,1],[.986229,.594891,.293503,1],[.985709,.602839,.297802,1],[.985069,.610792,.302512,1],[.98431,.618748,.307632,1],[.983435,.626704,.313159,1],[.982445,.634657,.319089,1],[.981341,.642606,.32542,1],[.98013,.650546,.332144,1],[.978812,.658475,.339257,1],[.977392,.666391,.346753,1],[.97587,.67429,.354625,1],[.974252,.68217,.362865,1],[.972545,.690026,.371466,1],[.97075,.697856,.380419,1],[.968873,.705658,.389718,1],[.966921,.713426,.399353,1],[.964901,.721157,.409313,1],[.962815,.728851,.419594,1],[.960677,.7365,.430181,1],[.95849,.744103,.44107,1],[.956263,.751656,.452248,1],[.954009,.759153,.463702,1],[.951732,.766595,.475429,1],[.949445,.773974,.487414,1],[.947158,.781289,.499647,1],[.944885,.788535,.512116,1],[.942634,.795709,.524811,1],[.940423,.802807,.537717,1],[.938261,.809825,.550825,1],[.936163,.81676,.564121,1],[.934146,.823608,.577591,1],[.932224,.830366,.59122,1],[.930412,.837031,.604997,1],[.928727,.843599,.618904,1],[.927187,.850066,.632926,1],[.925809,.856432,.647047,1],[.92461,.862691,.661249,1],[.923607,.868843,.675517,1],[.92282,.874884,.689832,1],[.922265,.880812,.704174,1],[.921962,.886626,.718523,1],[.92193,.892323,.732859,1],[.922183,.897903,.747163,1],[.922741,.903364,.76141,1],[.92362,.908706,.77558,1],[.924837,.913928,.789648,1],[.926405,.919031,.80359,1],[.92834,.924015,.817381,1],[.930655,.928881,.830995,1],[.93336,.933631,.844405,1],[.936466,.938267,.857583,1],[.939982,.942791,.870499,1],[.943914,.947207,.883122,1],[.948267,.951519,.895421,1],[.953044,.955732,.907359,1],[.958246,.959852,.918901,1],[.963869,.963887,.930004,1],[.969909,.967845,.940623,1],[.976355,.971737,.950704,1],[.983195,.97558,.960181,1],[.990402,.979395,.968966,1],[.99793,.983217,.97692,1]]};function m(e){return e>=1e3?(e/1e3).toFixed(1):Math.round(e).toString()}function f(e){return e>=1e3?"kHz":"Hz"}function b(e,t,s,r,a){const l=c(s,a);return function(e,t){switch(t){case"mel":return i(e);case"logarithmic":return n(e);case"bark":return o(e);case"erb":return h(e);default:return e}}(l+e/t*(c(r,a)-l),a)}function y(e,t,s,i){switch(this.bufferSize=e,this.sampleRate=t,this.bandwidth=2/e*(t/2),this.sinTable=new Float32Array(e),this.cosTable=new Float32Array(e),this.windowValues=new Float32Array(e),this.reverseTable=new Uint32Array(e),this.peakBand=0,this.peak=0,s){case"bartlett":for(r=0;r<e;r++)this.windowValues[r]=2/(e-1)*((e-1)/2-Math.abs(r-(e-1)/2));break;case"bartlettHann":for(r=0;r<e;r++)this.windowValues[r]=.62-.48*Math.abs(r/(e-1)-.5)-.38*Math.cos(2*Math.PI*r/(e-1));break;case"blackman":for(i=i||.16,r=0;r<e;r++)this.windowValues[r]=(1-i)/2-.5*Math.cos(2*Math.PI*r/(e-1))+i/2*Math.cos(4*Math.PI*r/(e-1));break;case"cosine":for(r=0;r<e;r++)this.windowValues[r]=Math.cos(Math.PI*r/(e-1)-Math.PI/2);break;case"gauss":for(i=i||.25,r=0;r<e;r++)this.windowValues[r]=Math.pow(Math.E,-.5*Math.pow((r-(e-1)/2)/(i*(e-1)/2),2));break;case"hamming":for(r=0;r<e;r++)this.windowValues[r]=.54-.46*Math.cos(2*Math.PI*r/(e-1));break;case"hann":case void 0:for(r=0;r<e;r++)this.windowValues[r]=.5*(1-Math.cos(2*Math.PI*r/(e-1)));break;case"lanczoz":for(r=0;r<e;r++)this.windowValues[r]=Math.sin(Math.PI*(2*r/(e-1)-1))/(Math.PI*(2*r/(e-1)-1));break;case"rectangular":for(r=0;r<e;r++)this.windowValues[r]=1;break;case"triangular":for(r=0;r<e;r++)this.windowValues[r]=2/e*(e/2-Math.abs(r-(e-1)/2));break;default:throw Error("No such window function '"+s+"'")}for(var r,n=1,a=e>>1;n<e;){for(r=0;r<n;r++)this.reverseTable[r+n]=this.reverseTable[r]+a;n<<=1,a>>=1}for(r=0;r<e;r++)this.sinTable[r]=Math.sin(-Math.PI/r),this.cosTable[r]=Math.cos(-Math.PI/r);this.calculateSpectrum=function(e){var t,s,i,r=this.bufferSize,n=this.cosTable,a=this.sinTable,o=this.reverseTable,l=new Float32Array(r),h=new Float32Array(r),c=2/this.bufferSize,d=Math.sqrt,u=new Float32Array(r/2),p=Math.floor(Math.log(r)/Math.LN2);if(Math.pow(2,p)!==r)throw"Invalid buffer size, must be a power of 2.";if(r!==e.length)throw"Supplied buffer is not the same size as defined FFT. FFT Size: "+r+" Buffer Size: "+e.length;for(var m,f,b,y,M,w,v,g,W=1,Z=0;Z<r;Z++)l[Z]=e[o[Z]]*this.windowValues[o[Z]],h[Z]=0;for(;W<r;){m=n[W],f=a[W],b=1,y=0;for(var S=0;S<W;S++){for(Z=S;Z<r;)w=b*l[M=Z+W]-y*h[M],v=b*h[M]+y*l[M],l[M]=l[Z]-w,h[M]=h[Z]-v,l[Z]+=w,h[Z]+=v,Z+=W<<1;b=(g=b)*m-y*f,y=g*f+y*m}W<<=1}Z=0;for(var x=r/2;Z<x;Z++)(i=c*d((t=l[Z])*t+(s=h[Z])*s))>this.peak&&(this.peakBand=Z,this.peak=i),u[Z]=i;return u}}class M{constructor(){this.listeners={}}on(e,t,s){if(this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e].add(t),null==s?void 0:s.once){const s=()=>{this.un(e,s),this.un(e,t)};return this.on(e,s),s}return()=>this.un(e,t)}un(e,t){var s;null===(s=this.listeners[e])||void 0===s||s.delete(t)}once(e,t){return this.on(e,t,{once:!0})}unAll(){this.listeners={}}emit(e,...t){this.listeners[e]&&this.listeners[e].forEach((e=>e(...t)))}}class w extends M{constructor(e){super(),this.subscriptions=[],this.isDestroyed=!1,this.options=e}onInit(){}_init(e){this.isDestroyed&&(this.subscriptions=[],this.isDestroyed=!1),this.wavesurfer=e,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((e=>e())),this.subscriptions=[],this.isDestroyed=!0,this.wavesurfer=void 0}}function v(e,t){const s=t.xmlns?document.createElementNS(t.xmlns,e):document.createElement(e);for(const[e,i]of Object.entries(t))if("children"===e&&i)for(const[e,t]of Object.entries(i))t instanceof Node?s.appendChild(t):"string"==typeof t?s.appendChild(document.createTextNode(t)):s.appendChild(v(e,t));else"style"===e?Object.assign(s.style,i):"textContent"===e?s.textContent=i:s.setAttribute(e,i.toString());return s}function g(e,t,s){const i=v(e,t||{});return null==s||s.appendChild(i),i}var W=null;try{var Z="undefined"!=typeof module&&"function"==typeof module.require&&module.require("worker_threads")||"function"==typeof __non_webpack_require__&&__non_webpack_require__("worker_threads")||"function"==typeof require&&require("worker_threads");W=Z.Worker}catch(e){}function S(e,t,s){var i=function(e){return Buffer.from(e,"base64").toString("utf8")}(e),r=i.indexOf("\n",10)+1,n=i.substring(r)+"";return function(e){return new W(n,Object.assign({},e,{eval:!0}))}}function x(e,t,s){var i=function(e){return atob(e)}(e),r=i.indexOf("\n",10)+1,n=i.substring(r)+"",a=new Blob([n],{type:"application/javascript"});return URL.createObjectURL(a)}var X="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0);function k(e,t,s){return X?S(e):function(e){var t;return function(s){return t=t||x(e),new Worker(t,s)}}(e)}var G=k("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwohZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7Y29uc3QgdD0xZTMqTWF0aC5sb2coMTApLzEwNy45Mzk7ZnVuY3Rpb24gZSh0KXtyZXR1cm4gMjU5NSpNYXRoLmxvZzEwKDErdC83MDApfWZ1bmN0aW9uIGEodCl7cmV0dXJuIDcwMCooTWF0aC5wb3coMTAsdC8yNTk1KS0xKX1mdW5jdGlvbiByKHQpe3JldHVybiBNYXRoLmxvZzEwKE1hdGgubWF4KDEsdCkpfWZ1bmN0aW9uIHModCl7cmV0dXJuIE1hdGgucG93KDEwLHQpfWZ1bmN0aW9uIG4odCl7bGV0IGU9MjYuODEqdC8oMTk2MCt0KS0uNTM7cmV0dXJuIGU8MiYmKGUrPS4xNSooMi1lKSksZT4yMC4xJiYoZSs9LjIyKihlLTI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T17dHlwZToiZnJlcXVlbmNpZXNSZXN1bHQiLGlkOncsZXJyb3I6dCBpbnN0YW5jZW9mIEVycm9yP3QubWVzc2FnZTpTdHJpbmcodCl9O3NlbGYucG9zdE1lc3NhZ2UoZSl9fX0oKTsKLy8jIHNvdXJjZU1hcHBpbmdVUkw9c3BlY3Ryb2dyYW0td29ya2VyLmpzLm1hcAoK");class T extends w{static create(e){return new T(e||{})}constructor(e){var t,s;if(super(e),this.canvases=[],this.useWebWorker=!1,this.worker=null,this.workerPromises=new Map,this.cachedFrequencies=null,this.cachedResampledData=null,this.cachedBuffer=null,this.cachedWidth=0,this.renderTimeout=null,this.isRendering=!1,this.lastZoomLevel=0,this.renderThrottleMs=50,this.zoomThreshold=.05,this.drawnCanvases={},this.pendingBitmaps=new Set,this.isScrollable=!1,this.scrollUnsubscribe=null,this.frequenciesDataUrl=e.frequenciesDataUrl,this.frequenciesDataUrl&&!e.sampleRate)throw new Error("sampleRate option is required when using frequenciesDataUrl");this.container="string"==typeof e.container?document.querySelector(e.container):e.container,this.useWebWorker=!0===e.useWebWorker,this.colorMap=function(e="roseus"){if(e&&"string"!=typeof e){if(e.length<256)throw new Error("Colormap must contain 256 elements");for(let t=0;t<e.length;t++)if(4!==e[t].length)throw new Error("ColorMap entries must contain 4 values");return e}const t=p[e];if(!t)throw Error("No such colormap '"+e+"'");return t()}(e.colorMap),this.fftSamples=e.fftSamples||512,this.height=e.height||200,this.noverlap=e.noverlap||null,this.windowFunc=e.windowFunc||"hann",this.alpha=e.alpha,this.frequencyMin=e.frequencyMin||0,this.frequencyMax=e.frequencyMax||0,this.gainDB=null!==(t=e.gainDB)&&void 0!==t?t:20,this.rangeDB=null!==(s=e.rangeDB)&&void 0!==s?s:80,this.scale=e.scale||"mel",this.numMelFilters=this.fftSamples/2,this.numLogFilters=this.fftSamples/2,this.numBarkFilters=this.fftSamples/2,this.numErbFilters=this.fftSamples/2,e.maxCanvasWidth&&(T.MAX_CANVAS_WIDTH=e.maxCanvasWidth),this.renderThrottleMs=50,this.zoomThreshold=.05,this.createWrapper(),this.createCanvas(),this.useWebWorker&&this.initializeWorker()}initializeWorker(){if("undefined"!=typeof window&&"undefined"!=typeof Worker)try{this.worker=new G,this.worker.onmessage=e=>{const{type:t,id:s,result:i,error:r}=e.data;if("frequenciesResult"===t){const e=this.workerPromises.get(s);e&&(this.workerPromises.delete(s),r?e.reject(new Error(r)):e.resolve(i))}},this.worker.onerror=e=>{console.warn("Spectrogram worker error, falling back to main thread:",e),this.worker=null}}catch(e){console.warn("Failed to initialize worker, falling back to main thread:",e),this.worker=null}else console.warn("Worker not available in this environment, using main thread calculation")}onInit(){this.wrapper||this.createWrapper(),this.canvasContainer||this.createCanvas(),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.throttledRender()))),this.wavesurfer.getDecodedData()&&setTimeout((()=>{this.throttledRender()}),0)}destroy(){this.unAll(),this.wavesurfer&&("function"==typeof this._onReady&&this.wavesurfer.un("ready",this._onReady),"function"==typeof this._onRender&&this.wavesurfer.un("redraw",this._onRender)),this.renderTimeout&&(clearTimeout(this.renderTimeout),this.renderTimeout=null),this.scrollUnsubscribe&&(this.scrollUnsubscribe(),this.scrollUnsubscribe=null),this.pendingBitmaps.clear(),this.worker&&(this.worker.terminate(),this.worker=null),this.cachedFrequencies=null,this.cachedResampledData=null,this.cachedBuffer=null,this.clearCanvases(),this.canvasContainer&&(this.canvasContainer.remove(),this.canvasContainer=null),this.wrapper&&(this.wrapper.remove(),this.wrapper=null),this.labelsEl&&(this.labelsEl.remove(),this.labelsEl=null),this.container=null,this.isRendering=!1,this.lastZoomLevel=0,this.wavesurfer=null,this.util=null,this.options=null,super.destroy()}loadFrequenciesData(t){return e(this,void 0,void 0,(function*(){const e=yield fetch(t);if(!e.ok)throw new Error("Unable to fetch frequencies data");const s=yield e.json();this.drawSpectrogram(s)}))}clearCache(){this.cachedFrequencies=null,this.cachedResampledData=null,this.cachedBuffer=null,this.cachedWidth=0,this.lastZoomLevel=0}createWrapper(){var e,t;this.wrapper=g("div",{style:{display:"block",position:"relative",userSelect:"none"}}),this.options.labels&&(this.labelsEl=g("canvas",{part:"spec-labels",style:{position:"absolute",zIndex:9,width:"55px",height:"100%"}},this.wrapper)),this._onWrapperClick=(e=this.wrapper,t=this.emit.bind(this),s=>{const i=e.getBoundingClientRect(),r=s.clientX-i.left,n=i.width;t("click",r/n)}),this.wrapper.addEventListener("click",this._onWrapperClick)}createCanvas(){this.canvasContainer=g("div",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",zIndex:4}},this.wrapper)}createSingleCanvas(e,t,s){const i=g("canvas",{style:{position:"absolute",left:`${Math.round(s)}px`,top:"0",width:`${e}px`,height:`${t}px`,zIndex:4}});return i.width=Math.round(e),i.height=Math.round(t),this.canvasContainer.appendChild(i),i}clearCanvases(){this.canvases.forEach((e=>e.remove())),this.canvases=[],this.drawnCanvases={}}clearExcessCanvases(){Object.keys(this.drawnCanvases).length>T.MAX_NODES&&this.clearCanvases()}throttledRender(){var e;if(this.renderTimeout&&clearTimeout(this.renderTimeout),this.isRendering)return;const t=(null===(e=this.wavesurfer)||void 0===e?void 0:e.options.minPxPerSec)||0;Math.abs(t-this.lastZoomLevel)/Math.max(t,this.lastZoomLevel,1)<this.zoomThreshold&&this.cachedFrequencies?this.renderTimeout=window.setTimeout((()=>{this.fastRender()}),this.renderThrottleMs):this.renderTimeout=window.setTimeout((()=>{this.render()}),this.renderThrottleMs)}render(){return e(this,void 0,void 0,(function*(){var e,t;if(!this.isRendering){this.isRendering=!0;try{if(this.frequenciesDataUrl)yield this.loadFrequenciesData(this.frequenciesDataUrl);else{const t=null===(e=this.wavesurfer)||void 0===e?void 0:e.getDecodedData();if(t)if(this.cachedBuffer===t&&this.cachedFrequencies)this.drawSpectrogram(this.cachedFrequencies);else{const e=yield this.getFrequencies(t);this.cachedFrequencies=e,this.cachedBuffer=t,this.drawSpectrogram(e)}}this.lastZoomLevel=(null===(t=this.wavesurfer)||void 0===t?void 0:t.options.minPxPerSec)||0}finally{this.isRendering=!1}}}))}fastRender(){var e;if(!this.isRendering&&this.cachedFrequencies){this.isRendering=!0;try{this.drawSpectrogram(this.cachedFrequencies),this.lastZoomLevel=(null===(e=this.wavesurfer)||void 0===e?void 0:e.options.minPxPerSec)||0}finally{this.isRendering=!1}}}drawSpectrogram(e){var t,s,i;isNaN(e[0][0])||(e=[e]),this.clearCanvases();const r=this.height*e.length;this.wrapper.style.height=r+"px";const n=this.getWidth(),a=Math.min(T.MAX_CANVAS_WIDTH,n);if(0===n||0===r)return;const o=Math.ceil(n/a);let l;const h=(null===(t=e[0])||void 0===t?void 0:t.length)||0;n!==h?this.cachedResampledData&&this.cachedWidth===n?l=this.cachedResampledData:(l=this.efficientResample(e,n),this.cachedResampledData=l,this.cachedWidth=n):l=e;const c=(null===(s=this.buffer)||void 0===s?void 0:s.sampleRate)?this.buffer.sampleRate/2:(this.options.sampleRate||0)/2,d=this.frequencyMin,u=this.frequencyMax,p=u>c,m=p?this.colorMap[this.colorMap.length-1]:null,f=e=>{if(e<0||e>=o)return;if(this.drawnCanvases[e])return;this.drawnCanvases[e]=!0;const t=e*a,s=Math.min(a,n-t);if(s<=0)return;const i=this.createSingleCanvas(s,r,t);this.canvases.push(i);const h=i.getContext("2d");if(h){p&&m&&(h.fillStyle=`rgba(${255*m[0]}, ${255*m[1]}, ${255*m[2]}, ${m[3]})`,h.fillRect(0,0,s,r));for(let e=0;e<l.length;e++)this.drawSpectrogramSegment(l[e],h,s,this.height,e*this.height,t,n,c,d,u)}};if(this.isScrollable=n>this.getWrapperWidth(),this.scrollUnsubscribe&&(this.scrollUnsubscribe(),this.scrollUnsubscribe=null),!this.isScrollable||o<=3)for(let e=0;e<o;e++)f(e);else{const e=()=>{var e;const t=null===(e=this.wavesurfer)||void 0===e?void 0:e.getWrapper();if(!t)return;const s=t.scrollLeft||0,i=t.clientWidth||0,r=Math.max(0,s-.5*i),a=Math.min(n,s+1.5*i),l=Math.floor(r/n*o),h=Math.min(Math.ceil(a/n*o),o-1);Object.keys(this.drawnCanvases).length>T.MAX_NODES&&this.clearExcessCanvases();for(let e=l;e<=h;e++)f(e)};e();let t=null;const s=()=>{t&&clearTimeout(t),t=window.setTimeout(e,16)},r=null===(i=this.wavesurfer)||void 0===i?void 0:i.getWrapper();r&&(r.addEventListener("scroll",s,{passive:!0}),this.scrollUnsubscribe=()=>{r.removeEventListener("scroll",s),t&&clearTimeout(t)})}this.options.labels&&this.loadLabels(this.options.labelsBackground,"12px","12px","",this.options.labelsColor,this.options.labelsHzColor||this.options.labelsColor,"center","#specLabels",e.length),this.emit("ready")}drawSpectrogramSegment(e,t,s,i,r,n,a,o,l,h){const d=e[0].length,u=Math.floor(n/a*e.length),p=Math.min(Math.ceil((n+s)/a*e.length),e.length),m=e.slice(u,p);if(0===m.length)return;const f=m.length,b=new ImageData(f,d),y=b.data;this.fillImageDataQuality(y,m,f,d);const M=c(l,this.scale)/c(o,this.scale),w=c(h,this.scale)/c(o,this.scale),v=Math.min(1,w),g=createImageBitmap(b,0,Math.round(d*(1-v)),f,Math.round(d*(v-M)));this.pendingBitmaps.add(g),g.then((e=>{if(this.pendingBitmaps.delete(g),t.canvas.parentNode){const n=i*v/w,a=r+i*(1-v/w);t.drawImage(e,0,a,s,n),"close"in e&&e.close()}})).catch((e=>{this.pendingBitmaps.delete(g)}))}getWidth(){return this.wavesurfer.getWrapper().offsetWidth}getWrapperWidth(){var e,t;return(null===(t=null===(e=this.wavesurfer)||void 0===e?void 0:e.getWrapper())||void 0===t?void 0:t.clientWidth)||0}calculateFrequenciesWithWorker(t){return e(this,void 0,void 0,(function*(){var e,s;if(!this.worker)throw new Error("Worker not available");const i=this.fftSamples,r=(null!==(e=this.options.splitChannels)&&void 0!==e?e:null===(s=this.wavesurfer)||void 0===s?void 0:s.options.splitChannels)?t.numberOfChannels:1;let n=this.noverlap;if(!n){const e=this.getWidth(),s=t.length/e;n=Math.max(0,Math.round(i-s))}const a=[];for(let e=0;e<r;e++)a.push(t.getChannelData(e));const o=`${Date.now()}_${Math.random()}`,l=new Promise(((e,t)=>{this.workerPromises.set(o,{resolve:e,reject:t}),setTimeout((()=>{this.workerPromises.has(o)&&(this.workerPromises.delete(o),t(new Error("Worker timeout")))}),3e4)}));return this.worker.postMessage({type:"calculateFrequencies",id:o,audioData:a,options:{startTime:0,endTime:t.duration,sampleRate:t.sampleRate,fftSamples:this.fftSamples,windowFunc:this.windowFunc,alpha:this.alpha,noverlap:n,scale:this.scale,gainDB:this.gainDB,rangeDB:this.rangeDB,splitChannels:this.options.splitChannels||!1}}),l}))}getFrequencies(t){return e(this,void 0,void 0,(function*(){var e,c;if(this.frequencyMax=this.frequencyMax||t.sampleRate/2,this.buffer=t,!t)return[];if(this.useWebWorker&&this.worker)try{return yield this.calculateFrequenciesWithWorker(t)}catch(e){console.warn("Worker calculation failed, falling back to main thread:",e)}const p=this.fftSamples,m=(null!==(e=this.options.splitChannels)&&void 0!==e?e:null===(c=this.wavesurfer)||void 0===c?void 0:c.options.splitChannels)?t.numberOfChannels:1,f=t.sampleRate,b=[];let M=this.noverlap;if(!M){const e=this.getWidth(),s=t.length/e;M=Math.max(0,Math.round(p-s))}let w=M||Math.max(0,Math.round(.5*p));const v=.5*p;w=Math.min(w,v);const g=Math.max(64,.25*p),W=Math.max(g,p-w),Z=new y(p,f,this.windowFunc,this.alpha),S=this.fftSamples/2,x=function(e,t,c,u){switch(e){case"mel":return d(t,c,u,s,i);case"logarithmic":return d(t,c,u,r,n);case"bark":return d(t,c,u,a,o);case"erb":return d(t,c,u,l,h);default:return null}}(this.scale,S,this.fftSamples,f);for(let e=0;e<m;e++){const s=t.getChannelData(e),i=[];for(let e=0;e+p<s.length;e+=W){const t=s.slice(e,e+p);let r=Z.calculateSpectrum(t);x&&(r=u(r,x));const n=new Uint8Array(r.length),a=this.gainDB+this.rangeDB;for(let e=0;e<r.length;e++){const t=r[e]>1e-12?r[e]:1e-12,s=20*Math.log10(t);s<-a?n[e]=0:s>-this.gainDB?n[e]=255:n[e]=Math.round((s+this.gainDB)/this.rangeDB*255)}i.push(n)}b.push(i)}return b}))}loadLabels(e,t,s,i,r,n,a,o,l){e=e||"rgba(68,68,68,0)",t=t||"12px",s=s||"12px",i=i||"Helvetica",r=r||"#fff",n=n||"#fff",a=a||"center";const h=this.height||512,c=h/256*5;this.frequencyMin;this.frequencyMax;const d=this.labelsEl.getContext("2d"),u=window.devicePixelRatio;if(this.labelsEl.height=this.height*l*u,this.labelsEl.width=55*u,d.scale(u,u),d)for(let o=0;o<l;o++){let l;for(d.fillStyle=e,d.fillRect(0,o*h,55,(1+o)*h),d.fill(),l=0;l<=c;l++){d.textAlign=a,d.textBaseline="middle";const e=b(l,c,this.frequencyMin,this.frequencyMax,this.scale),u=m(e),p=f(e),y=16;let M=(1+o)*h-l/c*h;M=Math.min(Math.max(M,o*h+10),(1+o)*h-10),d.fillStyle=n,d.font=s+" "+i,d.fillText(p,y+24,M),d.fillStyle=r,d.font=t+" "+i,d.fillText(u,y,M)}}}efficientResample(e,t){return e.map((e=>this.resampleChannel(e,t)))}resampleChannel(e,t){var s;const i=e.length,r=(null===(s=e[0])||void 0===s?void 0:s.length)||0;if(i===t||0===t)return e;const n=i/t,a=new Array(t);if(n>=1)for(let s=0;s<t;s++){const t=Math.floor(s*n),o=Math.min(Math.ceil((s+1)*n),i),l=o-t,h=new Uint8Array(r);if(1===l)h.set(e[t]);else for(let s=0;s<r;s++){let i=0;for(let r=t;r<o;r++)i+=e[r][s];h[s]=Math.round(i/l)}a[s]=h}else for(let s=0;s<t;s++){const t=s*n,o=Math.floor(t),l=Math.min(o+1,i-1),h=t-o,c=new Uint8Array(r);if(0===h||o===l)c.set(e[o]);else{const t=e[o],s=e[l],i=1-h;for(let e=0;e<r;e++)c[e]=Math.round(t[e]*i+s[e]*h)}a[s]=c}return a}fillImageDataQuality(e,t,s,i){const r=this.colorMap;for(let n=0;n<s;n++){const a=t[n];for(let t=0;t<i;t++){const o=r[a[t]],l=4*((i-t-1)*s+n);e[l]=255*o[0],e[l+1]=255*o[1],e[l+2]=255*o[2],e[l+3]=255*o[3]}}}}T.MAX_CANVAS_WIDTH=3e4,T.MAX_NODES=10;export{T as default};
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e="undefined"!=typeof globalThis?globalThis:e||self).WaveSurfer=e.WaveSurfer||{},e.WaveSurfer.Spectrogram=t())}(this,(function(){"use strict";function e(e,t,s,r){return new(s||(s=Promise))((function(i,a){function n(e){try{o(r.next(e))}catch(e){a(e)}}function h(e){try{o(r.throw(e))}catch(e){a(e)}}function o(e){var t;e.done?i(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(n,h)}o((r=r.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class t{constructor(){this.listeners={}}on(e,t,s){if(this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e].add(t),null==s?void 0:s.once){const s=()=>{this.un(e,s),this.un(e,t)};return this.on(e,s),s}return()=>this.un(e,t)}un(e,t){var s;null===(s=this.listeners[e])||void 0===s||s.delete(t)}once(e,t){return this.on(e,t,{once:!0})}unAll(){this.listeners={}}emit(e,...t){this.listeners[e]&&this.listeners[e].forEach((e=>e(...t)))}}class s extends t{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()))}}function r(e,t){const s=t.xmlns?document.createElementNS(t.xmlns,e):document.createElement(e);for(const[e,i]of Object.entries(t))if("children"===e&&i)for(const[e,t]of Object.entries(i))t instanceof Node?s.appendChild(t):"string"==typeof t?s.appendChild(document.createTextNode(t)):s.appendChild(r(e,t));else"style"===e?Object.assign(s.style,i):"textContent"===e?s.textContent=i:s.setAttribute(e,i.toString());return s}function i(e,t,s){const i=r(e,t||{});return null==s||s.appendChild(i),i}function a(e,t,s,r){switch(this.bufferSize=e,this.sampleRate=t,this.bandwidth=2/e*(t/2),this.sinTable=new Float32Array(e),this.cosTable=new Float32Array(e),this.windowValues=new Float32Array(e),this.reverseTable=new Uint32Array(e),this.peakBand=0,this.peak=0,s){case"bartlett":for(i=0;i<e;i++)this.windowValues[i]=2/(e-1)*((e-1)/2-Math.abs(i-(e-1)/2));break;case"bartlettHann":for(i=0;i<e;i++)this.windowValues[i]=.62-.48*Math.abs(i/(e-1)-.5)-.38*Math.cos(2*Math.PI*i/(e-1));break;case"blackman":for(r=r||.16,i=0;i<e;i++)this.windowValues[i]=(1-r)/2-.5*Math.cos(2*Math.PI*i/(e-1))+r/2*Math.cos(4*Math.PI*i/(e-1));break;case"cosine":for(i=0;i<e;i++)this.windowValues[i]=Math.cos(Math.PI*i/(e-1)-Math.PI/2);break;case"gauss":for(r=r||.25,i=0;i<e;i++)this.windowValues[i]=Math.pow(Math.E,-.5*Math.pow((i-(e-1)/2)/(r*(e-1)/2),2));break;case"hamming":for(i=0;i<e;i++)this.windowValues[i]=.54-.46*Math.cos(2*Math.PI*i/(e-1));break;case"hann":case void 0:for(i=0;i<e;i++)this.windowValues[i]=.5*(1-Math.cos(2*Math.PI*i/(e-1)));break;case"lanczoz":for(i=0;i<e;i++)this.windowValues[i]=Math.sin(Math.PI*(2*i/(e-1)-1))/(Math.PI*(2*i/(e-1)-1));break;case"rectangular":for(i=0;i<e;i++)this.windowValues[i]=1;break;case"triangular":for(i=0;i<e;i++)this.windowValues[i]=2/e*(e/2-Math.abs(i-(e-1)/2));break;default:throw Error("No such window function '"+s+"'")}for(var i,a=1,n=e>>1;a<e;){for(i=0;i<a;i++)this.reverseTable[i+a]=this.reverseTable[i]+n;a<<=1,n>>=1}for(i=0;i<e;i++)this.sinTable[i]=Math.sin(-Math.PI/i),this.cosTable[i]=Math.cos(-Math.PI/i);this.calculateSpectrum=function(e){var t,s,r,i=this.bufferSize,a=this.cosTable,n=this.sinTable,h=this.reverseTable,o=new Float32Array(i),l=new Float32Array(i),c=2/this.bufferSize,u=Math.sqrt,f=new Float32Array(i/2),p=Math.floor(Math.log(i)/Math.LN2);if(Math.pow(2,p)!==i)throw"Invalid buffer size, must be a power of 2.";if(i!==e.length)throw"Supplied buffer is not the same size as defined FFT. FFT Size: "+i+" Buffer Size: "+e.length;for(var d,w,g,b,M,m,v,y,T=1,k=0;k<i;k++)o[k]=e[h[k]]*this.windowValues[h[k]],l[k]=0;for(;T<i;){d=a[T],w=n[T],g=1,b=0;for(var z=0;z<T;z++){for(k=z;k<i;)m=g*o[M=k+T]-b*l[M],v=g*l[M]+b*o[M],o[M]=o[k]-m,l[M]=l[k]-v,o[k]+=m,l[k]+=v,k+=T<<1;g=(y=g)*d-b*w,b=y*w+b*d}T<<=1}k=0;for(var F=i/2;k<F;k++)(r=c*u((t=o[k])*t+(s=l[k])*s))>this.peak&&(this.peakBand=k,this.peak=r),f[k]=r;return f}}const n=1e3*Math.log(10)/107.939;class h extends s{static create(e){return new h(e||{})}constructor(e){var t,s;if(super(e),this.frequenciesDataUrl=e.frequenciesDataUrl,this.container="string"==typeof e.container?document.querySelector(e.container):e.container,e.colorMap&&"string"!=typeof e.colorMap){if(e.colorMap.length<256)throw new Error("Colormap must contain 256 elements");for(let t=0;t<e.colorMap.length;t++){if(4!==e.colorMap[t].length)throw new Error("ColorMap entries must contain 4 values")}this.colorMap=e.colorMap}else switch(this.colorMap=e.colorMap||"roseus",this.colorMap){case"gray":this.colorMap=[];for(let e=0;e<256;e++){const t=(255-e)/256;this.colorMap.push([t,t,t,1])}break;case"igray":this.colorMap=[];for(let e=0;e<256;e++){const t=e/256;this.colorMap.push([t,t,t,1])}break;case"roseus":this.colorMap=[[.004528,.004341,.004307,1],[.005625,.006156,.00601,1],[.006628,.008293,.008161,1],[.007551,.010738,.01079,1],[.008382,.013482,.013941,1],[.009111,.01652,.017662,1],[.009727,.019846,.022009,1],[.010223,.023452,.027035,1],[.010593,.027331,.032799,1],[.010833,.031475,.039361,1],[.010941,.035875,.046415,1],[.010918,.04052,.053597,1],[.010768,.045158,.060914,1],[.010492,.049708,.068367,1],[.010098,.054171,.075954,1],[.009594,.058549,.083672,1],[.008989,.06284,.091521,1],[.008297,.067046,.099499,1],[.00753,.071165,.107603,1],[.006704,.075196,.11583,1],[.005838,.07914,.124178,1],[.004949,.082994,.132643,1],[.004062,.086758,.141223,1],[.003198,.09043,.149913,1],[.002382,.09401,.158711,1],[.001643,.097494,.167612,1],[.001009,.100883,.176612,1],[514e-6,.104174,.185704,1],[187e-6,.107366,.194886,1],[66e-6,.110457,.204151,1],[186e-6,.113445,.213496,1],[587e-6,.116329,.222914,1],[.001309,.119106,.232397,1],[.002394,.121776,.241942,1],[.003886,.124336,.251542,1],[.005831,.126784,.261189,1],[.008276,.12912,.270876,1],[.011268,.131342,.280598,1],[.014859,.133447,.290345,1],[.0191,.135435,.300111,1],[.024043,.137305,.309888,1],[.029742,.139054,.319669,1],[.036252,.140683,.329441,1],[.043507,.142189,.339203,1],[.050922,.143571,.348942,1],[.058432,.144831,.358649,1],[.066041,.145965,.368319,1],[.073744,.146974,.377938,1],[.081541,.147858,.387501,1],[.089431,.148616,.396998,1],[.097411,.149248,.406419,1],[.105479,.149754,.415755,1],[.113634,.150134,.424998,1],[.121873,.150389,.434139,1],[.130192,.150521,.443167,1],[.138591,.150528,.452075,1],[.147065,.150413,.460852,1],[.155614,.150175,.469493,1],[.164232,.149818,.477985,1],[.172917,.149343,.486322,1],[.181666,.148751,.494494,1],[.190476,.148046,.502493,1],[.199344,.147229,.510313,1],[.208267,.146302,.517944,1],[.217242,.145267,.52538,1],[.226264,.144131,.532613,1],[.235331,.142894,.539635,1],[.24444,.141559,.546442,1],[.253587,.140131,.553026,1],[.262769,.138615,.559381,1],[.271981,.137016,.5655,1],[.281222,.135335,.571381,1],[.290487,.133581,.577017,1],[.299774,.131757,.582404,1],[.30908,.129867,.587538,1],[.318399,.12792,.592415,1],[.32773,.125921,.597032,1],[.337069,.123877,.601385,1],[.346413,.121793,.605474,1],[.355758,.119678,.609295,1],[.365102,.11754,.612846,1],[.374443,.115386,.616127,1],[.383774,.113226,.619138,1],[.393096,.111066,.621876,1],[.402404,.108918,.624343,1],[.411694,.106794,.62654,1],[.420967,.104698,.628466,1],[.430217,.102645,.630123,1],[.439442,.100647,.631513,1],[.448637,.098717,.632638,1],[.457805,.096861,.633499,1],[.46694,.095095,.6341,1],[.47604,.093433,.634443,1],[.485102,.091885,.634532,1],[.494125,.090466,.63437,1],[.503104,.08919,.633962,1],[.512041,.088067,.633311,1],[.520931,.087108,.63242,1],[.529773,.086329,.631297,1],[.538564,.085738,.629944,1],[.547302,.085346,.628367,1],[.555986,.085162,.626572,1],[.564615,.08519,.624563,1],[.573187,.085439,.622345,1],[.581698,.085913,.619926,1],[.590149,.086615,.617311,1],[.598538,.087543,.614503,1],[.606862,.0887,.611511,1],[.61512,.090084,.608343,1],[.623312,.09169,.605001,1],[.631438,.093511,.601489,1],[.639492,.095546,.597821,1],[.647476,.097787,.593999,1],[.655389,.100226,.590028,1],[.66323,.102856,.585914,1],[.670995,.105669,.581667,1],[.678686,.108658,.577291,1],[.686302,.111813,.57279,1],[.69384,.115129,.568175,1],[.7013,.118597,.563449,1],[.708682,.122209,.558616,1],[.715984,.125959,.553687,1],[.723206,.12984,.548666,1],[.730346,.133846,.543558,1],[.737406,.13797,.538366,1],[.744382,.142209,.533101,1],[.751274,.146556,.527767,1],[.758082,.151008,.522369,1],[.764805,.155559,.516912,1],[.771443,.160206,.511402,1],[.777995,.164946,.505845,1],[.784459,.169774,.500246,1],[.790836,.174689,.494607,1],[.797125,.179688,.488935,1],[.803325,.184767,.483238,1],[.809435,.189925,.477518,1],[.815455,.19516,.471781,1],[.821384,.200471,.466028,1],[.827222,.205854,.460267,1],[.832968,.211308,.454505,1],[.838621,.216834,.448738,1],[.844181,.222428,.442979,1],[.849647,.22809,.43723,1],[.855019,.233819,.431491,1],[.860295,.239613,.425771,1],[.865475,.245471,.420074,1],[.870558,.251393,.414403,1],[.875545,.25738,.408759,1],[.880433,.263427,.403152,1],[.885223,.269535,.397585,1],[.889913,.275705,.392058,1],[.894503,.281934,.386578,1],[.898993,.288222,.381152,1],[.903381,.294569,.375781,1],[.907667,.300974,.370469,1],[.911849,.307435,.365223,1],[.915928,.313953,.360048,1],[.919902,.320527,.354948,1],[.923771,.327155,.349928,1],[.927533,.333838,.344994,1],[.931188,.340576,.340149,1],[.934736,.347366,.335403,1],[.938175,.354207,.330762,1],[.941504,.361101,.326229,1],[.944723,.368045,.321814,1],[.947831,.375039,.317523,1],[.950826,.382083,.313364,1],[.953709,.389175,.309345,1],[.956478,.396314,.305477,1],[.959133,.403499,.301766,1],[.961671,.410731,.298221,1],[.964093,.418008,.294853,1],[.966399,.425327,.291676,1],[.968586,.43269,.288696,1],[.970654,.440095,.285926,1],[.972603,.44754,.28338,1],[.974431,.455025,.281067,1],[.976139,.462547,.279003,1],[.977725,.470107,.277198,1],[.979188,.477703,.275666,1],[.980529,.485332,.274422,1],[.981747,.492995,.273476,1],[.98284,.50069,.272842,1],[.983808,.508415,.272532,1],[.984653,.516168,.27256,1],[.985373,.523948,.272937,1],[.985966,.531754,.273673,1],[.986436,.539582,.274779,1],[.98678,.547434,.276264,1],[.986998,.555305,.278135,1],[.987091,.563195,.280401,1],[.987061,.5711,.283066,1],[.986907,.579019,.286137,1],[.986629,.58695,.289615,1],[.986229,.594891,.293503,1],[.985709,.602839,.297802,1],[.985069,.610792,.302512,1],[.98431,.618748,.307632,1],[.983435,.626704,.313159,1],[.982445,.634657,.319089,1],[.981341,.642606,.32542,1],[.98013,.650546,.332144,1],[.978812,.658475,.339257,1],[.977392,.666391,.346753,1],[.97587,.67429,.354625,1],[.974252,.68217,.362865,1],[.972545,.690026,.371466,1],[.97075,.697856,.380419,1],[.968873,.705658,.389718,1],[.966921,.713426,.399353,1],[.964901,.721157,.409313,1],[.962815,.728851,.419594,1],[.960677,.7365,.430181,1],[.95849,.744103,.44107,1],[.956263,.751656,.452248,1],[.954009,.759153,.463702,1],[.951732,.766595,.475429,1],[.949445,.773974,.487414,1],[.947158,.781289,.499647,1],[.944885,.788535,.512116,1],[.942634,.795709,.524811,1],[.940423,.802807,.537717,1],[.938261,.809825,.550825,1],[.936163,.81676,.564121,1],[.934146,.823608,.577591,1],[.932224,.830366,.59122,1],[.930412,.837031,.604997,1],[.928727,.843599,.618904,1],[.927187,.850066,.632926,1],[.925809,.856432,.647047,1],[.92461,.862691,.661249,1],[.923607,.868843,.675517,1],[.92282,.874884,.689832,1],[.922265,.880812,.704174,1],[.921962,.886626,.718523,1],[.92193,.892323,.732859,1],[.922183,.897903,.747163,1],[.922741,.903364,.76141,1],[.92362,.908706,.77558,1],[.924837,.913928,.789648,1],[.926405,.919031,.80359,1],[.92834,.924015,.817381,1],[.930655,.928881,.830995,1],[.93336,.933631,.844405,1],[.936466,.938267,.857583,1],[.939982,.942791,.870499,1],[.943914,.947207,.883122,1],[.948267,.951519,.895421,1],[.953044,.955732,.907359,1],[.958246,.959852,.918901,1],[.963869,.963887,.930004,1],[.969909,.967845,.940623,1],[.976355,.971737,.950704,1],[.983195,.97558,.960181,1],[.990402,.979395,.968966,1],[.99793,.983217,.97692,1]];break;default:throw Error("No such colormap '"+this.colorMap+"'")}this.fftSamples=e.fftSamples||512,this.height=e.height||200,this.noverlap=e.noverlap||null,this.windowFunc=e.windowFunc||"hann",this.alpha=e.alpha,this.frequencyMin=e.frequencyMin||0,this.frequencyMax=e.frequencyMax||0,this.gainDB=null!==(t=e.gainDB)&&void 0!==t?t:20,this.rangeDB=null!==(s=e.rangeDB)&&void 0!==s?s:80,this.scale=e.scale||"mel",this.numMelFilters=this.fftSamples/2,this.numLogFilters=this.fftSamples/2,this.numBarkFilters=this.fftSamples/2,this.numErbFilters=this.fftSamples/2,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("decode",(()=>{this.buffer=void 0,this.frequencies=void 0})),this.wavesurfer.on("redraw",(()=>this.render())))}destroy(){this.unAll(),this.wavesurfer.un("ready",this._onReady),this.wavesurfer.un("redraw",this._onRender),this.buffer=void 0,this.frequencies=void 0,this.wavesurfer=null,this.util=null,this.options=null,this.wrapper&&(this.wrapper.remove(),this.wrapper=null),super.destroy()}loadFrequenciesData(t){return e(this,void 0,void 0,(function*(){const e=yield fetch(t);if(!e.ok)throw new Error("Unable to fetch frequencies data");const s=yield e.json();this.frequencies=s,this.drawSpectrogram(s)}))}createWrapper(){this.wrapper=i("div",{style:{display:"block",position:"relative",userSelect:"none"}}),this.options.labels&&(this.labelsEl=i("canvas",{part:"spec-labels",style:{position:"absolute",zIndex:9,width:"55px",height:"100%"}},this.wrapper)),this.wrapper.addEventListener("click",this._onWrapperClick)}createCanvas(){this.canvas=i("canvas",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",zIndex:4}},this.wrapper),this.spectrCc=this.canvas.getContext("2d")}render(){var e;if(this.frequenciesDataUrl)this.loadFrequenciesData(this.frequenciesDataUrl);else{const t=null===(e=this.wavesurfer)||void 0===e?void 0:e.getDecodedData();t&&(this.frequencies&&this.buffer===t||(this.frequencies=this.getFrequencies(t)),this.drawSpectrogram(this.frequencies))}}drawSpectrogram(e){isNaN(e[0][0])||(e=[e]),this.wrapper.style.height=this.height*e.length+"px",this.canvas.width=this.getWidth(),this.canvas.height=this.height*e.length;const t=this.spectrCc,s=this.height,r=this.getWidth(),i=this.buffer.sampleRate/2,a=this.frequencyMin,n=this.frequencyMax;if(t){if(n>i){const i=this.colorMap[this.colorMap.length-1];t.fillStyle=`rgba(${i[0]}, ${i[1]}, ${i[2]}, ${i[3]})`,t.fillRect(0,0,r,s*e.length)}for(let h=0;h<e.length;h++){const o=this.resample(e[h]),l=o[0].length,c=new ImageData(r,l);for(let e=0;e<o.length;e++)for(let t=0;t<o[e].length;t++){const s=this.colorMap[o[e][t]],i=4*((l-t-1)*r+e);c.data[i]=255*s[0],c.data[i+1]=255*s[1],c.data[i+2]=255*s[2],c.data[i+3]=255*s[3]}const u=this.hzToScale(a)/this.hzToScale(i),f=this.hzToScale(n)/this.hzToScale(i),p=Math.min(1,f);createImageBitmap(c,0,Math.round(l*(1-p)),r,Math.round(l*(p-u))).then((e=>{t.drawImage(e,0,s*(h+1-p/f),r,s*p/f)}))}this.options.labels&&this.loadLabels(this.options.labelsBackground,"12px","12px","",this.options.labelsColor,this.options.labelsHzColor||this.options.labelsColor,"center","#specLabels",e.length),this.emit("ready")}}createFilterBank(e,t,s,r){const i=s(0),a=s(t/2),n=Array.from({length:e},(()=>Array(this.fftSamples/2+1).fill(0))),h=t/this.fftSamples;for(let t=0;t<e;t++){let s=r(i+t/e*(a-i)),o=Math.floor(s/h),l=o*h,c=(s-l)/((o+1)*h-l);n[t][o]=1-c,n[t][o+1]=c}return n}hzToMel(e){return 2595*Math.log10(1+e/700)}melToHz(e){return 700*(Math.pow(10,e/2595)-1)}createMelFilterBank(e,t){return this.createFilterBank(e,t,this.hzToMel,this.melToHz)}hzToLog(e){return Math.log10(Math.max(1,e))}logToHz(e){return Math.pow(10,e)}createLogFilterBank(e,t){return this.createFilterBank(e,t,this.hzToLog,this.logToHz)}hzToBark(e){let t=26.81*e/(1960+e)-.53;return t<2&&(t+=.15*(2-t)),t>20.1&&(t+=.22*(t-20.1)),t}barkToHz(e){return e<2&&(e=(e-.3)/.85),e>20.1&&(e=(e+4.422)/1.22),(e+.53)/(26.28-e)*1960}createBarkFilterBank(e,t){return this.createFilterBank(e,t,this.hzToBark,this.barkToHz)}hzToErb(e){return n*Math.log10(1+.00437*e)}erbToHz(e){return(Math.pow(10,e/n)-1)/.00437}createErbFilterBank(e,t){return this.createFilterBank(e,t,this.hzToErb,this.erbToHz)}hzToScale(e){switch(this.scale){case"mel":return this.hzToMel(e);case"logarithmic":return this.hzToLog(e);case"bark":return this.hzToBark(e);case"erb":return this.hzToErb(e)}return e}scaleToHz(e){switch(this.scale){case"mel":return this.melToHz(e);case"logarithmic":return this.logToHz(e);case"bark":return this.barkToHz(e);case"erb":return this.erbToHz(e)}return e}applyFilterBank(e,t){const s=t.length,r=Float32Array.from({length:s},(()=>0));for(let i=0;i<s;i++)for(let s=0;s<e.length;s++)r[i]+=e[s]*t[i][s];return r}getWidth(){return this.wavesurfer.getWrapper().offsetWidth}getFrequencies(e){var t,s;const r=this.fftSamples,i=(null!==(t=this.options.splitChannels)&&void 0!==t?t:null===(s=this.wavesurfer)||void 0===s?void 0:s.options.splitChannels)?e.numberOfChannels:1;if(this.frequencyMax=this.frequencyMax||e.sampleRate/2,!e)return;this.buffer=e;const n=e.sampleRate,h=[];let o=this.noverlap;if(!o){const t=e.length/this.canvas.width;o=Math.max(0,Math.round(r-t))}const l=new a(r,n,this.windowFunc,this.alpha);let c;switch(this.scale){case"mel":c=this.createFilterBank(this.numMelFilters,n,this.hzToMel,this.melToHz);break;case"logarithmic":c=this.createFilterBank(this.numLogFilters,n,this.hzToLog,this.logToHz);break;case"bark":c=this.createFilterBank(this.numBarkFilters,n,this.hzToBark,this.barkToHz);break;case"erb":c=this.createFilterBank(this.numErbFilters,n,this.hzToErb,this.erbToHz)}for(let t=0;t<i;t++){const s=e.getChannelData(t),i=[];let a=0;for(;a+r<s.length;){const e=s.slice(a,a+r),t=new Uint8Array(r/2);let n=l.calculateSpectrum(e);c&&(n=this.applyFilterBank(n,c));for(let e=0;e<r/2;e++){const s=n[e]>1e-12?n[e]:1e-12,r=20*Math.log10(s);r<-this.gainDB-this.rangeDB?t[e]=0:r>-this.gainDB?t[e]=255:t[e]=(r+this.gainDB)/this.rangeDB*255+256}i.push(t),a+=r-o}h.push(i)}return this.frequencies=h,h}freqType(e){return e>=1e3?(e/1e3).toFixed(1):Math.round(e)}unitType(e){return e>=1e3?"kHz":"Hz"}getLabelFrequency(e,t){const s=this.hzToScale(this.frequencyMin),r=this.hzToScale(this.frequencyMax);return this.scaleToHz(s+e/t*(r-s))}loadLabels(e,t,s,r,i,a,n,h,o){e=e||"rgba(68,68,68,0)",t=t||"12px",s=s||"12px",r=r||"Helvetica",i=i||"#fff",a=a||"#fff",n=n||"center";const l=this.height||512,c=l/256*5;this.frequencyMin;this.frequencyMax;const u=this.labelsEl.getContext("2d"),f=window.devicePixelRatio;if(this.labelsEl.height=this.height*o*f,this.labelsEl.width=55*f,u.scale(f,f),u)for(let h=0;h<o;h++){let o;for(u.fillStyle=e,u.fillRect(0,h*l,55,(1+h)*l),u.fill(),o=0;o<=c;o++){u.textAlign=n,u.textBaseline="middle";const e=this.getLabelFrequency(o,c),f=this.freqType(e),p=this.unitType(e),d=16;let w=(1+h)*l-o/c*l;w=Math.min(Math.max(w,h*l+10),(1+h)*l-10),u.fillStyle=a,u.font=s+" "+r,u.fillText(p,d+24,w),u.fillStyle=i,u.font=t+" "+r,u.fillText(f,d,w)}}}resample(e){const t=this.getWidth(),s=[],r=1/e.length,i=1/t;let a;for(a=0;a<t;a++){const t=new Array(e[0].length);let n;for(n=0;n<e.length;n++){const s=n*r,h=s+r,o=a*i,l=o+i,c=Math.max(0,Math.min(h,l)-Math.max(s,o));let u;if(c>0)for(u=0;u<e[0].length;u++)null==t[u]&&(t[u]=0),t[u]+=c/i*e[n][u]}const h=new Uint8Array(e[0].length);let o;for(o=0;o<e[0].length;o++)h[o]=t[o];s.push(h)}return s}}return h}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e="undefined"!=typeof globalThis?globalThis:e||self).WaveSurfer=e.WaveSurfer||{},e.WaveSurfer.Spectrogram=t())}(this,(function(){"use strict";function e(e,t,s,i){return new(s||(s=Promise))((function(r,n){function a(e){try{l(i.next(e))}catch(e){n(e)}}function o(e){try{l(i.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(a,o)}l((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t=1e3*Math.log(10)/107.939;function s(e){return 2595*Math.log10(1+e/700)}function i(e){return 700*(Math.pow(10,e/2595)-1)}function r(e){return Math.log10(Math.max(1,e))}function n(e){return Math.pow(10,e)}function a(e){let t=26.81*e/(1960+e)-.53;return t<2&&(t+=.15*(2-t)),t>20.1&&(t+=.22*(t-20.1)),t}function o(e){return e<2&&(e=(e-.3)/.85),e>20.1&&(e=(e+4.422)/1.22),(e+.53)/(26.28-e)*1960}function l(e){return t*Math.log10(1+.00437*e)}function h(e){return(Math.pow(10,e/t)-1)/.00437}function c(e,t){switch(t){case"mel":return s(e);case"logarithmic":return r(e);case"bark":return a(e);case"erb":return l(e);default:return e}}function d(e,t,s,i,r){const n=i(0),a=i(s/2),o=Array.from({length:e},(()=>Array(t/2+1).fill(0))),l=s/t;for(let t=0;t<e;t++){let s=r(n+t/e*(a-n)),i=Math.floor(s/l),h=i*l,c=(s-h)/((i+1)*l-h);o[t][i]=1-c,o[t][i+1]=c}return o}function u(e,t){const s=t.length,i=Float32Array.from({length:s},(()=>0));for(let r=0;r<s;r++)for(let s=0;s<e.length;s++)i[r]+=e[s]*t[r][s];return i}const p={gray:()=>{const e=[];for(let t=0;t<256;t++){const s=(255-t)/256;e.push([s,s,s,1])}return e},igray:()=>{const e=[];for(let t=0;t<256;t++){const s=t/256;e.push([s,s,s,1])}return e},roseus:()=>[[.004528,.004341,.004307,1],[.005625,.006156,.00601,1],[.006628,.008293,.008161,1],[.007551,.010738,.01079,1],[.008382,.013482,.013941,1],[.009111,.01652,.017662,1],[.009727,.019846,.022009,1],[.010223,.023452,.027035,1],[.010593,.027331,.032799,1],[.010833,.031475,.039361,1],[.010941,.035875,.046415,1],[.010918,.04052,.053597,1],[.010768,.045158,.060914,1],[.010492,.049708,.068367,1],[.010098,.054171,.075954,1],[.009594,.058549,.083672,1],[.008989,.06284,.091521,1],[.008297,.067046,.099499,1],[.00753,.071165,.107603,1],[.006704,.075196,.11583,1],[.005838,.07914,.124178,1],[.004949,.082994,.132643,1],[.004062,.086758,.141223,1],[.003198,.09043,.149913,1],[.002382,.09401,.158711,1],[.001643,.097494,.167612,1],[.001009,.100883,.176612,1],[514e-6,.104174,.185704,1],[187e-6,.107366,.194886,1],[66e-6,.110457,.204151,1],[186e-6,.113445,.213496,1],[587e-6,.116329,.222914,1],[.001309,.119106,.232397,1],[.002394,.121776,.241942,1],[.003886,.124336,.251542,1],[.005831,.126784,.261189,1],[.008276,.12912,.270876,1],[.011268,.131342,.280598,1],[.014859,.133447,.290345,1],[.0191,.135435,.300111,1],[.024043,.137305,.309888,1],[.029742,.139054,.319669,1],[.036252,.140683,.329441,1],[.043507,.142189,.339203,1],[.050922,.143571,.348942,1],[.058432,.144831,.358649,1],[.066041,.145965,.368319,1],[.073744,.146974,.377938,1],[.081541,.147858,.387501,1],[.089431,.148616,.396998,1],[.097411,.149248,.406419,1],[.105479,.149754,.415755,1],[.113634,.150134,.424998,1],[.121873,.150389,.434139,1],[.130192,.150521,.443167,1],[.138591,.150528,.452075,1],[.147065,.150413,.460852,1],[.155614,.150175,.469493,1],[.164232,.149818,.477985,1],[.172917,.149343,.486322,1],[.181666,.148751,.494494,1],[.190476,.148046,.502493,1],[.199344,.147229,.510313,1],[.208267,.146302,.517944,1],[.217242,.145267,.52538,1],[.226264,.144131,.532613,1],[.235331,.142894,.539635,1],[.24444,.141559,.546442,1],[.253587,.140131,.553026,1],[.262769,.138615,.559381,1],[.271981,.137016,.5655,1],[.281222,.135335,.571381,1],[.290487,.133581,.577017,1],[.299774,.131757,.582404,1],[.30908,.129867,.587538,1],[.318399,.12792,.592415,1],[.32773,.125921,.597032,1],[.337069,.123877,.601385,1],[.346413,.121793,.605474,1],[.355758,.119678,.609295,1],[.365102,.11754,.612846,1],[.374443,.115386,.616127,1],[.383774,.113226,.619138,1],[.393096,.111066,.621876,1],[.402404,.108918,.624343,1],[.411694,.106794,.62654,1],[.420967,.104698,.628466,1],[.430217,.102645,.630123,1],[.439442,.100647,.631513,1],[.448637,.098717,.632638,1],[.457805,.096861,.633499,1],[.46694,.095095,.6341,1],[.47604,.093433,.634443,1],[.485102,.091885,.634532,1],[.494125,.090466,.63437,1],[.503104,.08919,.633962,1],[.512041,.088067,.633311,1],[.520931,.087108,.63242,1],[.529773,.086329,.631297,1],[.538564,.085738,.629944,1],[.547302,.085346,.628367,1],[.555986,.085162,.626572,1],[.564615,.08519,.624563,1],[.573187,.085439,.622345,1],[.581698,.085913,.619926,1],[.590149,.086615,.617311,1],[.598538,.087543,.614503,1],[.606862,.0887,.611511,1],[.61512,.090084,.608343,1],[.623312,.09169,.605001,1],[.631438,.093511,.601489,1],[.639492,.095546,.597821,1],[.647476,.097787,.593999,1],[.655389,.100226,.590028,1],[.66323,.102856,.585914,1],[.670995,.105669,.581667,1],[.678686,.108658,.577291,1],[.686302,.111813,.57279,1],[.69384,.115129,.568175,1],[.7013,.118597,.563449,1],[.708682,.122209,.558616,1],[.715984,.125959,.553687,1],[.723206,.12984,.548666,1],[.730346,.133846,.543558,1],[.737406,.13797,.538366,1],[.744382,.142209,.533101,1],[.751274,.146556,.527767,1],[.758082,.151008,.522369,1],[.764805,.155559,.516912,1],[.771443,.160206,.511402,1],[.777995,.164946,.505845,1],[.784459,.169774,.500246,1],[.790836,.174689,.494607,1],[.797125,.179688,.488935,1],[.803325,.184767,.483238,1],[.809435,.189925,.477518,1],[.815455,.19516,.471781,1],[.821384,.200471,.466028,1],[.827222,.205854,.460267,1],[.832968,.211308,.454505,1],[.838621,.216834,.448738,1],[.844181,.222428,.442979,1],[.849647,.22809,.43723,1],[.855019,.233819,.431491,1],[.860295,.239613,.425771,1],[.865475,.245471,.420074,1],[.870558,.251393,.414403,1],[.875545,.25738,.408759,1],[.880433,.263427,.403152,1],[.885223,.269535,.397585,1],[.889913,.275705,.392058,1],[.894503,.281934,.386578,1],[.898993,.288222,.381152,1],[.903381,.294569,.375781,1],[.907667,.300974,.370469,1],[.911849,.307435,.365223,1],[.915928,.313953,.360048,1],[.919902,.320527,.354948,1],[.923771,.327155,.349928,1],[.927533,.333838,.344994,1],[.931188,.340576,.340149,1],[.934736,.347366,.335403,1],[.938175,.354207,.330762,1],[.941504,.361101,.326229,1],[.944723,.368045,.321814,1],[.947831,.375039,.317523,1],[.950826,.382083,.313364,1],[.953709,.389175,.309345,1],[.956478,.396314,.305477,1],[.959133,.403499,.301766,1],[.961671,.410731,.298221,1],[.964093,.418008,.294853,1],[.966399,.425327,.291676,1],[.968586,.43269,.288696,1],[.970654,.440095,.285926,1],[.972603,.44754,.28338,1],[.974431,.455025,.281067,1],[.976139,.462547,.279003,1],[.977725,.470107,.277198,1],[.979188,.477703,.275666,1],[.980529,.485332,.274422,1],[.981747,.492995,.273476,1],[.98284,.50069,.272842,1],[.983808,.508415,.272532,1],[.984653,.516168,.27256,1],[.985373,.523948,.272937,1],[.985966,.531754,.273673,1],[.986436,.539582,.274779,1],[.98678,.547434,.276264,1],[.986998,.555305,.278135,1],[.987091,.563195,.280401,1],[.987061,.5711,.283066,1],[.986907,.579019,.286137,1],[.986629,.58695,.289615,1],[.986229,.594891,.293503,1],[.985709,.602839,.297802,1],[.985069,.610792,.302512,1],[.98431,.618748,.307632,1],[.983435,.626704,.313159,1],[.982445,.634657,.319089,1],[.981341,.642606,.32542,1],[.98013,.650546,.332144,1],[.978812,.658475,.339257,1],[.977392,.666391,.346753,1],[.97587,.67429,.354625,1],[.974252,.68217,.362865,1],[.972545,.690026,.371466,1],[.97075,.697856,.380419,1],[.968873,.705658,.389718,1],[.966921,.713426,.399353,1],[.964901,.721157,.409313,1],[.962815,.728851,.419594,1],[.960677,.7365,.430181,1],[.95849,.744103,.44107,1],[.956263,.751656,.452248,1],[.954009,.759153,.463702,1],[.951732,.766595,.475429,1],[.949445,.773974,.487414,1],[.947158,.781289,.499647,1],[.944885,.788535,.512116,1],[.942634,.795709,.524811,1],[.940423,.802807,.537717,1],[.938261,.809825,.550825,1],[.936163,.81676,.564121,1],[.934146,.823608,.577591,1],[.932224,.830366,.59122,1],[.930412,.837031,.604997,1],[.928727,.843599,.618904,1],[.927187,.850066,.632926,1],[.925809,.856432,.647047,1],[.92461,.862691,.661249,1],[.923607,.868843,.675517,1],[.92282,.874884,.689832,1],[.922265,.880812,.704174,1],[.921962,.886626,.718523,1],[.92193,.892323,.732859,1],[.922183,.897903,.747163,1],[.922741,.903364,.76141,1],[.92362,.908706,.77558,1],[.924837,.913928,.789648,1],[.926405,.919031,.80359,1],[.92834,.924015,.817381,1],[.930655,.928881,.830995,1],[.93336,.933631,.844405,1],[.936466,.938267,.857583,1],[.939982,.942791,.870499,1],[.943914,.947207,.883122,1],[.948267,.951519,.895421,1],[.953044,.955732,.907359,1],[.958246,.959852,.918901,1],[.963869,.963887,.930004,1],[.969909,.967845,.940623,1],[.976355,.971737,.950704,1],[.983195,.97558,.960181,1],[.990402,.979395,.968966,1],[.99793,.983217,.97692,1]]};function m(e){return e>=1e3?(e/1e3).toFixed(1):Math.round(e).toString()}function f(e){return e>=1e3?"kHz":"Hz"}function b(e,t,s,r,a){const l=c(s,a);return function(e,t){switch(t){case"mel":return i(e);case"logarithmic":return n(e);case"bark":return o(e);case"erb":return h(e);default:return e}}(l+e/t*(c(r,a)-l),a)}function y(e,t,s,i){switch(this.bufferSize=e,this.sampleRate=t,this.bandwidth=2/e*(t/2),this.sinTable=new Float32Array(e),this.cosTable=new Float32Array(e),this.windowValues=new Float32Array(e),this.reverseTable=new Uint32Array(e),this.peakBand=0,this.peak=0,s){case"bartlett":for(r=0;r<e;r++)this.windowValues[r]=2/(e-1)*((e-1)/2-Math.abs(r-(e-1)/2));break;case"bartlettHann":for(r=0;r<e;r++)this.windowValues[r]=.62-.48*Math.abs(r/(e-1)-.5)-.38*Math.cos(2*Math.PI*r/(e-1));break;case"blackman":for(i=i||.16,r=0;r<e;r++)this.windowValues[r]=(1-i)/2-.5*Math.cos(2*Math.PI*r/(e-1))+i/2*Math.cos(4*Math.PI*r/(e-1));break;case"cosine":for(r=0;r<e;r++)this.windowValues[r]=Math.cos(Math.PI*r/(e-1)-Math.PI/2);break;case"gauss":for(i=i||.25,r=0;r<e;r++)this.windowValues[r]=Math.pow(Math.E,-.5*Math.pow((r-(e-1)/2)/(i*(e-1)/2),2));break;case"hamming":for(r=0;r<e;r++)this.windowValues[r]=.54-.46*Math.cos(2*Math.PI*r/(e-1));break;case"hann":case void 0:for(r=0;r<e;r++)this.windowValues[r]=.5*(1-Math.cos(2*Math.PI*r/(e-1)));break;case"lanczoz":for(r=0;r<e;r++)this.windowValues[r]=Math.sin(Math.PI*(2*r/(e-1)-1))/(Math.PI*(2*r/(e-1)-1));break;case"rectangular":for(r=0;r<e;r++)this.windowValues[r]=1;break;case"triangular":for(r=0;r<e;r++)this.windowValues[r]=2/e*(e/2-Math.abs(r-(e-1)/2));break;default:throw Error("No such window function '"+s+"'")}for(var r,n=1,a=e>>1;n<e;){for(r=0;r<n;r++)this.reverseTable[r+n]=this.reverseTable[r]+a;n<<=1,a>>=1}for(r=0;r<e;r++)this.sinTable[r]=Math.sin(-Math.PI/r),this.cosTable[r]=Math.cos(-Math.PI/r);this.calculateSpectrum=function(e){var t,s,i,r=this.bufferSize,n=this.cosTable,a=this.sinTable,o=this.reverseTable,l=new Float32Array(r),h=new Float32Array(r),c=2/this.bufferSize,d=Math.sqrt,u=new Float32Array(r/2),p=Math.floor(Math.log(r)/Math.LN2);if(Math.pow(2,p)!==r)throw"Invalid buffer size, must be a power of 2.";if(r!==e.length)throw"Supplied buffer is not the same size as defined FFT. FFT Size: "+r+" Buffer Size: "+e.length;for(var m,f,b,y,M,w,v,g,W=1,Z=0;Z<r;Z++)l[Z]=e[o[Z]]*this.windowValues[o[Z]],h[Z]=0;for(;W<r;){m=n[W],f=a[W],b=1,y=0;for(var S=0;S<W;S++){for(Z=S;Z<r;)w=b*l[M=Z+W]-y*h[M],v=b*h[M]+y*l[M],l[M]=l[Z]-w,h[M]=h[Z]-v,l[Z]+=w,h[Z]+=v,Z+=W<<1;b=(g=b)*m-y*f,y=g*f+y*m}W<<=1}Z=0;for(var x=r/2;Z<x;Z++)(i=c*d((t=l[Z])*t+(s=h[Z])*s))>this.peak&&(this.peakBand=Z,this.peak=i),u[Z]=i;return u}}class M{constructor(){this.listeners={}}on(e,t,s){if(this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e].add(t),null==s?void 0:s.once){const s=()=>{this.un(e,s),this.un(e,t)};return this.on(e,s),s}return()=>this.un(e,t)}un(e,t){var s;null===(s=this.listeners[e])||void 0===s||s.delete(t)}once(e,t){return this.on(e,t,{once:!0})}unAll(){this.listeners={}}emit(e,...t){this.listeners[e]&&this.listeners[e].forEach((e=>e(...t)))}}class w extends M{constructor(e){super(),this.subscriptions=[],this.isDestroyed=!1,this.options=e}onInit(){}_init(e){this.isDestroyed&&(this.subscriptions=[],this.isDestroyed=!1),this.wavesurfer=e,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((e=>e())),this.subscriptions=[],this.isDestroyed=!0,this.wavesurfer=void 0}}function v(e,t){const s=t.xmlns?document.createElementNS(t.xmlns,e):document.createElement(e);for(const[e,i]of Object.entries(t))if("children"===e&&i)for(const[e,t]of Object.entries(i))t instanceof Node?s.appendChild(t):"string"==typeof t?s.appendChild(document.createTextNode(t)):s.appendChild(v(e,t));else"style"===e?Object.assign(s.style,i):"textContent"===e?s.textContent=i:s.setAttribute(e,i.toString());return s}function g(e,t,s){const i=v(e,t||{});return null==s||s.appendChild(i),i}var W=null;try{var Z="undefined"!=typeof module&&"function"==typeof module.require&&module.require("worker_threads")||"function"==typeof __non_webpack_require__&&__non_webpack_require__("worker_threads")||"function"==typeof require&&require("worker_threads");W=Z.Worker}catch(e){}function S(e,t,s){var i=function(e){return Buffer.from(e,"base64").toString("utf8")}(e),r=i.indexOf("\n",10)+1,n=i.substring(r)+"";return function(e){return new W(n,Object.assign({},e,{eval:!0}))}}function x(e,t,s){var i=function(e){return atob(e)}(e),r=i.indexOf("\n",10)+1,n=i.substring(r)+"",a=new Blob([n],{type:"application/javascript"});return URL.createObjectURL(a)}var X="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0);function T(e,t,s){return X?S(e):function(e){var t;return function(s){return t=t||x(e),new Worker(t,s)}}(e)}var k=T("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwohZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7Y29uc3QgdD0xZTMqTWF0aC5sb2coMTApLzEwNy45Mzk7ZnVuY3Rpb24gZSh0KXtyZXR1cm4gMjU5NSpNYXRoLmxvZzEwKDErdC83MDApfWZ1bmN0aW9uIGEodCl7cmV0dXJuIDcwMCooTWF0aC5wb3coMTAsdC8yNTk1KS0xKX1mdW5jdGlvbiByKHQpe3JldHVybiBNYXRoLmxvZzEwKE1hdGgubWF4KDEsdCkpfWZ1bmN0aW9uIHModCl7cmV0dXJuIE1hdGgucG93KDEwLHQpfWZ1bmN0aW9uIG4odCl7bGV0IGU9MjYuODEqdC8oMTk2MCt0KS0uNTM7cmV0dXJuIGU8MiYmKGUrPS4xNSooMi1lKSksZT4yMC4xJiYoZSs9LjIyKihlLTIwLjEpKSxlfWZ1bmN0aW9uIG8odCl7cmV0dXJuIHQ8MiYmKHQ9KHQtLjMpLy44NSksdD4yMC4xJiYodD0odCs0LjQyMikvMS4yMiksKHQrLjUzKS8oMjYuMjgtdCkqMTk2MH1mdW5jdGlvbiBpKGUpe3JldHVybiB0Kk1hdGgubG9nMTAoMSsuMDA0MzcqZSl9ZnVuY3Rpb24gaChlKXtyZXR1cm4oTWF0aC5wb3coMTAsZS90KS0xKS8uMDA0Mzd9ZnVuY3Rpb24gbCh0LGUsYSxyLHMpe2NvbnN0IG49cigwKSxvPXIoYS8yKSxpPUFycmF5LmZyb20o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oKTtkZWZhdWx0OnJldHVybiBudWxsfX0oeSxwLzIscCxkKTtsZXQgUz1rfHxNYXRoLm1heCgwLE1hdGgucm91bmQoLjUqcCkpO2NvbnN0IHo9LjUqcDtTPU1hdGgubWluKFMseik7Y29uc3QgQj1NYXRoLm1heCg2NCwuMjUqcCkscT1NYXRoLm1heChCLHAtUykseD1bXTtmb3IobGV0IGU9MDtlPEE7ZSsrKXtjb25zdCBhPXRbZV0scj1bXTtmb3IobGV0IHQ9STt0K3A8Vjt0Kz1xKXtjb25zdCBlPWEuc2xpY2UodCx0K3ApO2xldCBzPWYuY2FsY3VsYXRlU3BlY3RydW0oZSk7UCYmKHM9YyhzLFApKTtjb25zdCBuPW5ldyBVaW50OEFycmF5KHMubGVuZ3RoKSxvPVQrRjtmb3IobGV0IHQ9MDt0PHMubGVuZ3RoO3QrKyl7Y29uc3QgZT1zW3RdPjFlLTEyP3NbdF06MWUtMTIsYT0yMCpNYXRoLmxvZzEwKGUpO25bdF09YTwtbz8wOmE+LVQ/MjU1Ok1hdGgucm91bmQoKGErVCkvRioyNTUpfXIucHVzaChuKX14LnB1c2gocil9cmV0dXJuIHh9KGIsZCksTT17dHlwZToiZnJlcXVlbmNpZXNSZXN1bHQiLGlkOncscmVzdWx0OnR9O3NlbGYucG9zdE1lc3NhZ2UoTSl9Y2F0Y2godCl7Y29uc3QgZT17dHlwZToiZnJlcXVlbmNpZXNSZXN1bHQiLGlkOncsZXJyb3I6dCBpbnN0YW5jZW9mIEVycm9yP3QubWVzc2FnZTpTdHJpbmcodCl9O3NlbGYucG9zdE1lc3NhZ2UoZSl9fX0oKTsKLy8jIHNvdXJjZU1hcHBpbmdVUkw9c3BlY3Ryb2dyYW0td29ya2VyLmpzLm1hcAoK");class G extends w{static create(e){return new G(e||{})}constructor(e){var t,s;if(super(e),this.canvases=[],this.useWebWorker=!1,this.worker=null,this.workerPromises=new Map,this.cachedFrequencies=null,this.cachedResampledData=null,this.cachedBuffer=null,this.cachedWidth=0,this.renderTimeout=null,this.isRendering=!1,this.lastZoomLevel=0,this.renderThrottleMs=50,this.zoomThreshold=.05,this.drawnCanvases={},this.pendingBitmaps=new Set,this.isScrollable=!1,this.scrollUnsubscribe=null,this.frequenciesDataUrl=e.frequenciesDataUrl,this.frequenciesDataUrl&&!e.sampleRate)throw new Error("sampleRate option is required when using frequenciesDataUrl");this.container="string"==typeof e.container?document.querySelector(e.container):e.container,this.useWebWorker=!0===e.useWebWorker,this.colorMap=function(e="roseus"){if(e&&"string"!=typeof e){if(e.length<256)throw new Error("Colormap must contain 256 elements");for(let t=0;t<e.length;t++)if(4!==e[t].length)throw new Error("ColorMap entries must contain 4 values");return e}const t=p[e];if(!t)throw Error("No such colormap '"+e+"'");return t()}(e.colorMap),this.fftSamples=e.fftSamples||512,this.height=e.height||200,this.noverlap=e.noverlap||null,this.windowFunc=e.windowFunc||"hann",this.alpha=e.alpha,this.frequencyMin=e.frequencyMin||0,this.frequencyMax=e.frequencyMax||0,this.gainDB=null!==(t=e.gainDB)&&void 0!==t?t:20,this.rangeDB=null!==(s=e.rangeDB)&&void 0!==s?s:80,this.scale=e.scale||"mel",this.numMelFilters=this.fftSamples/2,this.numLogFilters=this.fftSamples/2,this.numBarkFilters=this.fftSamples/2,this.numErbFilters=this.fftSamples/2,e.maxCanvasWidth&&(G.MAX_CANVAS_WIDTH=e.maxCanvasWidth),this.renderThrottleMs=50,this.zoomThreshold=.05,this.createWrapper(),this.createCanvas(),this.useWebWorker&&this.initializeWorker()}initializeWorker(){if("undefined"!=typeof window&&"undefined"!=typeof Worker)try{this.worker=new k,this.worker.onmessage=e=>{const{type:t,id:s,result:i,error:r}=e.data;if("frequenciesResult"===t){const e=this.workerPromises.get(s);e&&(this.workerPromises.delete(s),r?e.reject(new Error(r)):e.resolve(i))}},this.worker.onerror=e=>{console.warn("Spectrogram worker error, falling back to main thread:",e),this.worker=null}}catch(e){console.warn("Failed to initialize worker, falling back to main thread:",e),this.worker=null}else console.warn("Worker not available in this environment, using main thread calculation")}onInit(){this.wrapper||this.createWrapper(),this.canvasContainer||this.createCanvas(),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.throttledRender()))),this.wavesurfer.getDecodedData()&&setTimeout((()=>{this.throttledRender()}),0)}destroy(){this.unAll(),this.wavesurfer&&("function"==typeof this._onReady&&this.wavesurfer.un("ready",this._onReady),"function"==typeof this._onRender&&this.wavesurfer.un("redraw",this._onRender)),this.renderTimeout&&(clearTimeout(this.renderTimeout),this.renderTimeout=null),this.scrollUnsubscribe&&(this.scrollUnsubscribe(),this.scrollUnsubscribe=null),this.pendingBitmaps.clear(),this.worker&&(this.worker.terminate(),this.worker=null),this.cachedFrequencies=null,this.cachedResampledData=null,this.cachedBuffer=null,this.clearCanvases(),this.canvasContainer&&(this.canvasContainer.remove(),this.canvasContainer=null),this.wrapper&&(this.wrapper.remove(),this.wrapper=null),this.labelsEl&&(this.labelsEl.remove(),this.labelsEl=null),this.container=null,this.isRendering=!1,this.lastZoomLevel=0,this.wavesurfer=null,this.util=null,this.options=null,super.destroy()}loadFrequenciesData(t){return e(this,void 0,void 0,(function*(){const e=yield fetch(t);if(!e.ok)throw new Error("Unable to fetch frequencies data");const s=yield e.json();this.drawSpectrogram(s)}))}clearCache(){this.cachedFrequencies=null,this.cachedResampledData=null,this.cachedBuffer=null,this.cachedWidth=0,this.lastZoomLevel=0}createWrapper(){var e,t;this.wrapper=g("div",{style:{display:"block",position:"relative",userSelect:"none"}}),this.options.labels&&(this.labelsEl=g("canvas",{part:"spec-labels",style:{position:"absolute",zIndex:9,width:"55px",height:"100%"}},this.wrapper)),this._onWrapperClick=(e=this.wrapper,t=this.emit.bind(this),s=>{const i=e.getBoundingClientRect(),r=s.clientX-i.left,n=i.width;t("click",r/n)}),this.wrapper.addEventListener("click",this._onWrapperClick)}createCanvas(){this.canvasContainer=g("div",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",zIndex:4}},this.wrapper)}createSingleCanvas(e,t,s){const i=g("canvas",{style:{position:"absolute",left:`${Math.round(s)}px`,top:"0",width:`${e}px`,height:`${t}px`,zIndex:4}});return i.width=Math.round(e),i.height=Math.round(t),this.canvasContainer.appendChild(i),i}clearCanvases(){this.canvases.forEach((e=>e.remove())),this.canvases=[],this.drawnCanvases={}}clearExcessCanvases(){Object.keys(this.drawnCanvases).length>G.MAX_NODES&&this.clearCanvases()}throttledRender(){var e;if(this.renderTimeout&&clearTimeout(this.renderTimeout),this.isRendering)return;const t=(null===(e=this.wavesurfer)||void 0===e?void 0:e.options.minPxPerSec)||0;Math.abs(t-this.lastZoomLevel)/Math.max(t,this.lastZoomLevel,1)<this.zoomThreshold&&this.cachedFrequencies?this.renderTimeout=window.setTimeout((()=>{this.fastRender()}),this.renderThrottleMs):this.renderTimeout=window.setTimeout((()=>{this.render()}),this.renderThrottleMs)}render(){return e(this,void 0,void 0,(function*(){var e,t;if(!this.isRendering){this.isRendering=!0;try{if(this.frequenciesDataUrl)yield this.loadFrequenciesData(this.frequenciesDataUrl);else{const t=null===(e=this.wavesurfer)||void 0===e?void 0:e.getDecodedData();if(t)if(this.cachedBuffer===t&&this.cachedFrequencies)this.drawSpectrogram(this.cachedFrequencies);else{const e=yield this.getFrequencies(t);this.cachedFrequencies=e,this.cachedBuffer=t,this.drawSpectrogram(e)}}this.lastZoomLevel=(null===(t=this.wavesurfer)||void 0===t?void 0:t.options.minPxPerSec)||0}finally{this.isRendering=!1}}}))}fastRender(){var e;if(!this.isRendering&&this.cachedFrequencies){this.isRendering=!0;try{this.drawSpectrogram(this.cachedFrequencies),this.lastZoomLevel=(null===(e=this.wavesurfer)||void 0===e?void 0:e.options.minPxPerSec)||0}finally{this.isRendering=!1}}}drawSpectrogram(e){var t,s,i;isNaN(e[0][0])||(e=[e]),this.clearCanvases();const r=this.height*e.length;this.wrapper.style.height=r+"px";const n=this.getWidth(),a=Math.min(G.MAX_CANVAS_WIDTH,n);if(0===n||0===r)return;const o=Math.ceil(n/a);let l;const h=(null===(t=e[0])||void 0===t?void 0:t.length)||0;n!==h?this.cachedResampledData&&this.cachedWidth===n?l=this.cachedResampledData:(l=this.efficientResample(e,n),this.cachedResampledData=l,this.cachedWidth=n):l=e;const c=(null===(s=this.buffer)||void 0===s?void 0:s.sampleRate)?this.buffer.sampleRate/2:(this.options.sampleRate||0)/2,d=this.frequencyMin,u=this.frequencyMax,p=u>c,m=p?this.colorMap[this.colorMap.length-1]:null,f=e=>{if(e<0||e>=o)return;if(this.drawnCanvases[e])return;this.drawnCanvases[e]=!0;const t=e*a,s=Math.min(a,n-t);if(s<=0)return;const i=this.createSingleCanvas(s,r,t);this.canvases.push(i);const h=i.getContext("2d");if(h){p&&m&&(h.fillStyle=`rgba(${255*m[0]}, ${255*m[1]}, ${255*m[2]}, ${m[3]})`,h.fillRect(0,0,s,r));for(let e=0;e<l.length;e++)this.drawSpectrogramSegment(l[e],h,s,this.height,e*this.height,t,n,c,d,u)}};if(this.isScrollable=n>this.getWrapperWidth(),this.scrollUnsubscribe&&(this.scrollUnsubscribe(),this.scrollUnsubscribe=null),!this.isScrollable||o<=3)for(let e=0;e<o;e++)f(e);else{const e=()=>{var e;const t=null===(e=this.wavesurfer)||void 0===e?void 0:e.getWrapper();if(!t)return;const s=t.scrollLeft||0,i=t.clientWidth||0,r=Math.max(0,s-.5*i),a=Math.min(n,s+1.5*i),l=Math.floor(r/n*o),h=Math.min(Math.ceil(a/n*o),o-1);Object.keys(this.drawnCanvases).length>G.MAX_NODES&&this.clearExcessCanvases();for(let e=l;e<=h;e++)f(e)};e();let t=null;const s=()=>{t&&clearTimeout(t),t=window.setTimeout(e,16)},r=null===(i=this.wavesurfer)||void 0===i?void 0:i.getWrapper();r&&(r.addEventListener("scroll",s,{passive:!0}),this.scrollUnsubscribe=()=>{r.removeEventListener("scroll",s),t&&clearTimeout(t)})}this.options.labels&&this.loadLabels(this.options.labelsBackground,"12px","12px","",this.options.labelsColor,this.options.labelsHzColor||this.options.labelsColor,"center","#specLabels",e.length),this.emit("ready")}drawSpectrogramSegment(e,t,s,i,r,n,a,o,l,h){const d=e[0].length,u=Math.floor(n/a*e.length),p=Math.min(Math.ceil((n+s)/a*e.length),e.length),m=e.slice(u,p);if(0===m.length)return;const f=m.length,b=new ImageData(f,d),y=b.data;this.fillImageDataQuality(y,m,f,d);const M=c(l,this.scale)/c(o,this.scale),w=c(h,this.scale)/c(o,this.scale),v=Math.min(1,w),g=createImageBitmap(b,0,Math.round(d*(1-v)),f,Math.round(d*(v-M)));this.pendingBitmaps.add(g),g.then((e=>{if(this.pendingBitmaps.delete(g),t.canvas.parentNode){const n=i*v/w,a=r+i*(1-v/w);t.drawImage(e,0,a,s,n),"close"in e&&e.close()}})).catch((e=>{this.pendingBitmaps.delete(g)}))}getWidth(){return this.wavesurfer.getWrapper().offsetWidth}getWrapperWidth(){var e,t;return(null===(t=null===(e=this.wavesurfer)||void 0===e?void 0:e.getWrapper())||void 0===t?void 0:t.clientWidth)||0}calculateFrequenciesWithWorker(t){return e(this,void 0,void 0,(function*(){var e,s;if(!this.worker)throw new Error("Worker not available");const i=this.fftSamples,r=(null!==(e=this.options.splitChannels)&&void 0!==e?e:null===(s=this.wavesurfer)||void 0===s?void 0:s.options.splitChannels)?t.numberOfChannels:1;let n=this.noverlap;if(!n){const e=this.getWidth(),s=t.length/e;n=Math.max(0,Math.round(i-s))}const a=[];for(let e=0;e<r;e++)a.push(t.getChannelData(e));const o=`${Date.now()}_${Math.random()}`,l=new Promise(((e,t)=>{this.workerPromises.set(o,{resolve:e,reject:t}),setTimeout((()=>{this.workerPromises.has(o)&&(this.workerPromises.delete(o),t(new Error("Worker timeout")))}),3e4)}));return this.worker.postMessage({type:"calculateFrequencies",id:o,audioData:a,options:{startTime:0,endTime:t.duration,sampleRate:t.sampleRate,fftSamples:this.fftSamples,windowFunc:this.windowFunc,alpha:this.alpha,noverlap:n,scale:this.scale,gainDB:this.gainDB,rangeDB:this.rangeDB,splitChannels:this.options.splitChannels||!1}}),l}))}getFrequencies(t){return e(this,void 0,void 0,(function*(){var e,c;if(this.frequencyMax=this.frequencyMax||t.sampleRate/2,this.buffer=t,!t)return[];if(this.useWebWorker&&this.worker)try{return yield this.calculateFrequenciesWithWorker(t)}catch(e){console.warn("Worker calculation failed, falling back to main thread:",e)}const p=this.fftSamples,m=(null!==(e=this.options.splitChannels)&&void 0!==e?e:null===(c=this.wavesurfer)||void 0===c?void 0:c.options.splitChannels)?t.numberOfChannels:1,f=t.sampleRate,b=[];let M=this.noverlap;if(!M){const e=this.getWidth(),s=t.length/e;M=Math.max(0,Math.round(p-s))}let w=M||Math.max(0,Math.round(.5*p));const v=.5*p;w=Math.min(w,v);const g=Math.max(64,.25*p),W=Math.max(g,p-w),Z=new y(p,f,this.windowFunc,this.alpha),S=this.fftSamples/2,x=function(e,t,c,u){switch(e){case"mel":return d(t,c,u,s,i);case"logarithmic":return d(t,c,u,r,n);case"bark":return d(t,c,u,a,o);case"erb":return d(t,c,u,l,h);default:return null}}(this.scale,S,this.fftSamples,f);for(let e=0;e<m;e++){const s=t.getChannelData(e),i=[];for(let e=0;e+p<s.length;e+=W){const t=s.slice(e,e+p);let r=Z.calculateSpectrum(t);x&&(r=u(r,x));const n=new Uint8Array(r.length),a=this.gainDB+this.rangeDB;for(let e=0;e<r.length;e++){const t=r[e]>1e-12?r[e]:1e-12,s=20*Math.log10(t);s<-a?n[e]=0:s>-this.gainDB?n[e]=255:n[e]=Math.round((s+this.gainDB)/this.rangeDB*255)}i.push(n)}b.push(i)}return b}))}loadLabels(e,t,s,i,r,n,a,o,l){e=e||"rgba(68,68,68,0)",t=t||"12px",s=s||"12px",i=i||"Helvetica",r=r||"#fff",n=n||"#fff",a=a||"center";const h=this.height||512,c=h/256*5;this.frequencyMin;this.frequencyMax;const d=this.labelsEl.getContext("2d"),u=window.devicePixelRatio;if(this.labelsEl.height=this.height*l*u,this.labelsEl.width=55*u,d.scale(u,u),d)for(let o=0;o<l;o++){let l;for(d.fillStyle=e,d.fillRect(0,o*h,55,(1+o)*h),d.fill(),l=0;l<=c;l++){d.textAlign=a,d.textBaseline="middle";const e=b(l,c,this.frequencyMin,this.frequencyMax,this.scale),u=m(e),p=f(e),y=16;let M=(1+o)*h-l/c*h;M=Math.min(Math.max(M,o*h+10),(1+o)*h-10),d.fillStyle=n,d.font=s+" "+i,d.fillText(p,y+24,M),d.fillStyle=r,d.font=t+" "+i,d.fillText(u,y,M)}}}efficientResample(e,t){return e.map((e=>this.resampleChannel(e,t)))}resampleChannel(e,t){var s;const i=e.length,r=(null===(s=e[0])||void 0===s?void 0:s.length)||0;if(i===t||0===t)return e;const n=i/t,a=new Array(t);if(n>=1)for(let s=0;s<t;s++){const t=Math.floor(s*n),o=Math.min(Math.ceil((s+1)*n),i),l=o-t,h=new Uint8Array(r);if(1===l)h.set(e[t]);else for(let s=0;s<r;s++){let i=0;for(let r=t;r<o;r++)i+=e[r][s];h[s]=Math.round(i/l)}a[s]=h}else for(let s=0;s<t;s++){const t=s*n,o=Math.floor(t),l=Math.min(o+1,i-1),h=t-o,c=new Uint8Array(r);if(0===h||o===l)c.set(e[o]);else{const t=e[o],s=e[l],i=1-h;for(let e=0;e<r;e++)c[e]=Math.round(t[e]*i+s[e]*h)}a[s]=c}return a}fillImageDataQuality(e,t,s,i){const r=this.colorMap;for(let n=0;n<s;n++){const a=t[n];for(let t=0;t<i;t++){const o=r[a[t]],l=4*((i-t-1)*s+n);e[l]=255*o[0],e[l+1]=255*o[1],e[l+2]=255*o[2],e[l+3]=255*o[3]}}}}return G.MAX_CANVAS_WIDTH=3e4,G.MAX_NODES=10,G}));
@@ -1 +1 @@
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&&s)for(const[t,e]of Object.entries(s))e instanceof Node?n.appendChild(e):"string"==typeof e?n.appendChild(document.createTextNode(e)):n.appendChild(i(t,e));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){return i(t,e||{})}const s={height:20,timeOffset:0,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 r extends e{constructor(t){super(t||{}),this.options=Object.assign({},s,t),this.timelineWrapper=this.initTimelineWrapper()}static create(t){return new r(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}virtualAppend(t,e,i){let n=!1;const s=(s,r)=>{if(!this.wavesurfer)return;const o=i.clientWidth,l=t>s&&t+o<r;l!==n&&(n=l,l?e.appendChild(i):i.remove())};if(!this.wavesurfer)return;const r=this.wavesurfer.getScroll(),o=r+this.wavesurfer.getWidth();s(r,o),this.subscriptions.push(this.wavesurfer.on("scroll",((t,e,i,n)=>{s(i,n)})))}initTimeline(){var t,e,i,s,r,o,l,a;const h=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,p=((null===(s=this.wavesurfer)||void 0===s?void 0:s.getWrapper().scrollWidth)||this.timelineWrapper.scrollWidth)/h,u=null!==(r=this.options.timeInterval)&&void 0!==r?r:this.defaultTimeInterval(p),c=null!==(o=this.options.primaryLabelInterval)&&void 0!==o?o:this.defaultPrimaryLabelInterval(p),d=this.options.primaryLabelSpacing,f=null!==(l=this.options.secondaryLabelInterval)&&void 0!==l?l:this.defaultSecondaryLabelInterval(p),m=this.options.secondaryLabelSpacing,v="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"},v?{position:"absolute",top:"0",left:"0",right:"0",zIndex:"2"}:{position:"relative"})});y.setAttribute("part","timeline"),"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 b=n("div",{style:{width:"0",height:"50%",display:"flex",flexDirection:"column",justifyContent:v?"flex-start":"flex-end",top:v?"0":"auto",bottom:v?"auto":"0",overflow:"visible",borderLeft:"1px solid currentColor",opacity:`${null!==(a=this.options.secondaryLabelOpacity)&&void 0!==a?a:.25}`,position:"absolute",zIndex:"1"}});for(let t=0,e=0;t<h;t+=u,e++){const i=b.cloneNode(),n=Math.round(100*t)%Math.round(100*c)==0||d&&e%d==0,s=Math.round(100*t)%Math.round(100*f)==0||m&&e%m==0;(n||s)&&(i.style.height="100%",i.style.textIndent="3px",i.textContent=this.options.formatTimeCallback(t),n&&(i.style.opacity="1"));const r=n?"primary":s?"secondary":"tick";i.setAttribute("part",`timeline-notch timeline-notch-${r}`);const o=Math.round(100*(t+this.options.timeOffset))/100*p;i.style.left=`${o}px`,this.virtualAppend(o,y,i)}this.timelineWrapper.innerHTML="",this.timelineWrapper.appendChild(y),this.emit("ready")}}module.exports=r;
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.isDestroyed=!1,this.options=t}onInit(){}_init(t){this.isDestroyed&&(this.subscriptions=[],this.isDestroyed=!1),this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t())),this.subscriptions=[],this.isDestroyed=!0,this.wavesurfer=void 0}}function i(t,e){const s=e.xmlns?document.createElementNS(e.xmlns,t):document.createElement(t);for(const[t,n]of Object.entries(e))if("children"===t&&n)for(const[t,e]of Object.entries(n))e instanceof Node?s.appendChild(e):"string"==typeof e?s.appendChild(document.createTextNode(e)):s.appendChild(i(t,e));else"style"===t?Object.assign(s.style,n):"textContent"===t?s.textContent=n:s.setAttribute(t,n.toString());return s}function s(t,e,s){return i(t,e||{})}const n={height:20,timeOffset:0,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 r extends e{constructor(t){super(t||{}),this.options=Object.assign({},n,t),this.timelineWrapper=this.initTimelineWrapper()}static create(t){return new r(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 s("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}virtualAppend(t,e,i){let s=!1;const n=(n,r)=>{if(!this.wavesurfer)return;const o=i.clientWidth,l=t>=n&&t+o<r;l!==s&&(s=l,l?e.appendChild(i):i.remove())};if(!this.wavesurfer)return;const r=this.wavesurfer.getScroll(),o=r+this.wavesurfer.getWidth();n(r,o),this.subscriptions.push(this.wavesurfer.on("scroll",((t,e,i,s)=>{n(i,s)})))}initTimeline(){var t,e,i,n,r,o,l,a;const h=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,p=((null===(n=this.wavesurfer)||void 0===n?void 0:n.getWrapper().scrollWidth)||this.timelineWrapper.scrollWidth)/h,u=null!==(r=this.options.timeInterval)&&void 0!==r?r:this.defaultTimeInterval(p),d=null!==(o=this.options.primaryLabelInterval)&&void 0!==o?o:this.defaultPrimaryLabelInterval(p),c=this.options.primaryLabelSpacing,f=null!==(l=this.options.secondaryLabelInterval)&&void 0!==l?l:this.defaultSecondaryLabelInterval(p),v=this.options.secondaryLabelSpacing,m="beforebegin"===this.options.insertPosition,y=s("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"})});y.setAttribute("part","timeline"),"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 b=s("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!==(a=this.options.secondaryLabelOpacity)&&void 0!==a?a:.25}`,position:"absolute",zIndex:"1"}});for(let t=0,e=0;t<h;t+=u,e++){const i=b.cloneNode(),s=Math.round(100*t)%Math.round(100*d)==0||c&&e%c==0,n=Math.round(100*t)%Math.round(100*f)==0||v&&e%v==0;(s||n)&&(i.style.height="100%",i.style.textIndent="3px",i.textContent=this.options.formatTimeCallback(t),s&&(i.style.opacity="1"));const r=s?"primary":n?"secondary":"tick";i.setAttribute("part",`timeline-notch timeline-notch-${r}`);const o=Math.round(100*(t+this.options.timeOffset))/100*p;i.style.left=`${o}px`,this.virtualAppend(o,y,i)}this.timelineWrapper.innerHTML="",this.timelineWrapper.appendChild(y),this.emit("ready")}}module.exports=r;
@@ -1 +1 @@
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&&s)for(const[t,e]of Object.entries(s))e instanceof Node?n.appendChild(e):"string"==typeof e?n.appendChild(document.createTextNode(e)):n.appendChild(i(t,e));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){return i(t,e||{})}const s={height:20,timeOffset:0,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 r extends e{constructor(t){super(t||{}),this.options=Object.assign({},s,t),this.timelineWrapper=this.initTimelineWrapper()}static create(t){return new r(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}virtualAppend(t,e,i){let n=!1;const s=(s,r)=>{if(!this.wavesurfer)return;const o=i.clientWidth,l=t>s&&t+o<r;l!==n&&(n=l,l?e.appendChild(i):i.remove())};if(!this.wavesurfer)return;const r=this.wavesurfer.getScroll(),o=r+this.wavesurfer.getWidth();s(r,o),this.subscriptions.push(this.wavesurfer.on("scroll",((t,e,i,n)=>{s(i,n)})))}initTimeline(){var t,e,i,s,r,o,l,a;const h=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,p=((null===(s=this.wavesurfer)||void 0===s?void 0:s.getWrapper().scrollWidth)||this.timelineWrapper.scrollWidth)/h,u=null!==(r=this.options.timeInterval)&&void 0!==r?r:this.defaultTimeInterval(p),d=null!==(o=this.options.primaryLabelInterval)&&void 0!==o?o:this.defaultPrimaryLabelInterval(p),c=this.options.primaryLabelSpacing,f=null!==(l=this.options.secondaryLabelInterval)&&void 0!==l?l:this.defaultSecondaryLabelInterval(p),v=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"})});y.setAttribute("part","timeline"),"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 b=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!==(a=this.options.secondaryLabelOpacity)&&void 0!==a?a:.25}`,position:"absolute",zIndex:"1"}});for(let t=0,e=0;t<h;t+=u,e++){const i=b.cloneNode(),n=Math.round(100*t)%Math.round(100*d)==0||c&&e%c==0,s=Math.round(100*t)%Math.round(100*f)==0||v&&e%v==0;(n||s)&&(i.style.height="100%",i.style.textIndent="3px",i.textContent=this.options.formatTimeCallback(t),n&&(i.style.opacity="1"));const r=n?"primary":s?"secondary":"tick";i.setAttribute("part",`timeline-notch timeline-notch-${r}`);const o=Math.round(100*(t+this.options.timeOffset))/100*p;i.style.left=`${o}px`,this.virtualAppend(o,y,i)}this.timelineWrapper.innerHTML="",this.timelineWrapper.appendChild(y),this.emit("ready")}}export{r as default};
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.isDestroyed=!1,this.options=t}onInit(){}_init(t){this.isDestroyed&&(this.subscriptions=[],this.isDestroyed=!1),this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t())),this.subscriptions=[],this.isDestroyed=!0,this.wavesurfer=void 0}}function i(t,e){const s=e.xmlns?document.createElementNS(e.xmlns,t):document.createElement(t);for(const[t,n]of Object.entries(e))if("children"===t&&n)for(const[t,e]of Object.entries(n))e instanceof Node?s.appendChild(e):"string"==typeof e?s.appendChild(document.createTextNode(e)):s.appendChild(i(t,e));else"style"===t?Object.assign(s.style,n):"textContent"===t?s.textContent=n:s.setAttribute(t,n.toString());return s}function s(t,e,s){return i(t,e||{})}const n={height:20,timeOffset:0,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 r extends e{constructor(t){super(t||{}),this.options=Object.assign({},n,t),this.timelineWrapper=this.initTimelineWrapper()}static create(t){return new r(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 s("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}virtualAppend(t,e,i){let s=!1;const n=(n,r)=>{if(!this.wavesurfer)return;const o=i.clientWidth,l=t>=n&&t+o<r;l!==s&&(s=l,l?e.appendChild(i):i.remove())};if(!this.wavesurfer)return;const r=this.wavesurfer.getScroll(),o=r+this.wavesurfer.getWidth();n(r,o),this.subscriptions.push(this.wavesurfer.on("scroll",((t,e,i,s)=>{n(i,s)})))}initTimeline(){var t,e,i,n,r,o,l,a;const h=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,p=((null===(n=this.wavesurfer)||void 0===n?void 0:n.getWrapper().scrollWidth)||this.timelineWrapper.scrollWidth)/h,u=null!==(r=this.options.timeInterval)&&void 0!==r?r:this.defaultTimeInterval(p),d=null!==(o=this.options.primaryLabelInterval)&&void 0!==o?o:this.defaultPrimaryLabelInterval(p),c=this.options.primaryLabelSpacing,f=null!==(l=this.options.secondaryLabelInterval)&&void 0!==l?l:this.defaultSecondaryLabelInterval(p),v=this.options.secondaryLabelSpacing,m="beforebegin"===this.options.insertPosition,y=s("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"})});y.setAttribute("part","timeline"),"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 b=s("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!==(a=this.options.secondaryLabelOpacity)&&void 0!==a?a:.25}`,position:"absolute",zIndex:"1"}});for(let t=0,e=0;t<h;t+=u,e++){const i=b.cloneNode(),s=Math.round(100*t)%Math.round(100*d)==0||c&&e%c==0,n=Math.round(100*t)%Math.round(100*f)==0||v&&e%v==0;(s||n)&&(i.style.height="100%",i.style.textIndent="3px",i.textContent=this.options.formatTimeCallback(t),s&&(i.style.opacity="1"));const r=s?"primary":n?"secondary":"tick";i.setAttribute("part",`timeline-notch timeline-notch-${r}`);const o=Math.round(100*(t+this.options.timeOffset))/100*p;i.style.left=`${o}px`,this.virtualAppend(o,y,i)}this.timelineWrapper.innerHTML="",this.timelineWrapper.appendChild(y),this.emit("ready")}}export{r as default};
@@ -1 +1 @@
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&&s)for(const[t,e]of Object.entries(s))e instanceof Node?n.appendChild(e):"string"==typeof e?n.appendChild(document.createTextNode(e)):n.appendChild(i(t,e));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){return i(t,e||{})}const s={height:20,timeOffset:0,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 r extends e{constructor(t){super(t||{}),this.options=Object.assign({},s,t),this.timelineWrapper=this.initTimelineWrapper()}static create(t){return new r(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}virtualAppend(t,e,i){let n=!1;const s=(s,r)=>{if(!this.wavesurfer)return;const o=i.clientWidth,l=t>s&&t+o<r;l!==n&&(n=l,l?e.appendChild(i):i.remove())};if(!this.wavesurfer)return;const r=this.wavesurfer.getScroll(),o=r+this.wavesurfer.getWidth();s(r,o),this.subscriptions.push(this.wavesurfer.on("scroll",((t,e,i,n)=>{s(i,n)})))}initTimeline(){var t,e,i,s,r,o,l,a;const h=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,p=((null===(s=this.wavesurfer)||void 0===s?void 0:s.getWrapper().scrollWidth)||this.timelineWrapper.scrollWidth)/h,u=null!==(r=this.options.timeInterval)&&void 0!==r?r:this.defaultTimeInterval(p),d=null!==(o=this.options.primaryLabelInterval)&&void 0!==o?o:this.defaultPrimaryLabelInterval(p),c=this.options.primaryLabelSpacing,f=null!==(l=this.options.secondaryLabelInterval)&&void 0!==l?l:this.defaultSecondaryLabelInterval(p),v=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"})});y.setAttribute("part","timeline"),"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 b=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!==(a=this.options.secondaryLabelOpacity)&&void 0!==a?a:.25}`,position:"absolute",zIndex:"1"}});for(let t=0,e=0;t<h;t+=u,e++){const i=b.cloneNode(),n=Math.round(100*t)%Math.round(100*d)==0||c&&e%c==0,s=Math.round(100*t)%Math.round(100*f)==0||v&&e%v==0;(n||s)&&(i.style.height="100%",i.style.textIndent="3px",i.textContent=this.options.formatTimeCallback(t),n&&(i.style.opacity="1"));const r=n?"primary":s?"secondary":"tick";i.setAttribute("part",`timeline-notch timeline-notch-${r}`);const o=Math.round(100*(t+this.options.timeOffset))/100*p;i.style.left=`${o}px`,this.virtualAppend(o,y,i)}this.timelineWrapper.innerHTML="",this.timelineWrapper.appendChild(y),this.emit("ready")}}export{r as default};
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.isDestroyed=!1,this.options=t}onInit(){}_init(t){this.isDestroyed&&(this.subscriptions=[],this.isDestroyed=!1),this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t())),this.subscriptions=[],this.isDestroyed=!0,this.wavesurfer=void 0}}function i(t,e){const s=e.xmlns?document.createElementNS(e.xmlns,t):document.createElement(t);for(const[t,n]of Object.entries(e))if("children"===t&&n)for(const[t,e]of Object.entries(n))e instanceof Node?s.appendChild(e):"string"==typeof e?s.appendChild(document.createTextNode(e)):s.appendChild(i(t,e));else"style"===t?Object.assign(s.style,n):"textContent"===t?s.textContent=n:s.setAttribute(t,n.toString());return s}function s(t,e,s){return i(t,e||{})}const n={height:20,timeOffset:0,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 r extends e{constructor(t){super(t||{}),this.options=Object.assign({},n,t),this.timelineWrapper=this.initTimelineWrapper()}static create(t){return new r(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 s("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}virtualAppend(t,e,i){let s=!1;const n=(n,r)=>{if(!this.wavesurfer)return;const o=i.clientWidth,l=t>=n&&t+o<r;l!==s&&(s=l,l?e.appendChild(i):i.remove())};if(!this.wavesurfer)return;const r=this.wavesurfer.getScroll(),o=r+this.wavesurfer.getWidth();n(r,o),this.subscriptions.push(this.wavesurfer.on("scroll",((t,e,i,s)=>{n(i,s)})))}initTimeline(){var t,e,i,n,r,o,l,a;const h=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,p=((null===(n=this.wavesurfer)||void 0===n?void 0:n.getWrapper().scrollWidth)||this.timelineWrapper.scrollWidth)/h,u=null!==(r=this.options.timeInterval)&&void 0!==r?r:this.defaultTimeInterval(p),d=null!==(o=this.options.primaryLabelInterval)&&void 0!==o?o:this.defaultPrimaryLabelInterval(p),c=this.options.primaryLabelSpacing,f=null!==(l=this.options.secondaryLabelInterval)&&void 0!==l?l:this.defaultSecondaryLabelInterval(p),v=this.options.secondaryLabelSpacing,m="beforebegin"===this.options.insertPosition,y=s("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"})});y.setAttribute("part","timeline"),"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 b=s("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!==(a=this.options.secondaryLabelOpacity)&&void 0!==a?a:.25}`,position:"absolute",zIndex:"1"}});for(let t=0,e=0;t<h;t+=u,e++){const i=b.cloneNode(),s=Math.round(100*t)%Math.round(100*d)==0||c&&e%c==0,n=Math.round(100*t)%Math.round(100*f)==0||v&&e%v==0;(s||n)&&(i.style.height="100%",i.style.textIndent="3px",i.textContent=this.options.formatTimeCallback(t),s&&(i.style.opacity="1"));const r=s?"primary":n?"secondary":"tick";i.setAttribute("part",`timeline-notch timeline-notch-${r}`);const o=Math.round(100*(t+this.options.timeOffset))/100*p;i.style.left=`${o}px`,this.virtualAppend(o,y,i)}this.timelineWrapper.innerHTML="",this.timelineWrapper.appendChild(y),this.emit("ready")}}export{r 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={}}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&&s)for(const[t,e]of Object.entries(s))e instanceof Node?n.appendChild(e):"string"==typeof e?n.appendChild(document.createTextNode(e)):n.appendChild(i(t,e));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){return i(t,e||{})}const s={height:20,timeOffset:0,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}virtualAppend(t,e,i){let n=!1;const s=(s,o)=>{if(!this.wavesurfer)return;const r=i.clientWidth,l=t>s&&t+r<o;l!==n&&(n=l,l?e.appendChild(i):i.remove())};if(!this.wavesurfer)return;const o=this.wavesurfer.getScroll(),r=o+this.wavesurfer.getWidth();s(o,r),this.subscriptions.push(this.wavesurfer.on("scroll",((t,e,i,n)=>{s(i,n)})))}initTimeline(){var t,e,i,s,o,r,l,a;const h=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,p=((null===(s=this.wavesurfer)||void 0===s?void 0:s.getWrapper().scrollWidth)||this.timelineWrapper.scrollWidth)/h,u=null!==(o=this.options.timeInterval)&&void 0!==o?o:this.defaultTimeInterval(p),d=null!==(r=this.options.primaryLabelInterval)&&void 0!==r?r:this.defaultPrimaryLabelInterval(p),c=this.options.primaryLabelSpacing,f=null!==(l=this.options.secondaryLabelInterval)&&void 0!==l?l:this.defaultSecondaryLabelInterval(p),m=this.options.secondaryLabelSpacing,v="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"},v?{position:"absolute",top:"0",left:"0",right:"0",zIndex:"2"}:{position:"relative"})});y.setAttribute("part","timeline"),"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 b=n("div",{style:{width:"0",height:"50%",display:"flex",flexDirection:"column",justifyContent:v?"flex-start":"flex-end",top:v?"0":"auto",bottom:v?"auto":"0",overflow:"visible",borderLeft:"1px solid currentColor",opacity:`${null!==(a=this.options.secondaryLabelOpacity)&&void 0!==a?a:.25}`,position:"absolute",zIndex:"1"}});for(let t=0,e=0;t<h;t+=u,e++){const i=b.cloneNode(),n=Math.round(100*t)%Math.round(100*d)==0||c&&e%c==0,s=Math.round(100*t)%Math.round(100*f)==0||m&&e%m==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}`);const r=Math.round(100*(t+this.options.timeOffset))/100*p;i.style.left=`${r}px`,this.virtualAppend(r,y,i)}this.timelineWrapper.innerHTML="",this.timelineWrapper.appendChild(y),this.emit("ready")}}return o}));
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.isDestroyed=!1,this.options=t}onInit(){}_init(t){this.isDestroyed&&(this.subscriptions=[],this.isDestroyed=!1),this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t())),this.subscriptions=[],this.isDestroyed=!0,this.wavesurfer=void 0}}function i(t,e){const s=e.xmlns?document.createElementNS(e.xmlns,t):document.createElement(t);for(const[t,n]of Object.entries(e))if("children"===t&&n)for(const[t,e]of Object.entries(n))e instanceof Node?s.appendChild(e):"string"==typeof e?s.appendChild(document.createTextNode(e)):s.appendChild(i(t,e));else"style"===t?Object.assign(s.style,n):"textContent"===t?s.textContent=n:s.setAttribute(t,n.toString());return s}function s(t,e,s){return i(t,e||{})}const n={height:20,timeOffset:0,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({},n,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 s("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}virtualAppend(t,e,i){let s=!1;const n=(n,o)=>{if(!this.wavesurfer)return;const r=i.clientWidth,l=t>=n&&t+r<o;l!==s&&(s=l,l?e.appendChild(i):i.remove())};if(!this.wavesurfer)return;const o=this.wavesurfer.getScroll(),r=o+this.wavesurfer.getWidth();n(o,r),this.subscriptions.push(this.wavesurfer.on("scroll",((t,e,i,s)=>{n(i,s)})))}initTimeline(){var t,e,i,n,o,r,l,a;const h=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,p=((null===(n=this.wavesurfer)||void 0===n?void 0:n.getWrapper().scrollWidth)||this.timelineWrapper.scrollWidth)/h,u=null!==(o=this.options.timeInterval)&&void 0!==o?o:this.defaultTimeInterval(p),d=null!==(r=this.options.primaryLabelInterval)&&void 0!==r?r:this.defaultPrimaryLabelInterval(p),c=this.options.primaryLabelSpacing,f=null!==(l=this.options.secondaryLabelInterval)&&void 0!==l?l:this.defaultSecondaryLabelInterval(p),v=this.options.secondaryLabelSpacing,m="beforebegin"===this.options.insertPosition,y=s("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"})});y.setAttribute("part","timeline"),"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 b=s("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!==(a=this.options.secondaryLabelOpacity)&&void 0!==a?a:.25}`,position:"absolute",zIndex:"1"}});for(let t=0,e=0;t<h;t+=u,e++){const i=b.cloneNode(),s=Math.round(100*t)%Math.round(100*d)==0||c&&e%c==0,n=Math.round(100*t)%Math.round(100*f)==0||v&&e%v==0;(s||n)&&(i.style.height="100%",i.style.textIndent="3px",i.textContent=this.options.formatTimeCallback(t),s&&(i.style.opacity="1"));const o=s?"primary":n?"secondary":"tick";i.setAttribute("part",`timeline-notch timeline-notch-${o}`);const r=Math.round(100*(t+this.options.timeOffset))/100*p;i.style.left=`${r}px`,this.virtualAppend(r,y,i)}this.timelineWrapper.innerHTML="",this.timelineWrapper.appendChild(y),this.emit("ready")}}return o}));
@@ -1 +1 @@
1
- "use strict";class t{constructor(){this.listeners={}}on(t,s,e){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(s),null==e?void 0:e.once){const e=()=>{this.un(t,e),this.un(t,s)};return this.on(t,e),e}return()=>this.un(t,s)}un(t,s){var e;null===(e=this.listeners[t])||void 0===e||e.delete(s)}once(t,s){return this.on(t,s,{once:!0})}unAll(){this.listeners={}}emit(t,...s){this.listeners[t]&&this.listeners[t].forEach((t=>t(...s)))}}class s 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 e={scale:.5,deltaThreshold:5,exponentialZooming:!1,iterations:20};class i extends s{constructor(t){super(t||{}),this.wrapper=void 0,this.container=null,this.accumulatedDelta=0,this.pointerTime=0,this.oldX=0,this.endZoom=0,this.startZoom=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.startZoom&&this.options.exponentialZooming&&(this.startZoom=this.wavesurfer.getWrapper().clientWidth/this.wavesurfer.getDuration()),0===this.options.deltaThreshold||Math.abs(this.accumulatedDelta)>=this.options.deltaThreshold)){const s=this.wavesurfer.getDuration(),e=0===this.wavesurfer.options.minPxPerSec?this.wavesurfer.getWrapper().scrollWidth/s:this.wavesurfer.options.minPxPerSec,i=t.clientX-this.container.getBoundingClientRect().left,o=this.container.clientWidth,n=this.wavesurfer.getScroll();i===this.oldX&&0!==this.oldX||(this.pointerTime=(n+i)/e),this.oldX=i;const r=this.calculateNewZoom(e,this.accumulatedDelta),h=o/r*(i/o);r*s<o?(this.wavesurfer.zoom(o/s),this.container.scrollLeft=0):(this.wavesurfer.zoom(r),this.container.scrollLeft=(this.pointerTime-h)*r),this.accumulatedDelta=0}},this.calculateNewZoom=(t,s)=>{let e;if(this.options.exponentialZooming){const i=s>0?Math.pow(this.endZoom/this.startZoom,1/(this.options.iterations-1)):Math.pow(this.startZoom/this.endZoom,1/(this.options.iterations-1));e=Math.max(0,t*i)}else e=Math.max(0,t+s*this.options.scale);return Math.min(e,this.options.maxZoom)},this.options=Object.assign({},e,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.container.addEventListener("wheel",this.onWheel),void 0===this.options.maxZoom&&(this.options.maxZoom=this.container.clientWidth),this.endZoom=this.options.maxZoom)}destroy(){this.wrapper&&this.wrapper.removeEventListener("wheel",this.onWheel),super.destroy()}}module.exports=i;
1
+ "use strict";class t{constructor(){this.listeners={}}on(t,s,e){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(s),null==e?void 0:e.once){const e=()=>{this.un(t,e),this.un(t,s)};return this.on(t,e),e}return()=>this.un(t,s)}un(t,s){var e;null===(e=this.listeners[t])||void 0===e||e.delete(s)}once(t,s){return this.on(t,s,{once:!0})}unAll(){this.listeners={}}emit(t,...s){this.listeners[t]&&this.listeners[t].forEach((t=>t(...s)))}}class s extends t{constructor(t){super(),this.subscriptions=[],this.isDestroyed=!1,this.options=t}onInit(){}_init(t){this.isDestroyed&&(this.subscriptions=[],this.isDestroyed=!1),this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t())),this.subscriptions=[],this.isDestroyed=!0,this.wavesurfer=void 0}}const e={scale:.5,deltaThreshold:5,exponentialZooming:!1,iterations:20};class i extends s{constructor(t){super(t||{}),this.wrapper=void 0,this.container=null,this.accumulatedDelta=0,this.pointerTime=0,this.oldX=0,this.endZoom=0,this.startZoom=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.startZoom&&this.options.exponentialZooming&&(this.startZoom=this.wavesurfer.getWrapper().clientWidth/this.wavesurfer.getDuration()),0===this.options.deltaThreshold||Math.abs(this.accumulatedDelta)>=this.options.deltaThreshold)){const s=this.wavesurfer.getDuration(),e=0===this.wavesurfer.options.minPxPerSec?this.wavesurfer.getWrapper().scrollWidth/s:this.wavesurfer.options.minPxPerSec,i=t.clientX-this.container.getBoundingClientRect().left,o=this.container.clientWidth,n=this.wavesurfer.getScroll();i===this.oldX&&0!==this.oldX||(this.pointerTime=(n+i)/e),this.oldX=i;const r=this.calculateNewZoom(e,this.accumulatedDelta),h=o/r*(i/o);r*s<o?(this.wavesurfer.zoom(o/s),this.container.scrollLeft=0):(this.wavesurfer.zoom(r),this.container.scrollLeft=(this.pointerTime-h)*r),this.accumulatedDelta=0}},this.calculateNewZoom=(t,s)=>{let e;if(this.options.exponentialZooming){const i=s>0?Math.pow(this.endZoom/this.startZoom,1/(this.options.iterations-1)):Math.pow(this.startZoom/this.endZoom,1/(this.options.iterations-1));e=Math.max(0,t*i)}else e=Math.max(0,t+s*this.options.scale);return Math.min(e,this.options.maxZoom)},this.options=Object.assign({},e,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.container.addEventListener("wheel",this.onWheel),void 0===this.options.maxZoom&&(this.options.maxZoom=this.container.clientWidth),this.endZoom=this.options.maxZoom)}destroy(){this.wrapper&&this.wrapper.removeEventListener("wheel",this.onWheel),super.destroy()}}module.exports=i;
@@ -1 +1 @@
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,exponentialZooming:!1,iterations:20};class i extends e{constructor(t){super(t||{}),this.wrapper=void 0,this.container=null,this.accumulatedDelta=0,this.pointerTime=0,this.oldX=0,this.endZoom=0,this.startZoom=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.startZoom&&this.options.exponentialZooming&&(this.startZoom=this.wavesurfer.getWrapper().clientWidth/this.wavesurfer.getDuration()),0===this.options.deltaThreshold||Math.abs(this.accumulatedDelta)>=this.options.deltaThreshold)){const e=this.wavesurfer.getDuration(),s=0===this.wavesurfer.options.minPxPerSec?this.wavesurfer.getWrapper().scrollWidth/e:this.wavesurfer.options.minPxPerSec,i=t.clientX-this.container.getBoundingClientRect().left,o=this.container.clientWidth,n=this.wavesurfer.getScroll();i===this.oldX&&0!==this.oldX||(this.pointerTime=(n+i)/s),this.oldX=i;const r=this.calculateNewZoom(s,this.accumulatedDelta),h=o/r*(i/o);r*e<o?(this.wavesurfer.zoom(o/e),this.container.scrollLeft=0):(this.wavesurfer.zoom(r),this.container.scrollLeft=(this.pointerTime-h)*r),this.accumulatedDelta=0}},this.calculateNewZoom=(t,e)=>{let s;if(this.options.exponentialZooming){const i=e>0?Math.pow(this.endZoom/this.startZoom,1/(this.options.iterations-1)):Math.pow(this.startZoom/this.endZoom,1/(this.options.iterations-1));s=Math.max(0,t*i)}else s=Math.max(0,t+e*this.options.scale);return 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.container.addEventListener("wheel",this.onWheel),void 0===this.options.maxZoom&&(this.options.maxZoom=this.container.clientWidth),this.endZoom=this.options.maxZoom)}destroy(){this.wrapper&&this.wrapper.removeEventListener("wheel",this.onWheel),super.destroy()}}export{i as default};
1
+ class t{constructor(){this.listeners={}}on(t,s,e){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(s),null==e?void 0:e.once){const e=()=>{this.un(t,e),this.un(t,s)};return this.on(t,e),e}return()=>this.un(t,s)}un(t,s){var e;null===(e=this.listeners[t])||void 0===e||e.delete(s)}once(t,s){return this.on(t,s,{once:!0})}unAll(){this.listeners={}}emit(t,...s){this.listeners[t]&&this.listeners[t].forEach((t=>t(...s)))}}class s extends t{constructor(t){super(),this.subscriptions=[],this.isDestroyed=!1,this.options=t}onInit(){}_init(t){this.isDestroyed&&(this.subscriptions=[],this.isDestroyed=!1),this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t())),this.subscriptions=[],this.isDestroyed=!0,this.wavesurfer=void 0}}const e={scale:.5,deltaThreshold:5,exponentialZooming:!1,iterations:20};class i extends s{constructor(t){super(t||{}),this.wrapper=void 0,this.container=null,this.accumulatedDelta=0,this.pointerTime=0,this.oldX=0,this.endZoom=0,this.startZoom=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.startZoom&&this.options.exponentialZooming&&(this.startZoom=this.wavesurfer.getWrapper().clientWidth/this.wavesurfer.getDuration()),0===this.options.deltaThreshold||Math.abs(this.accumulatedDelta)>=this.options.deltaThreshold)){const s=this.wavesurfer.getDuration(),e=0===this.wavesurfer.options.minPxPerSec?this.wavesurfer.getWrapper().scrollWidth/s:this.wavesurfer.options.minPxPerSec,i=t.clientX-this.container.getBoundingClientRect().left,o=this.container.clientWidth,n=this.wavesurfer.getScroll();i===this.oldX&&0!==this.oldX||(this.pointerTime=(n+i)/e),this.oldX=i;const r=this.calculateNewZoom(e,this.accumulatedDelta),h=o/r*(i/o);r*s<o?(this.wavesurfer.zoom(o/s),this.container.scrollLeft=0):(this.wavesurfer.zoom(r),this.container.scrollLeft=(this.pointerTime-h)*r),this.accumulatedDelta=0}},this.calculateNewZoom=(t,s)=>{let e;if(this.options.exponentialZooming){const i=s>0?Math.pow(this.endZoom/this.startZoom,1/(this.options.iterations-1)):Math.pow(this.startZoom/this.endZoom,1/(this.options.iterations-1));e=Math.max(0,t*i)}else e=Math.max(0,t+s*this.options.scale);return Math.min(e,this.options.maxZoom)},this.options=Object.assign({},e,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.container.addEventListener("wheel",this.onWheel),void 0===this.options.maxZoom&&(this.options.maxZoom=this.container.clientWidth),this.endZoom=this.options.maxZoom)}destroy(){this.wrapper&&this.wrapper.removeEventListener("wheel",this.onWheel),super.destroy()}}export{i as default};
@@ -1 +1 @@
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,exponentialZooming:!1,iterations:20};class i extends e{constructor(t){super(t||{}),this.wrapper=void 0,this.container=null,this.accumulatedDelta=0,this.pointerTime=0,this.oldX=0,this.endZoom=0,this.startZoom=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.startZoom&&this.options.exponentialZooming&&(this.startZoom=this.wavesurfer.getWrapper().clientWidth/this.wavesurfer.getDuration()),0===this.options.deltaThreshold||Math.abs(this.accumulatedDelta)>=this.options.deltaThreshold)){const e=this.wavesurfer.getDuration(),s=0===this.wavesurfer.options.minPxPerSec?this.wavesurfer.getWrapper().scrollWidth/e:this.wavesurfer.options.minPxPerSec,i=t.clientX-this.container.getBoundingClientRect().left,o=this.container.clientWidth,n=this.wavesurfer.getScroll();i===this.oldX&&0!==this.oldX||(this.pointerTime=(n+i)/s),this.oldX=i;const r=this.calculateNewZoom(s,this.accumulatedDelta),h=o/r*(i/o);r*e<o?(this.wavesurfer.zoom(o/e),this.container.scrollLeft=0):(this.wavesurfer.zoom(r),this.container.scrollLeft=(this.pointerTime-h)*r),this.accumulatedDelta=0}},this.calculateNewZoom=(t,e)=>{let s;if(this.options.exponentialZooming){const i=e>0?Math.pow(this.endZoom/this.startZoom,1/(this.options.iterations-1)):Math.pow(this.startZoom/this.endZoom,1/(this.options.iterations-1));s=Math.max(0,t*i)}else s=Math.max(0,t+e*this.options.scale);return 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.container.addEventListener("wheel",this.onWheel),void 0===this.options.maxZoom&&(this.options.maxZoom=this.container.clientWidth),this.endZoom=this.options.maxZoom)}destroy(){this.wrapper&&this.wrapper.removeEventListener("wheel",this.onWheel),super.destroy()}}export{i as default};
1
+ class t{constructor(){this.listeners={}}on(t,s,e){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(s),null==e?void 0:e.once){const e=()=>{this.un(t,e),this.un(t,s)};return this.on(t,e),e}return()=>this.un(t,s)}un(t,s){var e;null===(e=this.listeners[t])||void 0===e||e.delete(s)}once(t,s){return this.on(t,s,{once:!0})}unAll(){this.listeners={}}emit(t,...s){this.listeners[t]&&this.listeners[t].forEach((t=>t(...s)))}}class s extends t{constructor(t){super(),this.subscriptions=[],this.isDestroyed=!1,this.options=t}onInit(){}_init(t){this.isDestroyed&&(this.subscriptions=[],this.isDestroyed=!1),this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t())),this.subscriptions=[],this.isDestroyed=!0,this.wavesurfer=void 0}}const e={scale:.5,deltaThreshold:5,exponentialZooming:!1,iterations:20};class i extends s{constructor(t){super(t||{}),this.wrapper=void 0,this.container=null,this.accumulatedDelta=0,this.pointerTime=0,this.oldX=0,this.endZoom=0,this.startZoom=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.startZoom&&this.options.exponentialZooming&&(this.startZoom=this.wavesurfer.getWrapper().clientWidth/this.wavesurfer.getDuration()),0===this.options.deltaThreshold||Math.abs(this.accumulatedDelta)>=this.options.deltaThreshold)){const s=this.wavesurfer.getDuration(),e=0===this.wavesurfer.options.minPxPerSec?this.wavesurfer.getWrapper().scrollWidth/s:this.wavesurfer.options.minPxPerSec,i=t.clientX-this.container.getBoundingClientRect().left,o=this.container.clientWidth,n=this.wavesurfer.getScroll();i===this.oldX&&0!==this.oldX||(this.pointerTime=(n+i)/e),this.oldX=i;const r=this.calculateNewZoom(e,this.accumulatedDelta),h=o/r*(i/o);r*s<o?(this.wavesurfer.zoom(o/s),this.container.scrollLeft=0):(this.wavesurfer.zoom(r),this.container.scrollLeft=(this.pointerTime-h)*r),this.accumulatedDelta=0}},this.calculateNewZoom=(t,s)=>{let e;if(this.options.exponentialZooming){const i=s>0?Math.pow(this.endZoom/this.startZoom,1/(this.options.iterations-1)):Math.pow(this.startZoom/this.endZoom,1/(this.options.iterations-1));e=Math.max(0,t*i)}else e=Math.max(0,t+s*this.options.scale);return Math.min(e,this.options.maxZoom)},this.options=Object.assign({},e,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.container.addEventListener("wheel",this.onWheel),void 0===this.options.maxZoom&&(this.options.maxZoom=this.container.clientWidth),this.endZoom=this.options.maxZoom)}destroy(){this.wrapper&&this.wrapper.removeEventListener("wheel",this.onWheel),super.destroy()}}export{i as default};