PluginProbe
Gutenberg / trunk
Gutenberg vtrunk
24.1.0 24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 All 404 releases
← All changes | build/modules/block-library/playlist/view.min.js +32 -30 23.3.2 → trunk View file →
@@ -1,29 +1,14 @@
1 -import{store as Wt,getContext as H,getElement as Dt}from"@wordpress/interactivity";var et={grad:.9,turn:360,rad:360/(2*Math.PI)},k=function(t){return typeof t=="string"?t.length>0:typeof t=="number"},y=function(t,e,a){return e===void 0&&(e=0),a===void 0&&(a=Math.pow(10,e)),Math.round(a*t)/a+0},g=function(t,e,a){return e===void 0&&(e=0),a===void 0&&(a=1),t>a?a:t>e?t:e},J=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},q=function(t){return{r:g(t.r,0,255),g:g(t.g,0,255),b:g(t.b,0,255),a:g(t.a)}},I=function(t){return{r:y(t.r),g:y(t.g),b:y(t.b),a:y(t.a,3)}},at=/^#([0-9a-f]{3,8})$/i,x=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},Y=function(t){var e=t.r,a=t.g,i=t.b,r=t.a,o=Math.max(e,a,i),s=o-Math.min(e,a,i),n=s?o===e?(a-i)/s:o===a?2+(i-e)/s:4+(e-a)/s:0;return{h:60*(n<0?n+6:n),s:o?s/o*100:0,v:o/255*100,a:r}},G=function(t){var e=t.h,a=t.s,i=t.v,r=t.a;e=e/360*6,a/=100,i/=100;var o=Math.floor(e),s=i*(1-a),n=i*(1-(e-o)*a),l=i*(1-(1-e+o)*a),h=o%6;return{r:255*[i,n,s,s,l,i][h],g:255*[l,i,i,n,s,s][h],b:255*[s,s,l,i,i,n][h],a:r}},$=function(t){return{h:J(t.h),s:g(t.s,0,100),l:g(t.l,0,100),a:g(t.a)}},z=function(t){return{h:y(t.h),s:y(t.s),l:y(t.l),a:y(t.a,3)}},O=function(t){return G((a=(e=t).s,{h:e.h,s:(a*=((i=e.l)<50?i:100-i)/100)>0?2*a/(i+a)*100:0,v:i+a,a:e.a}));var e,a,i},M=function(t){return{h:(e=Y(t)).h,s:(r=(200-(a=e.s))*(i=e.v)/100)>0&&r<200?a*i/100/(r<=100?r:200-r)*100:0,l:r/2,a:e.a};var e,a,i,r},it=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,rt=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ot=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,st=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,U={string:[[function(t){var e=at.exec(t);return e?(t=e[1]).length<=4?{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:t.length===4?y(parseInt(t[3]+t[3],16)/255,2):1}:t.length===6||t.length===8?{r:parseInt(t.substr(0,2),16),g:parseInt(t.substr(2,2),16),b:parseInt(t.substr(4,2),16),a:t.length===8?y(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=ot.exec(t)||st.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:q({r:Number(e[1])/(e[2]?100/255:1),g:Number(e[3])/(e[4]?100/255:1),b:Number(e[5])/(e[6]?100/255:1),a:e[7]===void 0?1:Number(e[7])/(e[8]?100:1)}):null},"rgb"],[function(t){var e=it.exec(t)||rt.exec(t);if(!e)return null;var a,i,r=$({h:(a=e[1],i=e[2],i===void 0&&(i="deg"),Number(a)*(et[i]||1)),s:Number(e[3]),l:Number(e[4]),a:e[5]===void 0?1:Number(e[5])/(e[6]?100:1)});return O(r)},"hsl"]],object:[[function(t){var e=t.r,a=t.g,i=t.b,r=t.a,o=r===void 0?1:r;return k(e)&&k(a)&&k(i)?q({r:Number(e),g:Number(a),b:Number(i),a:Number(o)}):null},"rgb"],[function(t){var e=t.h,a=t.s,i=t.l,r=t.a,o=r===void 0?1:r;if(!k(e)||!k(a)||!k(i))return null;var s=$({h:Number(e),s:Number(a),l:Number(i),a:Number(o)});return O(s)},"hsl"],[function(t){var e=t.h,a=t.s,i=t.v,r=t.a,o=r===void 0?1:r;if(!k(e)||!k(a)||!k(i))return null;var s=(function(n){return{h:J(n.h),s:g(n.s,0,100),v:g(n.v,0,100),a:g(n.a)}})({h:Number(e),s:Number(a),v:Number(i),a:Number(o)});return G(s)},"hsv"]]},F=function(t,e){for(var a=0;a<e.length;a++){var i=e[a][0](t);if(i)return[i,e[a][1]]}return[null,void 0]},nt=function(t){return typeof t=="string"?F(t.trim(),U.string):typeof t=="object"&&t!==null?F(t,U.object):[null,void 0]};var R=function(t,e){var a=M(t);return{h:a.h,s:g(a.s+100*e,0,100),l:a.l,a:a.a}},B=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},j=function(t,e){var a=M(t);return{h:a.h,s:a.s,l:g(a.l+100*e,0,100),a:a.a}},V=(function(){function t(e){this.parsed=nt(e)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return t.prototype.isValid=function(){return this.parsed!==null},t.prototype.brightness=function(){return y(B(this.rgba),2)},t.prototype.isDark=function(){return B(this.rgba)<.5},t.prototype.isLight=function(){return B(this.rgba)>=.5},t.prototype.toHex=function(){return e=I(this.rgba),a=e.r,i=e.g,r=e.b,s=(o=e.a)<1?x(y(255*o)):"","#"+x(a)+x(i)+x(r)+s;var e,a,i,r,o,s},t.prototype.toRgb=function(){return I(this.rgba)},t.prototype.toRgbString=function(){return e=I(this.rgba),a=e.r,i=e.g,r=e.b,(o=e.a)<1?"rgba("+a+", "+i+", "+r+", "+o+")":"rgb("+a+", "+i+", "+r+")";var e,a,i,r,o},t.prototype.toHsl=function(){return z(M(this.rgba))},t.prototype.toHslString=function(){return e=z(M(this.rgba)),a=e.h,i=e.s,r=e.l,(o=e.a)<1?"hsla("+a+", "+i+"%, "+r+"%, "+o+")":"hsl("+a+", "+i+"%, "+r+"%)";var e,a,i,r,o},t.prototype.toHsv=function(){return e=Y(this.rgba),{h:y(e.h),s:y(e.s),v:y(e.v),a:y(e.a,3)};var e},t.prototype.invert=function(){return v({r:255-(e=this.rgba).r,g:255-e.g,b:255-e.b,a:e.a});var e},t.prototype.saturate=function(e){return e===void 0&&(e=.1),v(R(this.rgba,e))},t.prototype.desaturate=function(e){return e===void 0&&(e=.1),v(R(this.rgba,-e))},t.prototype.grayscale=function(){return v(R(this.rgba,-1))},t.prototype.lighten=function(e){return e===void 0&&(e=.1),v(j(this.rgba,e))},t.prototype.darken=function(e){return e===void 0&&(e=.1),v(j(this.rgba,-e))},t.prototype.rotate=function(e){return e===void 0&&(e=15),this.hue(this.hue()+e)},t.prototype.alpha=function(e){return typeof e=="number"?v({r:(a=this.rgba).r,g:a.g,b:a.b,a:e}):y(this.rgba.a,3);var a},t.prototype.hue=function(e){var a=M(this.rgba);return typeof e=="number"?v({h:e,s:a.s,l:a.l,a:a.a}):y(a.h)},t.prototype.isEqual=function(e){return this.toHex()===v(e).toHex()},t})(),v=function(t){return t instanceof V?t:new V(t)};function lt(t){let e={};if(t.dataset.url&&(e.url=t.dataset.url),t.dataset.height&&(e.height=parseInt(t.dataset.height)),t.dataset.samples&&(e.samples=parseInt(t.dataset.samples)),t.dataset.preload&&(e.preload=t.dataset.preload),t.dataset.waveformStyle&&(e.waveformStyle=t.dataset.waveformStyle),t.dataset.barWidth&&(e.barWidth=parseInt(t.dataset.barWidth)),t.dataset.barSpacing&&(e.barSpacing=parseInt(t.dataset.barSpacing)),t.dataset.buttonAlign&&(e.buttonAlign=t.dataset.buttonAlign),t.dataset.colorPreset&&(e.colorPreset=t.dataset.colorPreset),t.dataset.waveformColor&&(e.waveformColor=t.dataset.waveformColor),t.dataset.progressColor&&(e.progressColor=t.dataset.progressColor),t.dataset.buttonColor&&(e.buttonColor=t.dataset.buttonColor),t.dataset.buttonHoverColor&&(e.buttonHoverColor=t.dataset.buttonHoverColor),t.dataset.textColor&&(e.textColor=t.dataset.textColor),t.dataset.textSecondaryColor&&(e.textSecondaryColor=t.dataset.textSecondaryColor),t.dataset.backgroundColor&&(e.backgroundColor=t.dataset.backgroundColor),t.dataset.borderColor&&(e.borderColor=t.dataset.borderColor),t.dataset.color&&(e.waveformColor=t.dataset.color),t.dataset.theme&&(e.colorPreset=t.dataset.theme),t.dataset.autoplay&&(e.autoplay=t.dataset.autoplay==="true"),t.dataset.showTime&&(e.showTime=t.dataset.showTime==="true"),t.dataset.showHoverTime&&(e.showHoverTime=t.dataset.showHoverTime==="true"),t.dataset.showBpm&&(e.showBPM=t.dataset.showBpm==="true"),t.dataset.singlePlay&&(e.singlePlay=t.dataset.singlePlay==="true"),t.dataset.playOnSeek&&(e.playOnSeek=t.dataset.playOnSeek==="true"),t.dataset.title&&(e.title=t.dataset.title),t.dataset.subtitle&&(e.subtitle=t.dataset.subtitle),t.dataset.album&&(e.album=t.dataset.album),t.dataset.artwork&&(e.artwork=t.dataset.artwork),t.dataset.waveform&&(e.waveform=t.dataset.waveform),t.dataset.markers)try{e.markers=JSON.parse(t.dataset.markers)}catch(a){console.warn("Invalid markers JSON:",a)}if(t.dataset.playbackRate&&(e.playbackRate=parseFloat(t.dataset.playbackRate)),t.dataset.showPlaybackSpeed!==void 0&&(e.showPlaybackSpeed=t.dataset.showPlaybackSpeed==="true"),t.dataset.playbackRates)try{e.playbackRates=JSON.parse(t.dataset.playbackRates)}catch(a){console.warn("Invalid playbackRates JSON:",a)}return t.dataset.enableMediaSession!==void 0&&(e.enableMediaSession=t.dataset.enableMediaSession==="true"),e}function K(t){if(!t||isNaN(t))return"0:00";let e=Math.floor(t/60),a=Math.floor(t%60);return`${e}:${a.toString().padStart(2,"0")}`}function ht(t){let e=t||Math.random().toString();return btoa(e.substring(0,10)).replace(/[^a-zA-Z0-9]/g,"")}function dt(t){if(!t)return"Audio";let e=t.split("/");return e[e.length-1].split(".")[0].replace(/[-_]/g," ").replace(/\b\w/g,a=>a.toUpperCase())}function X(...t){let e={};for(let a of t)for(let i in a)a[i]!==null&&a[i]!==void 0&&(e[i]=a[i]);return e}function ut(t,e){let a;return function(...i){let r=()=>{clearTimeout(a),t(...i)};clearTimeout(a),a=setTimeout(r,e)}}function T(t,e){if(t.length===e)return t;if(t.length===0||e===0)return[];let a=[];if(e>t.length){let i=(t.length-1)/(e-1);for(let r=0;r<e;r++){let o=r*i,s=Math.floor(o),n=Math.ceil(o),l=o-s;if(n>=t.length)a.push(t[t.length-1]);else if(s===n)a.push(t[s]);else{let h=t[s]*(1-l)+t[n]*l;a.push(h)}}}else{let i=t.length/e;for(let r=0;r<e;r++){let o=Math.floor(r*i),s=Math.floor((r+1)*i),n=0,l=0;for(let h=o;h<=s&&h<t.length;h++)t[h]>n&&(n=t[h]),l++;if(l===0){let h=Math.min(Math.round(r*i),t.length-1);n=t[h]}a.push(n)}}return a}function Q(t,e,a,i,r){let o=window.devicePixelRatio||1,s=r.barWidth*o,n=r.barSpacing*o,l=Math.floor(e.width/(s+n)),h=T(a,l),u=e.height,c=i*e.width;t.clearRect(0,0,e.width,e.height);for(let m=0;m<h.length;m++){let f=m*(s+n);if(f+s>e.width)break;let d=h[m]*u*.9,b=u-d;t.fillStyle=r.color,t.fillRect(f,b,s,d)}t.save(),t.beginPath(),t.rect(0,0,c,u),t.clip();for(let m=0;m<h.length;m++){let f=m*(s+n);if(f>c)break;let d=h[m]*u*.9,b=u-d;t.fillStyle=r.progressColor,t.fillRect(f,b,s,d)}t.restore()}function ct(t,e,a,i,r){let o=window.devicePixelRatio||1,s=r.barWidth*o,n=r.barSpacing*o,l=Math.floor(e.width/(s+n)),h=T(a,l),u=e.height,c=u/2,m=i*e.width;t.clearRect(0,0,e.width,e.height);for(let f=0;f<h.length;f++){let d=f*(s+n);if(d+s>e.width)break;let b=h[f]*u*.45;t.fillStyle=r.color,t.fillRect(d,c-b,s,b),t.fillRect(d,c,s,b)}t.save(),t.beginPath(),t.rect(0,0,m,u),t.clip();for(let f=0;f<h.length;f++){let d=f*(s+n);if(d>m)break;let b=h[f]*u*.45;t.fillStyle=r.progressColor,t.fillRect(d,c-b,s,b),t.fillRect(d,c,s,b)}t.restore()}function pt(t,e,a,i,r){let o=e.width,s=e.height,n=s/2,l=s*.35;t.clearRect(0,0,o,s);let h=(u,c,m=1,f=!1)=>{f&&(t.shadowBlur=12,t.shadowColor=u),t.strokeStyle=u,t.lineWidth=c,t.lineCap="round",t.lineJoin="round",t.beginPath(),t.moveTo(0,n);let d=[],b=Math.floor(a.length*m);for(let p=0;p<b;p++){let P=p/(a.length-1)*o,E=a[p],S=Math.sin(p*.1)*E,C=n+S*l;d.push({x:P,y:C})}for(let p=0;p<d.length-1;p++){let P=d[p].x+(d[p+1].x-d[p].x)*.5,E=d[p].y,S=d[p+1].x-(d[p+1].x-d[p].x)*.5,C=d[p+1].y;t.bezierCurveTo(P,E,S,C,d[p+1].x,d[p+1].y)}t.stroke(),f&&(t.shadowBlur=0)};t.strokeStyle="rgba(255, 255, 255, 0.03)",t.lineWidth=.5,t.beginPath(),t.moveTo(0,n),t.lineTo(o,n),t.stroke();for(let u=0;u<=10;u++){let c=o/10*u;t.beginPath(),t.moveTo(c,0),t.lineTo(c,s),t.stroke()}h(r.color,2,1,!1),i>0&&h(r.progressColor,3,i,!0)}function mt(t,e,a,i,r){let o=window.devicePixelRatio||1,s=(r.barWidth||3)*o,n=(r.barSpacing||1)*o,l=Math.floor(e.width/(s+n)),h=T(a,l),u=e.height,c=4*o,m=2*o,f=i*e.width,d=u/2;t.clearRect(0,0,e.width,e.height);for(let b=0;b<h.length;b++){let p=b*(s+n);if(p+s>e.width)break;let P=h[b]*u*.9,E=Math.floor(P/(c+m));t.fillStyle=p<f?r.progressColor:r.color;for(let S=0;S<E;S++){let C=S*(c+m);t.fillRect(p,d-C-c,s,c),S>0&&t.fillRect(p,d+C,s,c)}}}function ft(t,e,a,i,r){let o=window.devicePixelRatio||1,s=(r.barWidth||2)*o,n=(r.barSpacing||3)*o,l=Math.floor(e.width/(s+n)),h=T(a,l),u=e.height,c=Math.max(1.5*o,s/2),m=i*e.width,f=u/2;t.clearRect(0,0,e.width,e.height);for(let d=0;d<h.length;d++){let b=d*(s+n)+s/2;if(b>e.width)break;let p=h[d]*u*.9;t.fillStyle=b<m?r.progressColor:r.color,t.beginPath(),t.arc(b,f-p/2,c,0,Math.PI*2),t.fill(),t.beginPath(),t.arc(b,f+p/2,c,0,Math.PI*2),t.fill()}}function bt(t,e,a,i,r){let o=e.width,s=e.height,n=s/2,l=4,h=l/2;if(t.clearRect(0,0,o,s),t.fillStyle=r.color||"rgba(255, 255, 255, 0.2)",t.beginPath(),t.moveTo(h,n-l/2),t.lineTo(o-h,n-l/2),t.arc(o-h,n,l/2,-Math.PI/2,Math.PI/2),t.lineTo(h,n+l/2),t.arc(h,n,l/2,Math.PI/2,-Math.PI/2),t.closePath(),t.fill(),i>0){let u=Math.max(h*2,i*o);t.shadowBlur=8,t.shadowColor=r.progressColor,t.fillStyle=r.progressColor||"rgba(255, 255, 255, 0.9)",t.beginPath(),t.moveTo(h,n-l/2),t.lineTo(u-h,n-l/2),t.arc(u-h,n,l/2,-Math.PI/2,Math.PI/2),t.lineTo(h,n+l/2),t.arc(h,n,l/2,Math.PI/2,-Math.PI/2),t.closePath(),t.fill(),t.shadowBlur=0;let c=8,m=u;t.shadowBlur=4,t.shadowColor="rgba(0, 0, 0, 0.3)",t.shadowOffsetY=2,t.fillStyle="#ffffff",t.beginPath(),t.arc(m,n,c,0,Math.PI*2),t.fill(),t.shadowBlur=0,t.shadowOffsetY=0,t.fillStyle=r.progressColor||"rgba(255, 255, 255, 0.9)",t.beginPath(),t.arc(m,n,c*.4,0,Math.PI*2),t.fill()}}var yt={bars:Q,mirror:ct,line:pt,blocks:mt,dots:ft,seekbar:bt};function vt(t,e,a,i,r){(yt[r.waveformStyle]||Q)(t,e,a,i,r)}function gt(t){try{let e=t.getChannelData(0),a=t.sampleRate,i=wt(e,a);if(i.length<2)return 120;let r=[];for(let l=1;l<i.length;l++)r.push((i[l]-i[l-1])/a);let o={};r.forEach(l=>{let h=60/l,u=Math.round(h/3)*3;u>60&&u<200&&(o[u]=(o[u]||0)+1)});let s=0,n=120;for(let[l,h]of Object.entries(o))h>s&&(s=h,n=parseInt(l));return n<70&&o[n*2]?n*=2:n>160&&o[Math.round(n/2)]&&(n=Math.round(n/2)),n-1}catch(e){return console.warn("BPM detection failed:",e),null}}function wt(t,e){let a=[],i=0;for(let r=0;r<t.length-2048;r+=1024){let o=0;for(let l=r;l<r+2048;l++)o+=t[l]*t[l];o=o/2048;let s=o-i,n=i*1.8+.01;if(s>n&&o>.01){let l=a[a.length-1]||0,h=e*.15;r-l>h&&a.push(r)}i=o*.8+i*.2}return a}function kt(t,e=200){let a=t.length/e,i=~~(a/10)||1,r=t.numberOfChannels,o=[];for(let n=0;n<r;n++){let l=t.getChannelData(n);for(let h=0;h<e;h++){let u=~~(h*a),c=~~(u+a),m=0,f=0;for(let b=u;b<c;b+=i){let p=l[b];p>f&&(f=p),p<m&&(m=p)}let d=Math.max(Math.abs(f),Math.abs(m));(n===0||d>o[h])&&(o[h]=d)}}let s=Math.max(...o);return s>0?o.map(n=>n/s):o}async function Z(t,e=200,a=!1){try{let i=new(window.AudioContext||window.webkitAudioContext),r=await(await fetch(t)).arrayBuffer(),o=await i.decodeAudioData(r),s=kt(o,e);s=Ct(s);let n=null;return a&&(n=await gt(o)),i.close(),{peaks:s,bpm:n}}catch(i){throw console.error("Failed to generate waveform:",i),i}}function St(t=200){let e=[];for(let a=0;a<t;a++){let i=Math.random()*.5+.3,r=Math.sin(a/t*Math.PI*4)*.2;e.push(Math.max(.1,Math.min(1,i+r)))}return e}function Ct(t,e=.95){let a=Math.max(...t);if(a===0||a>e)return t;let i=e/a;return t.map(r=>r*i)}function Pt(){let t=document.documentElement,e=document.body;if(t.classList.contains("dark")||t.classList.contains("dark-mode")||t.classList.contains("theme-dark")||t.getAttribute("data-theme")==="dark"||t.getAttribute("data-color-scheme")==="dark"||e.classList.contains("dark")||e.classList.contains("dark-mode")||e.getAttribute("data-theme")==="dark")return"dark";if(t.classList.contains("light")||t.classList.contains("light-mode")||t.classList.contains("theme-light")||t.getAttribute("data-theme")==="light"||t.getAttribute("data-color-scheme")==="light"||e.classList.contains("light")||e.classList.contains("light-mode")||e.getAttribute("data-theme")==="light")return"light";try{let a=getComputedStyle(document.body).backgroundColor.match(/\d+/g);if(a&&a.length>=3){let[i,r,o]=a.map(Number),s=(i*299+r*587+o*114)/1e3;if(s>128)return"light";if(s<128)return"dark"}}catch{}if(window.matchMedia){if(window.matchMedia("(prefers-color-scheme: dark)").matches)return"dark";if(window.matchMedia("(prefers-color-scheme: light)").matches)return"light"}return"dark"}var W={dark:{waveformColor:"rgba(255, 255, 255, 0.3)",progressColor:"rgba(255, 255, 255, 0.9)",buttonColor:"rgba(255, 255, 255, 0.9)",buttonHoverColor:"rgba(255, 255, 255, 1)",textColor:"#ffffff",textSecondaryColor:"rgba(255, 255, 255, 0.6)",backgroundColor:"rgba(255, 255, 255, 0.03)",borderColor:"rgba(255, 255, 255, 0.1)"},light:{waveformColor:"rgba(0, 0, 0, 0.2)",progressColor:"rgba(0, 0, 0, 0.8)",buttonColor:"rgba(0, 0, 0, 0.8)",buttonHoverColor:"rgba(0, 0, 0, 0.9)",textColor:"#333333",textSecondaryColor:"rgba(0, 0, 0, 0.6)",backgroundColor:"rgba(0, 0, 0, 0.02)",borderColor:"rgba(0, 0, 0, 0.1)"}};function Et(t){if(t&&W[t])return W[t];let e=Pt();return W[e]}var Mt={url:"",height:60,samples:200,preload:"metadata",playbackRate:1,showPlaybackSpeed:!1,playbackRates:[.5,.75,1,1.25,1.5,1.75,2],buttonAlign:"auto",waveformStyle:"mirror",barWidth:2,barSpacing:0,colorPreset:null,waveformColor:null,progressColor:null,buttonColor:null,buttonHoverColor:null,textColor:null,textSecondaryColor:null,backgroundColor:null,borderColor:null,autoplay:!1,showTime:!0,showHoverTime:!1,showBPM:!1,singlePlay:!0,playOnSeek:!0,enableMediaSession:!0,markers:[],showMarkers:!0,title:null,subtitle:null,artwork:null,album:"",playIcon:'<svg viewBox="0 0 24 24" width="16" height="16"><path d="M8 5v14l11-7z"/></svg>',pauseIcon:'<svg viewBox="0 0 24 24" width="16" height="16"><path d="M6 4h4v16H6zM14 4h4v16h-4z"/></svg>',onLoad:null,onPlay:null,onPause:null,onEnd:null,onError:null,onTimeUpdate:null},xt={bars:{barWidth:3,barSpacing:1},mirror:{barWidth:2,barSpacing:0},line:{barWidth:2,barSpacing:0},blocks:{barWidth:4,barSpacing:2},dots:{barWidth:3,barSpacing:3},seekbar:{barWidth:1,barSpacing:0}},A=class w{static instances=new Map;static currentlyPlaying=null;constructor(e,a={}){if(this.container=typeof e=="string"?document.querySelector(e):e,!this.container)throw new Error("WaveformPlayer: Container element not found");let i=lt(this.container);this.options=X(Mt,i,a);let r=Et(this.options.colorPreset);for(let[s,n]of Object.entries(r))(this.options[s]===null||this.options[s]===void 0)&&(this.options[s]=n);let o=xt[this.options.waveformStyle];o&&(i.barWidth===void 0&&a.barWidth===void 0&&(this.options.barWidth=o.barWidth),i.barSpacing===void 0&&a.barSpacing===void 0&&(this.options.barSpacing=o.barSpacing)),this.audio=null,this.canvas=null,this.ctx=null,this.waveformData=[],this.progress=0,this.isPlaying=!1,this.isLoading=!1,this.hasError=!1,this.updateTimer=null,this.resizeObserver=null,this.id=this.container.id||ht(this.options.url),w.instances.set(this.id,this),this.init(),setTimeout(()=>{this.container.dispatchEvent(new CustomEvent("waveformplayer:ready",{bubbles:!0,detail:{player:this,url:this.options.url}}))},100)}init(){this.createDOM(),this.createAudio(),this.initPlaybackSpeed(),this.initKeyboardControls(),this.bindEvents(),this.setupResizeObserver(),requestAnimationFrame(()=>{this.resizeCanvas(),this.options.url&&this.load(this.options.url).then(()=>{this.options.autoplay&&this.play()}).catch(e=>{console.error("Failed to load audio:",e)})})}createDOM(){this.container.innerHTML="",this.container.className="waveform-player";let e=this.options.buttonAlign;e==="auto"&&(this.options.waveformStyle==="bars"?e="bottom":e="center"),this.container.innerHTML=`
2 - <div class="waveform-player-inner">
3 - <div class="waveform-body">
4 - <div class="waveform-track waveform-align-${e}">
5 - <button class="waveform-btn" aria-label="Play/Pause" style="
6 - border-color: ${this.options.buttonColor};
7 - color: ${this.options.buttonColor};
8 - ">
1 +import{store as Xe,getContext as F,getElement as Qe}from"@wordpress/interactivity";for(Pt={grad:.9,turn:360,rad:360/(2*Math.PI)},L=function(e){return typeof e=="string"?e.length>0:typeof e=="number"},S=function(e,t,i){return t===void 0&&(t=0),i===void 0&&(i=Math.pow(10,t)),Math.round(i*e)/i+0},A=function(e,t,i){return t===void 0&&(t=0),i===void 0&&(i=1),e>i?i:e>t?e:t},et=function(e){return(e=isFinite(e)?e%360:0)<0?e+360:e},G=function(e,t){return t===void 0&&(t=0),S(e,t)%360},Z=function(e){return{r:A(e.r,0,255),g:A(e.g,0,255),b:A(e.b,0,255),a:A(e.a)}},j=function(e){return{r:S(e.r),g:S(e.g),b:S(e.b),a:S(e.a,3)}},At=/^#([0-9a-f]{3,8})$/i,D=function(e,t){var i=e.charCodeAt(t);return(15&i)+9*(i>>6)},O=function(e,t){return D(e,t)<<4|D(e,t+1)},tt=[],$=0;$<256;$++)tt.push(($<16?"0":"")+$.toString(16));var Pt,L,S,A,et,G,Z,j,At,D,O,tt,$,U=function(e){return tt[A(e,0,255)]},Tt=function(e){var t=e.r,i=e.g,r=e.b,a=e.a,s=Math.max(t,i,r),o=s-Math.min(t,i,r),n=o?s===t?(i-r)/o:s===i?2+(r-t)/o:4+(t-i)/o:0;return{h:60*(n<0?n+6:n),s:s?o/s*100:0,v:s/255*100,a}},xt=function(e){var t=e.h,i=e.s,r=e.v,a=e.a;t=t/360*6,i/=100,r/=100;var s=Math.floor(t),o=r*(1-i),n=r*(1-(t-s)*i),l=r*(1-(1-t+s)*i),h=s%6;return{r:255*[r,n,o,o,l,r][h],g:255*[l,r,r,n,o,o][h],b:255*[o,o,l,r,r,n][h],a}},vt=function(e){return{h:et(e.h),s:A(e.s,0,100),l:A(e.l,0,100),a:A(e.a)}},gt=function(e){return{h:G(e.h),s:S(e.s),l:S(e.l),a:S(e.a,3)}},bt=function(e){return xt((i=(t=e).s,{h:t.h,s:(i*=((r=t.l)<50?r:100-r)/100)>0?2*i/(r+i)*100:0,v:r+i,a:t.a}));var t,i,r},H=function(e){return{h:(t=Tt(e)).h,s:(a=(200-(i=t.s))*(r=t.v)/100)>0&&a<200?i*r/100/(a<=100?a:200-a)*100:0,l:a/2,a:t.a};var t,i,r,a},ae=/^hsla?\(\s*([+-]?(?:\d*\.\d+|\d+))(deg|rad|grad|turn)?\s*,\s*([+-]?(?:\d*\.\d+|\d+))%\s*,\s*([+-]?(?:\d*\.\d+|\d+))%\s*(?:,\s*([+-]?(?:\d*\.\d+|\d+))(%)?\s*)?\)$/i,se=/^hsla?\(\s*([+-]?(?:\d*\.\d+|\d+))(deg|rad|grad|turn)?\s+([+-]?(?:\d*\.\d+|\d+))%\s+([+-]?(?:\d*\.\d+|\d+))%\s*(?:\/\s*([+-]?(?:\d*\.\d+|\d+))(%)?\s*)?\)$/i,oe=/^rgba?\(\s*([+-]?(?:\d*\.\d+|\d+))(%)?\s*,\s*([+-]?(?:\d*\.\d+|\d+))(%)?\s*,\s*([+-]?(?:\d*\.\d+|\d+))(%)?\s*(?:,\s*([+-]?(?:\d*\.\d+|\d+))(%)?\s*)?\)$/i,ne=/^rgba?\(\s*([+-]?(?:\d*\.\d+|\d+))(%)?\s+([+-]?(?:\d*\.\d+|\d+))(%)?\s+([+-]?(?:\d*\.\d+|\d+))(%)?\s*(?:\/\s*([+-]?(?:\d*\.\d+|\d+))(%)?\s*)?\)$/i,wt={string:[[function(e){if(!At.test(e))return null;var t=e.length;return t<=5?{r:17*D(e,1),g:17*D(e,2),b:17*D(e,3),a:t===5?S(17*D(e,4)/255,2):1}:t===7||t===9?{r:O(e,1),g:O(e,3),b:O(e,5),a:t===9?S(O(e,7)/255,2):1}:null},"hex"],[function(e){var t=oe.exec(e)||ne.exec(e);return t?t[2]!==t[4]||t[4]!==t[6]?null:Z({r:Number(t[1])/(t[2]?100/255:1),g:Number(t[3])/(t[4]?100/255:1),b:Number(t[5])/(t[6]?100/255:1),a:t[7]===void 0?1:Number(t[7])/(t[8]?100:1)}):null},"rgb"],[function(e){var t=ae.exec(e)||se.exec(e);if(!t)return null;var i,r,a=vt({h:(i=t[1],r=t[2],r===void 0&&(r="deg"),Number(i)*(Pt[r]||1)),s:Number(t[3]),l:Number(t[4]),a:t[5]===void 0?1:Number(t[5])/(t[6]?100:1)});return bt(a)},"hsl"]],object:[[function(e){var t=e.r,i=e.g,r=e.b,a=e.a,s=a===void 0?1:a;return L(t)&&L(i)&&L(r)?Z({r:Number(t),g:Number(i),b:Number(r),a:Number(s)}):null},"rgb"],[function(e){var t=e.h,i=e.s,r=e.l,a=e.a,s=a===void 0?1:a;if(!L(t)||!L(i)||!L(r))return null;var o=vt({h:Number(t),s:Number(i),l:Number(r),a:Number(s)});return bt(o)},"hsl"],[function(e){var t=e.h,i=e.s,r=e.v,a=e.a,s=a===void 0?1:a;if(!L(t)||!L(i)||!L(r))return null;var o=(function(n){return{h:et(n.h),s:A(n.s,0,100),v:A(n.v,0,100),a:A(n.a)}})({h:Number(t),s:Number(i),v:Number(r),a:Number(s)});return xt(o)},"hsv"]]},kt=function(e,t){for(var i=0;i<t.length;i++){var r=t[i][0](e);if(r)return[r,t[i][1]]}return[null,void 0]},le=function(e){return typeof e=="string"?kt(e.trim(),wt.string):typeof e=="object"&&e!==null?kt(e,wt.object):[null,void 0]};var Q=function(e,t){var i=H(e);return{h:i.h,s:A(i.s+100*t,0,100),l:i.l,a:i.a}},Y=function(e){return(299*e.r+587*e.g+114*e.b)/1e3/255},St=function(e,t){var i=H(e);return{h:i.h,s:i.s,l:A(i.l+100*t,0,100),a:i.a}},Et=(function(){function e(t){this.parsed=le(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return e.prototype.isValid=function(){return this.parsed!==null},e.prototype.brightness=function(){return S(Y(this.rgba),2)},e.prototype.isDark=function(){return Y(this.rgba)<.5},e.prototype.isLight=function(){return Y(this.rgba)>=.5},e.prototype.toHex=function(){return t=j(this.rgba),i=t.r,r=t.g,a=t.b,o=(s=t.a)<1?U(S(255*s)):"","#"+U(i)+U(r)+U(a)+o;var t,i,r,a,s,o},e.prototype.toRgb=function(){return j(this.rgba)},e.prototype.toRgbString=function(){return t=j(this.rgba),i=t.r,r=t.g,a=t.b,(s=t.a)<1?"rgba("+i+", "+r+", "+a+", "+s+")":"rgb("+i+", "+r+", "+a+")";var t,i,r,a,s},e.prototype.toHsl=function(){return gt(H(this.rgba))},e.prototype.toHslString=function(){return t=gt(H(this.rgba)),i=t.h,r=t.s,a=t.l,(s=t.a)<1?"hsla("+i+", "+r+"%, "+a+"%, "+s+")":"hsl("+i+", "+r+"%, "+a+"%)";var t,i,r,a,s},e.prototype.toHsv=function(){return t=Tt(this.rgba),{h:G(t.h),s:S(t.s),v:S(t.v),a:S(t.a,3)};var t},e.prototype.invert=function(){return k({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},e.prototype.saturate=function(t){return t===void 0&&(t=.1),k(Q(this.rgba,t))},e.prototype.desaturate=function(t){return t===void 0&&(t=.1),k(Q(this.rgba,-t))},e.prototype.grayscale=function(){return k(Q(this.rgba,-1))},e.prototype.lighten=function(t){return t===void 0&&(t=.1),k(St(this.rgba,t))},e.prototype.darken=function(t){return t===void 0&&(t=.1),k(St(this.rgba,-t))},e.prototype.rotate=function(t){return t===void 0&&(t=15),this.hue(H(this.rgba).h+t)},e.prototype.alpha=function(t){return typeof t=="number"?k({r:(i=this.rgba).r,g:i.g,b:i.b,a:t}):S(this.rgba.a,3);var i},e.prototype.hue=function(t){var i=H(this.rgba);return typeof t=="number"?k({h:t,s:i.s,l:i.l,a:i.a}):G(i.h)},e.prototype.isEqual=function(t){return this.toHex()===k(t).toHex()},e})(),k=function(e){return e instanceof Et?e:new Et(e)};function qt(e){let t=-1/0;for(let i=0;i<e.length;i++)e[i]>t&&(t=e[i]);return t}function M(e){return String(e??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function Ct(e){return M(typeof e=="number"?`${e}px`:e)}function he(e){if(typeof e!="string"||e==="")return!1;try{let t=new URL(e,"http://localhost/");return t.protocol==="http:"||t.protocol==="https:"}catch{return!1}}function b(e,t=0,i=1){return Math.max(t,Math.min(e,i))}function J(e,t=null,i={}){let{min:r=-1/0,max:a=1/0,integer:s=!1}=i,o=typeof e=="number"?e:typeof e=="string"&&e.trim()!==""?Number(e):NaN;if(!Number.isFinite(o))return t;let n=b(o,r,a);return s?Math.round(n):n}function lt(e,t=null){if(Array.isArray(e))return e;if(typeof e=="string"&&e.trim().startsWith("["))try{let i=JSON.parse(e);if(Array.isArray(i))return i}catch{}return t}function ht(e,t={}){let{min:i=-1/0,max:r=1/0,fallback:a=null}=t,s=lt(e);if(!s&&typeof e=="string"&&e.trim()!==""&&(s=e.split(/[,\s]+/)),!s)return a;let o=s.map(n=>J(n)).filter(n=>n!==null&&n>=i&&n<=r);return o.length?o:a}function ue(e,t,i=null){return t.includes(e)?e:i}function de(e){if(typeof e=="string"){let t=e.trim().toLowerCase();return t!==""&&t!=="false"&&t!=="0"}return!!e}function ce(e){return e===void 0?void 0:e==="true"}function Lt(e){if(typeof e=="string"&&e.trim().startsWith("["))try{return JSON.parse(e)}catch{}return e}function Ft(e){let t={},i=(o,n=o)=>{let l=ce(e.dataset[n]);l!==void 0&&(t[o]=l)},r=(o,n=o,l=!1)=>{let h=e.dataset[n];h&&(t[o]=l?parseFloat(h):parseInt(h,10))},a=(o,n=o)=>{let l=e.dataset[n];l&&(t[o]=/^\d+(\.\d+)?$/.test(l.trim())?parseFloat(l):l)},s=(o,n=o)=>{let l=e.dataset[n];if(!l)return;let h=lt(l);h?t[o]=h:console.warn(`[WaveformPlayer] Invalid ${n} attribute, expected a JSON array:`,l)};if(e.dataset.src&&(t.url=e.dataset.src),e.dataset.url&&(t.url=e.dataset.url),r("height"),r("samples"),e.dataset.preload&&(t.preload=e.dataset.preload),e.dataset.crossOrigin&&(t.crossOrigin=e.dataset.crossOrigin),e.dataset.audioMode&&(t.audioMode=e.dataset.audioMode),e.dataset.style&&(t.waveformStyle=e.dataset.style),e.dataset.waveformStyle&&(t.waveformStyle=e.dataset.waveformStyle),e.dataset.waveformGradient&&(t.waveformGradient=e.dataset.waveformGradient),r("barWidth"),r("barSpacing"),r("barRadius"),e.dataset.buttonAlign&&(t.buttonAlign=e.dataset.buttonAlign),e.dataset.layout&&(t.layout=e.dataset.layout),e.dataset.buttonStyle&&(t.buttonStyle=e.dataset.buttonStyle),a("buttonSize"),a("buttonRadius"),e.dataset.colorPreset&&(t.colorPreset=e.dataset.colorPreset),e.dataset.waveformColor&&(t.waveformColor=Lt(e.dataset.waveformColor)),e.dataset.progressColor&&(t.progressColor=Lt(e.dataset.progressColor)),e.dataset.color&&(t.waveformColor=e.dataset.color),e.dataset.theme&&(t.colorPreset=e.dataset.theme),i("autoplay"),i("showControls"),i("showInfo"),i("showTime"),i("showHoverTime"),i("seekHandle"),i("showBPM","showBpm"),r("bpm"),i("singlePlay"),i("playOnSeek"),e.dataset.title&&(t.title=e.dataset.title),e.dataset.artist&&(t.artist=e.dataset.artist),e.dataset.album&&(t.album=e.dataset.album),e.dataset.artwork&&(t.artwork=e.dataset.artwork),e.dataset.artworkPosition&&(t.artworkPosition=e.dataset.artworkPosition),e.dataset.waveform&&(t.waveform=e.dataset.waveform),s("markers"),r("playbackRate","playbackRate",!0),i("showPlaybackSpeed"),e.dataset.playbackRates){let o=ht(e.dataset.playbackRates);o?t.playbackRates=o:console.warn("[WaveformPlayer] Invalid playbackRates attribute:",e.dataset.playbackRates)}return i("enableMediaSession"),i("showMarkers"),i("accessibleSeek"),e.dataset.seekLabel&&(t.seekLabel=e.dataset.seekLabel),e.dataset.seekValueText&&(t.seekValueText=e.dataset.seekValueText),e.dataset.errorText&&(t.errorText=e.dataset.errorText),e.dataset.playPauseLabel&&(t.playPauseLabel=e.dataset.playPauseLabel),e.dataset.speedLabel&&(t.speedLabel=e.dataset.speedLabel),e.dataset.artworkAlt&&(t.artworkAlt=e.dataset.artworkAlt),e.dataset.unknownTrackText&&(t.unknownTrackText=e.dataset.unknownTrackText),t}function pe(e,...t){let i=0;return e.replace(/%(?:(\d+)\$)?s/g,(r,a)=>{let s=a?Number(a)-1:i++;return t[s]??r})}function R(e){let t=Number(e);if(!t||!Number.isFinite(t)||t<0)return"0:00";let i=Math.floor(t/3600),r=Math.floor(t%3600/60),a=Math.floor(t%60);return i>0?`${i}:${r.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`:`${r}:${a.toString().padStart(2,"0")}`}var me=0;function fe(e){let t=e||"audio",i=5381;for(let r=0;r<t.length;r++)i=(i<<5)+i+t.charCodeAt(r)|0;return`wp_${(i>>>0).toString(36)}_${(me++).toString(36)}`}function zt(e){if(!e)return"Audio";let t=e.split("/");return t[t.length-1].split(".")[0].replace(/[-_]/g," ").replace(/\b\w/g,i=>i.toUpperCase())}function Ut(e){if(typeof e!="string")return null;let t=e.match(/rgba?\(\s*([\d.]+)\s*[,\s]\s*([\d.]+)\s*[,\s]\s*([\d.]+)\s*(?:[,/]\s*([\d.]+)(%?))?/i);if(!t)return null;let i=Number(t[1]),r=Number(t[2]),a=Number(t[3]);if(!Number.isFinite(i)||!Number.isFinite(r)||!Number.isFinite(a))return null;let s=t[4]===void 0?1:Number(t[4]);return Number.isFinite(s)?(t[5]==="%"&&(s/=100),{r:i,g:r,b:a,a:b(s,0,1)}):null}function ye(e){let t=Ut(e);return!t||t.a<=0?null:(t.r*299+t.g*587+t.b*114)/1e3}function Mt(...e){let t={};for(let i of e)for(let r in i)i[r]!==null&&i[r]!==void 0&&(t[r]=i[r]);return t}function ve(e,t){let i;return function(...r){let a=()=>{clearTimeout(i),e(...r)};clearTimeout(i),i=setTimeout(a,t)}}function K(e,t){if(e.length===t)return e;if(e.length===0||t===0)return[];let i=[];if(t>e.length){let r=(e.length-1)/(t-1);for(let a=0;a<t;a++){let s=a*r,o=Math.floor(s),n=Math.ceil(s),l=s-o;if(n>=e.length)i.push(e[e.length-1]);else if(o===n)i.push(e[o]);else{let h=e[o]*(1-l)+e[n]*l;i.push(h)}}}else{let r=e.length/t;for(let a=0;a<t;a++){let s=Math.floor(a*r),o=Math.floor((a+1)*r),n=0,l=0;for(let h=s;h<=o&&h<e.length;h++)e[h]>n&&(n=e[h]),l++;if(l===0){let h=Math.min(Math.round(a*r),e.length-1);n=e[h]}i.push(n)}}return i}function x(e,t,i,r){if(!Array.isArray(t))return t;if(t.length<2)return t[0];let a=i.width,s=i.height,o=r&&r.waveformGradient,[n,l,h,u]=o==="horizontal"?[0,0,a,0]:o==="diagonal"?[0,0,a,s]:[0,0,0,s];try{let c=e.createLinearGradient(n,l,h,u);return t.forEach((p,y)=>c.addColorStop(y/(t.length-1),p)),c}catch{return t[0]}}function B(e,t,i,r,a,s){if((Array.isArray(s)?s.some(o=>o>0):s>0)&&typeof e.roundRect=="function"){let o=Math.min(r/2,Math.abs(a)/2),n=l=>b(l,0,o);e.beginPath(),e.roundRect(t,i,r,a,Array.isArray(s)?s.map(n):n(s)),e.fill()}else e.fillRect(t,i,r,a)}function jt(e,t){return(e.barRadius||0)*t}function ge(e,t){let i=jt(e,t);return[i,i,0,0]}function _t(e,t,i,r,a){let s=a/2;e.beginPath(),e.moveTo(t,r-s),e.lineTo(i-s,r-s),e.arc(i-s,r,s,-Math.PI/2,Math.PI/2),e.lineTo(t,r+s),e.arc(t,r,s,Math.PI/2,-Math.PI/2),e.closePath()}function it(e,t,i,r,a){let s=window.devicePixelRatio||1,o=a.barWidth*s,n=a.barSpacing*s,l=Math.floor(t.width/(o+n)),h=K(i,l),u=t.height,c=r*t.width,p=ge(a,s),y=x(e,a.color,t,a),g=x(e,a.progressColor,t,a);e.clearRect(0,0,t.width,t.height),e.fillStyle=y;for(let m=0;m<h.length;m++){let f=m*(o+n);if(f+o>t.width)break;let v=h[m]*u*.9,d=u-v;B(e,f,d,o,v,p)}e.save(),e.beginPath(),e.rect(0,0,c,u),e.clip(),e.fillStyle=g;for(let m=0;m<h.length;m++){let f=m*(o+n);if(f>c)break;let v=h[m]*u*.9,d=u-v;B(e,f,d,o,v,p)}e.restore()}function be(e,t,i,r,a){let s=window.devicePixelRatio||1,o=a.barWidth*s,n=a.barSpacing*s,l=Math.floor(t.width/(o+n)),h=K(i,l),u=t.height,c=u/2,p=r*t.width,y=jt(a,s),g=[y,y,0,0],m=[0,0,y,y],f=x(e,a.color,t,a),v=x(e,a.progressColor,t,a);e.clearRect(0,0,t.width,t.height),e.fillStyle=f;for(let d=0;d<h.length;d++){let E=d*(o+n);if(E+o>t.width)break;let P=h[d]*u*.45;B(e,E,c-P,o,P,g),B(e,E,c,o,P,m)}e.save(),e.beginPath(),e.rect(0,0,p,u),e.clip(),e.fillStyle=v;for(let d=0;d<h.length;d++){let E=d*(o+n);if(E>p)break;let P=h[d]*u*.45;B(e,E,c-P,o,P,g),B(e,E,c,o,P,m)}e.restore()}function we(e,t,i,r,a){let s=t.width,o=t.height,n=o/2,l=o*.35;e.clearRect(0,0,s,o);let h=(u,c,p=1,y=!1)=>{let g=x(e,u,t,a),m=Array.isArray(u)?u[u.length-1]:u;y&&(e.shadowBlur=12,e.shadowColor=m),e.strokeStyle=g,e.lineWidth=c,e.lineCap="round",e.lineJoin="round",e.beginPath(),e.moveTo(0,n);let f=[],v=Math.floor(i.length*p);for(let d=0;d<v;d++){let E=d/(i.length-1)*s,P=i[d],C=Math.sin(d*.1)*P,_=n+C*l;f.push({x:E,y:_})}for(let d=0;d<f.length-1;d++){let E=f[d].x+(f[d+1].x-f[d].x)*.5,P=f[d].y,C=f[d+1].x-(f[d+1].x-f[d].x)*.5,_=f[d+1].y;e.bezierCurveTo(E,P,C,_,f[d+1].x,f[d+1].y)}e.stroke(),y&&(e.shadowBlur=0)};e.strokeStyle="rgba(255, 255, 255, 0.03)",e.lineWidth=.5,e.beginPath(),e.moveTo(0,n),e.lineTo(s,n),e.stroke();for(let u=0;u<=10;u++){let c=s/10*u;e.beginPath(),e.moveTo(c,0),e.lineTo(c,o),e.stroke()}h(a.color,2,1,!1),r>0&&h(a.progressColor,3,r,!0)}function Rt(e,t,i,r,a){let s=window.devicePixelRatio||1,o=(a.barWidth||3)*s,n=(a.barSpacing||1)*s,l=Math.floor(t.width/(o+n)),h=K(i,l),u=t.height,c=4*s,p=2*s,y=r*t.width,g=u/2,m=x(e,a.color,t,a),f=x(e,a.progressColor,t,a);e.clearRect(0,0,t.width,t.height);for(let v=0;v<h.length;v++){let d=v*(o+n);if(d+o>t.width)break;let E=h[v]*u*.9,P=Math.floor(E/(c+p));e.fillStyle=d<y?f:m;for(let C=0;C<P;C++){let _=C*(c+p);e.fillRect(d,g-_-c,o,c),C>0&&e.fillRect(d,g+_,o,c)}}}function Dt(e,t,i,r,a){let s=window.devicePixelRatio||1,o=(a.barWidth||2)*s,n=(a.barSpacing||3)*s,l=Math.floor(t.width/(o+n)),h=K(i,l),u=t.height,c=Math.max(1.5*s,o/2),p=r*t.width,y=u/2,g=x(e,a.color,t,a),m=x(e,a.progressColor,t,a);e.clearRect(0,0,t.width,t.height);for(let f=0;f<h.length;f++){let v=f*(o+n)+o/2;if(v>t.width)break;let d=h[f]*u*.9;e.fillStyle=v<p?m:g,e.beginPath(),e.arc(v,y-d/2,c,0,Math.PI*2),e.fill(),e.beginPath(),e.arc(v,y+d/2,c,0,Math.PI*2),e.fill()}}function ke(e,t,i,r,a){let s=t.width,o=t.height,n=o/2,l=4,h=l/2,u=!!a.seekActive;if(e.clearRect(0,0,s,o),e.fillStyle=x(e,a.color,t,a)||"rgba(255, 255, 255, 0.2)",_t(e,h,s,n,l),e.fill(),r>0){let c=Math.max(h*2,r*s);e.save(),e.globalAlpha=a.seekHandle&&!u?.7:1,e.fillStyle=x(e,a.progressColor,t,a)||"rgba(255, 255, 255, 0.9)",_t(e,h,c,n,l),e.fill(),e.restore()}}var Se={bars:it,bar:it,mirror:be,line:we,blocks:Rt,block:Rt,dots:Dt,dot:Dt,seekbar:ke};function Ee(e,t,i,r,a){(Se[a.waveformStyle]||it)(e,t,i,r,a)}function Pe(e){try{let t=e.getChannelData(0),i=e.sampleRate,r=Ae(t,i);if(r.length<2)return 120;let a=[];for(let l=1;l<r.length;l++)a.push((r[l]-r[l-1])/i);let s={};a.forEach(l=>{let h=60/l,u=Math.round(h/3)*3;u>60&&u<200&&(s[u]=(s[u]||0)+1)});let o=0,n=120;for(let[l,h]of Object.entries(s))h>o&&(o=h,n=parseInt(l));return n<70&&s[n*2]?n*=2:n>160&&s[Math.round(n/2)]&&(n=Math.round(n/2)),n-1}catch(t){return console.warn("[WaveformPlayer] BPM detection failed:",t),null}}function Ae(e,t){let i=[],r=0;for(let a=0;a<e.length-2048;a+=1024){let s=0;for(let l=a;l<a+2048;l++)s+=e[l]*e[l];s=s/2048;let o=s-r,n=r*1.8+.01;if(o>n&&s>.01){let l=i[i.length-1]||0,h=t*.15;a-l>h&&i.push(a)}r=s*.8+r*.2}return i}function Te(e,t=1800){let i=e.length/t,r=e.numberOfChannels,a=[];for(let o=0;o<r;o++){let n=e.getChannelData(o);for(let l=0;l<t;l++){let h=~~(l*i),u=~~(h+i),c=0,p=0;for(let g=h;g<u;g++){let m=n[g];m>p&&(p=m),m<c&&(c=m)}let y=Math.max(Math.abs(p),Math.abs(c));(o===0||y>a[l])&&(a[l]=y)}}let s=qt(a);return s>0?a.map(o=>o/s):a}async function Ht(e,t=1800,i=!1){let r;try{let a=window.AudioContext||window.webkitAudioContext;r=new a;let s=await(await fetch(e)).arrayBuffer(),o=await r.decodeAudioData(s),n=Te(o,t);n=Ce(n);let l=null;return i&&(l=Pe(o)),{peaks:n,bpm:l}}finally{r&&r.close()}}function xe(e=1800){let t=[];for(let i=0;i<e;i++){let r=Math.random()*.5+.3,a=Math.sin(i/e*Math.PI*4)*.2;t.push(b(r+a,.1,1))}return t}function Ce(e,t=.95){let i=qt(e);if(i===0||i>t)return e;let r=t/i;return e.map(a=>a*r)}var rt=128;function Bt(e){let t=document.documentElement,i=document.body;return t.classList.contains(e)||t.classList.contains(`${e}-mode`)||t.classList.contains(`theme-${e}`)||t.getAttribute("data-theme")===e||t.getAttribute("data-color-scheme")===e||i.classList.contains(e)||i.classList.contains(`${e}-mode`)||i.getAttribute("data-theme")===e}function Le(e){let t=0,i=0;for(let r=e;r&&r.nodeType===1&&i<.995;r=r.parentElement){let a=Ut(getComputedStyle(r).backgroundColor);if(!a||a.a<=0)continue;let s=a.a*(1-i);t+=(a.r*299+a.g*587+a.b*114)/1e3*s,i+=s}return{sum:t,alpha:i}}function Me(){let e=ye(getComputedStyle(document.body).color);if(e!==null)return e>rt?"dark":"light";if(window.matchMedia){if(window.matchMedia("(prefers-color-scheme: dark)").matches)return"dark";if(window.matchMedia("(prefers-color-scheme: light)").matches)return"light"}return"dark"}function V(e){if(Bt("dark"))return"dark";if(Bt("light"))return"light";try{let t=e&&e.nodeType===1?e:document.body,{sum:i,alpha:r}=Le(t),a=Me(),s=i+(a==="dark"?0:255)*(1-r);return s>rt?"light":s<rt?"dark":a}catch{return"dark"}}var W={dark:{waveformColor:"rgba(255, 255, 255, 0.3)",progressColor:"rgba(255, 255, 255, 0.9)"},light:{waveformColor:"rgba(0, 0, 0, 0.2)",progressColor:"rgba(0, 0, 0, 0.8)"}};function Wt(e,t){if(e&&W[e])return W[e];let i=V(t);return W[i]}var at={url:"",height:64,samples:1800,preload:"metadata",crossOrigin:null,audioMode:"self",playbackRate:1,showPlaybackSpeed:!1,playbackRates:[.5,.75,1,1.25,1.5,1.75,2],buttonAlign:"auto",layout:"default",buttonStyle:"circle",buttonSize:null,buttonRadius:null,waveformStyle:"mirror",barWidth:2,barSpacing:0,barRadius:1,waveformGradient:"vertical",colorPreset:null,waveformColor:null,progressColor:null,autoplay:!1,showControls:!0,showInfo:!0,showTime:!0,showHoverTime:!1,seekHandle:!1,showBPM:!1,bpm:null,singlePlay:!0,playOnSeek:!0,enableMediaSession:!0,markers:[],showMarkers:!0,accessibleSeek:!0,seekLabel:null,seekValueText:null,title:null,artist:null,artwork:null,artworkPosition:"info",album:"",errorText:"Unable to load audio",playPauseLabel:"Play/Pause",speedLabel:"Playback speed",artworkAlt:"Album artwork",unknownTrackText:"Unknown Track",playIcon:'<svg viewBox="0 0 24 24" width="16" height="16"><path d="M8 5v14l11-7z"/></svg>',pauseIcon:'<svg viewBox="0 0 24 24" width="16" height="16"><path d="M6 4h4v16H6zM14 4h4v16h-4z"/></svg>',onLoad:null,onPlay:null,onPause:null,onEnd:null,onError:null,onTimeUpdate:null,onNextTrack:null,onPreviousTrack:null},Gt={bars:{barWidth:3,barSpacing:1},mirror:{barWidth:2,barSpacing:2},line:{barWidth:2,barSpacing:0},blocks:{barWidth:4,barSpacing:2},dots:{barWidth:3,barSpacing:3},seekbar:{barWidth:1,barSpacing:0}},Vt=["auto","top","center","bottom"],ut=.25,dt=4,_e={buttonAlign:Vt,layout:["default","preview"],buttonStyle:["circle","minimal"],artworkPosition:["info","button"],waveformStyle:Object.keys(Gt),waveformGradient:["vertical","horizontal","diagonal"],audioMode:["self","external"],preload:["none","metadata","auto"],colorPreset:Object.keys(W),crossOrigin:["anonymous","use-credentials"]},Re={height:{min:1,integer:!0},samples:{min:1,integer:!0},barWidth:{min:0},barSpacing:{min:0},barRadius:{min:0},bpm:{min:1},playbackRate:{min:ut,max:dt}},De=["autoplay","showControls","showInfo","showTime","showHoverTime","seekHandle","showBPM","singlePlay","playOnSeek","enableMediaSession","showMarkers","accessibleSeek","showPlaybackSpeed"],He=["onLoad","onPlay","onPause","onEnd","onError","onTimeUpdate","onNextTrack","onPreviousTrack"];function st(e,t){console.warn(`[WaveformPlayer] Invalid ${e} option, using default:`,t)}function ot(e){let t=lt(e);return t?t.reduce((i,r)=>{let a=r&&typeof r=="object"?J(r.time,null,{min:0}):null;return a===null?(st("marker",r),i):(i.push({...r,time:a,label:r.label==null?"":r.label}),i)},[]):(e!=null&&st("markers",e),[])}function It(e){let t=r=>e[r]!=null,i=r=>{st(r,e[r]),e[r]=at[r]};for(let[r,a]of Object.entries(Re)){if(!t(r))continue;let s=J(e[r],null,a);s===null?i(r):e[r]=s}for(let[r,a]of Object.entries(_e))t(r)&&ue(e[r],a)===null&&i(r);for(let r of De)e[r]=de(e[r]);for(let r of He)t(r)&&typeof e[r]!="function"&&i(r);if(t("playbackRates")){let r=ht(e.playbackRates,{min:ut,max:dt,fallback:null});r===null?i("playbackRates"):e.playbackRates=r}e.markers=ot(e.markers);for(let r of["buttonSize","buttonRadius"]){if(!t(r))continue;let a=e[r];(typeof a=="number"?Number.isFinite(a):typeof a=="string"&&a.trim()!=="")||i(r)}for(let r of["waveformColor","progressColor"]){if(!t(r))continue;let a=e[r];!(typeof a=="string"&&a.trim()!=="")&&!Array.isArray(a)&&i(r)}return e}var Be="data:image/svg+xml,"+encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect width="24" height="24" rx="4" fill="#71717a" fill-opacity="0.15"/><g fill="none" stroke="#a1a1aa" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><circle cx="8" cy="17" r="2.2"/><circle cx="17" cy="15" r="2.2"/><path d="M10.2 17V7l9-1.6v9"/></g></svg>'),Nt=5,$t=10,We='button, a[href], input, [role="slider"]',I=class w{static instances=new Map;static currentlyPlaying=null;constructor(t,i={}){if(this.container=typeof t=="string"?document.querySelector(t):t,!this.container)throw new Error("[WaveformPlayer] Container element not found");let r=Ft(this.container),a={...i};a.style&&!a.waveformStyle&&(a.waveformStyle=a.style),a.src&&!a.url&&(a.url=a.src),this.options=It(Mt(at,r,a));let s=Wt(this.options.colorPreset,this.container);this._autoTheme=this.options.colorPreset==null||!W[this.options.colorPreset],this._presetKeys=[],this._scheme=this.options.colorPreset&&W[this.options.colorPreset]?this.options.colorPreset:V(this.container);for(let[n,l]of Object.entries(s))(this.options[n]===null||this.options[n]===void 0)&&(this.options[n]=l,this._presetKeys.push(n));let o=Gt[this.options.waveformStyle];o&&(r.barWidth===void 0&&i.barWidth===void 0&&(this.options.barWidth=o.barWidth),r.barSpacing===void 0&&i.barSpacing===void 0&&(this.options.barSpacing=o.barSpacing)),this.audio=null,this.canvas=null,this.ctx=null,this.waveformData=[],this.progress=0,this._activeMarkerIndex=-1,this._markerLabelTimer=null,this.isPlaying=!1,this.isLoading=!1,this.hasError=!1,this.updateTimer=null,this.resizeObserver=null,this._ac=new AbortController,this.id=this.container.id||fe(this.options.url),w.instances.set(this.id,this),w._watchTheme();try{this.init()}catch(n){throw w.instances.delete(this.id),this._ac.abort(),n}setTimeout(()=>{this._emit("waveformplayer:ready",{player:this,url:this.options.url})},100)}_emit(t,i,r=!1){let a=new CustomEvent(t,{bubbles:!0,cancelable:r,detail:i});return this.container.dispatchEvent(a),a}_requestSeek(t){this._emit("waveformplayer:request-seek",{...this._buildTrackDetail(),percent:t},!0).defaultPrevented||(this.progress=t,this.drawWaveform?.())}init(){this.createDOM(),this.createAudio(),this.initPlaybackSpeed(),this.initKeyboardControls(),this.initSeekControl(),this.bindEvents(),this.setupResizeObserver(),requestAnimationFrame(()=>{this.resizeCanvas(),this.options.url&&this.load(this.options.url).then(()=>{this.options.autoplay&&this.play()?.catch(()=>{})}).catch(t=>{console.error("[WaveformPlayer] Failed to load audio:",t)})})}createDOM(){this.container.innerHTML="",this.container.className="waveform-player";let t=Vt.includes(this.options.buttonAlign)?this.options.buttonAlign:"auto";t==="auto"&&(this.options.waveformStyle==="bars"?t="bottom":t="center"),this.options.layout==="preview"&&this.container.classList.add("waveform-layout-preview"),this.container.classList.toggle("waveform-theme-light",this._scheme==="light");let i=[];this.options.buttonSize!=null&&i.push(`--wfp-btn-size: ${Ct(this.options.buttonSize)}`),this.options.buttonRadius!=null&&i.push(`--wfp-btn-radius: ${Ct(this.options.buttonRadius)}`);let r=i.length?` style="${i.join("; ")};"`:"",a=this.options.artworkPosition==="button"&&this.options.artwork,s=a?`<img class="waveform-btn-artwork" src="${M(this.options.artwork)}" alt="" aria-hidden="true">`:"",o=this.options.showControls?`
2 + <button class="waveform-btn${this.options.buttonStyle==="minimal"?" waveform-btn-minimal":""}${a?" waveform-btn-has-artwork":""}" aria-label="${M(this.options.playPauseLabel)}"${r}>
3 + ${s}
9 4 <span class="waveform-icon-play">${this.options.playIcon}</span>
10 5 <span class="waveform-icon-pause" style="display:none;">${this.options.pauseIcon}</span>
11 6 </button>
12 -
13 - <div class="waveform-container">
14 - <canvas></canvas>
15 - <div class="waveform-markers"></div>
16 - <div class="waveform-loading" style="display:none;"></div>
17 - <div class="waveform-error" style="display:none;">
18 - <span class="waveform-error-text">Unable to load audio</span>
19 - </div>
20 - </div>
21 - </div>
22 -
7 + `:"",n=this.options.showInfo?`
23 8 <div class="waveform-info">
24 - ${this.options.artwork?`
25 - <img class="waveform-artwork" src="${this.options.artwork}" alt="Album artwork" style="
9 + ${this.options.artworkPosition!=="button"&&this.options.artwork?`
10 + <img class="waveform-artwork" src="${M(this.options.artwork)}" alt="${M(this.options.artworkAlt)}" style="
26 11 width: 40px;
27 12 height: 40px;
28 13 border-radius: 4px;
29 14 object-fit: cover;
@@ -30,34 +15,51 @@
30 15 flex-shrink: 0;
31 16 ">
32 17 `:""}
33 18 <div class="waveform-text">
34 - <span class="waveform-title" style="color: ${this.options.textColor};"></span>
35 - ${this.options.subtitle?`<span class="waveform-subtitle" style="color: ${this.options.textSecondaryColor};">${this.options.subtitle}</span>`:""}
19 + <span class="waveform-title"></span>
20 + ${this.options.artist?`<span class="waveform-artist">${M(this.options.artist)}</span>`:""}
36 21 </div>
37 - <div style="display: flex; align-items: center; gap: 1rem;">
22 + <div class="waveform-meta" style="display: flex; align-items: center; gap: 1rem;">
38 23 ${this.options.showBPM?`
39 - <span class="waveform-bpm" style="color: ${this.options.textSecondaryColor}; display: none;">
24 + <span class="waveform-bpm" style="display: none;">
40 25 <span class="bpm-value">--</span> BPM
41 26 </span>
42 27 `:""}
43 28 ${this.options.showPlaybackSpeed?`
44 29 <div class="waveform-speed">
45 - <button class="speed-btn" aria-label="Playback speed">
30 + <button class="speed-btn" aria-label="${M(this.options.speedLabel)}" aria-haspopup="menu" aria-expanded="false">
46 31 <span class="speed-value">1x</span>
47 32 </button>
48 - <div class="speed-menu" style="display: none;">
49 - ${this.options.playbackRates.map(a=>`<button class="speed-option" data-rate="${a}">${a}x</button>`).join("")}
33 + <div class="speed-menu" role="menu" aria-label="${M(this.options.speedLabel)}" style="display: none;">
34 + ${this.options.playbackRates.map(l=>`<button class="speed-option" role="menuitemradio" tabindex="-1" aria-checked="false" data-rate="${l}">${l}x</button>`).join("")}
50 35 </div>
51 36 </div>
52 37 `:""}
53 38 ${this.options.showTime?`
54 - <span class="waveform-time" style="color: ${this.options.textSecondaryColor};">
39 + <span class="waveform-time">
55 40 <span class="time-current">0:00</span> / <span class="time-total">0:00</span>
56 41 </span>
57 42 `:""}
58 43 </div>
59 44 </div>
45 + `:"";this.container.innerHTML=`
46 + <div class="waveform-player-inner">
47 + <div class="waveform-body">
48 + <div class="waveform-track waveform-align-${t}">
49 + ${o}
50 +
51 + <div class="waveform-container">
52 + <canvas></canvas>
53 + <div class="waveform-markers"></div>
54 + <div class="waveform-loading" style="display:none;"></div>
55 + <div class="waveform-error" style="display:none;" role="alert">
56 + <span class="waveform-error-text">${M(this.options.errorText)}</span>
57 + </div>
58 + </div>
59 + </div>
60 +
61 + ${n}
60 62 </div>
61 63 </div>
62 -`,this.playBtn=this.container.querySelector(".waveform-btn"),this.canvas=this.container.querySelector("canvas"),this.ctx=this.canvas.getContext("2d"),this.titleEl=this.container.querySelector(".waveform-title"),this.subtitleEl=this.container.querySelector(".waveform-subtitle"),this.artworkEl=this.container.querySelector(".waveform-artwork"),this.currentTimeEl=this.container.querySelector(".time-current"),this.totalTimeEl=this.container.querySelector(".time-total"),this.bpmEl=this.container.querySelector(".waveform-bpm"),this.bpmValueEl=this.container.querySelector(".bpm-value"),this.loadingEl=this.container.querySelector(".waveform-loading"),this.errorEl=this.container.querySelector(".waveform-error"),this.markersContainer=this.container.querySelector(".waveform-markers"),this.speedBtn=this.container.querySelector(".speed-btn"),this.speedMenu=this.container.querySelector(".speed-menu"),this.resizeCanvas()}createAudio(){this.audio=new Audio,this.audio.preload=this.options.preload||"metadata",this.audio.crossOrigin="anonymous"}initPlaybackSpeed(){this.options.playbackRate&&this.options.playbackRate!==1&&(this.audio.playbackRate=this.options.playbackRate),this.options.showPlaybackSpeed&&this.initSpeedControls()}initSpeedControls(){let e=this.container.querySelector(".speed-btn"),a=this.container.querySelector(".speed-menu");!e||!a||(e.addEventListener("click",i=>{i.stopPropagation(),a.style.display=a.style.display==="none"?"block":"none"}),document.addEventListener("click",()=>{a.style.display="none"}),a.addEventListener("click",i=>{if(i.stopPropagation(),i.target.classList.contains("speed-option")){let r=parseFloat(i.target.dataset.rate);this.setPlaybackRate(r),a.style.display="none"}}),this.updateSpeedUI())}initKeyboardControls(){this.container.setAttribute("tabindex","-1"),this.container.addEventListener("click",()=>{w.getAllInstances().forEach(e=>{e!==this&&e.container.setAttribute("tabindex","-1")}),this.container.setAttribute("tabindex","0"),this.container.focus()}),this.container.addEventListener("keydown",e=>{if(document.activeElement!==this.container)return;let a=e.key,i=this.audio.currentTime;if(a>="0"&&a<="9"){e.preventDefault(),this.seekToPercent(parseInt(a)/10);return}let r={" ":()=>this.togglePlay(),ArrowLeft:()=>this.seekTo(Math.max(0,i-5)),ArrowRight:()=>this.seekTo(Math.min(this.audio.duration,i+5)),ArrowUp:()=>this.setVolume(Math.min(1,this.audio.volume+.1)),ArrowDown:()=>this.setVolume(Math.max(0,this.audio.volume-.1)),m:()=>this.audio.muted=!this.audio.muted,M:()=>this.audio.muted=!this.audio.muted};r[a]&&(e.preventDefault(),r[a]())})}initMediaSession(){!("mediaSession"in navigator)||!this.options.enableMediaSession||(navigator.mediaSession.metadata=new MediaMetadata({title:this.options.title||"Unknown Track",artist:this.options.subtitle||"",album:this.options.album||"",artwork:this.options.artwork?[{src:this.options.artwork,sizes:"512x512",type:"image/jpeg"}]:[]}),navigator.mediaSession.setActionHandler("play",()=>this.play()),navigator.mediaSession.setActionHandler("pause",()=>this.pause()),navigator.mediaSession.setActionHandler("seekbackward",()=>{this.seekTo(Math.max(0,this.audio.currentTime-10))}),navigator.mediaSession.setActionHandler("seekforward",()=>{this.seekTo(Math.min(this.audio.duration,this.audio.currentTime+10))}),navigator.mediaSession.setActionHandler("seekto",e=>{e.seekTime!==null&&this.seekTo(e.seekTime)}))}bindEvents(){this.playBtn.addEventListener("click",()=>this.togglePlay()),this.audio.addEventListener("loadstart",()=>this.setLoading(!0)),this.audio.addEventListener("loadedmetadata",()=>this.onMetadataLoaded()),this.audio.addEventListener("canplay",()=>this.setLoading(!1)),this.audio.addEventListener("play",()=>this.onPlay()),this.audio.addEventListener("pause",()=>this.onPause()),this.audio.addEventListener("ended",()=>this.onEnded()),this.audio.addEventListener("error",e=>this.onError(e)),this.canvas.addEventListener("click",e=>this.handleCanvasClick(e)),this.resizeHandler=ut(()=>this.resizeCanvas(),100),window.addEventListener("resize",this.resizeHandler)}setupResizeObserver(){"ResizeObserver"in window&&(this.resizeObserver=new ResizeObserver(()=>{this.resizeCanvas()}),this.canvas?.parentElement&&this.resizeObserver.observe(this.canvas.parentElement))}async load(e){try{this.setLoading(!0),this.progress=0,this.hasError=!1,this.audio.src=e,await new Promise((i,r)=>{let o=()=>{this.audio.removeEventListener("loadedmetadata",o),this.audio.removeEventListener("error",s),i()},s=n=>{this.audio.removeEventListener("loadedmetadata",o),this.audio.removeEventListener("error",s),r(n)};this.audio.addEventListener("loadedmetadata",o),this.audio.addEventListener("error",s)});let a=this.options.title||dt(e);if(this.titleEl&&(this.titleEl.textContent=a),this.options.waveform)this.setWaveformData(this.options.waveform);else try{let i=await Z(e,this.options.samples,this.options.showBPM);this.waveformData=i.peaks,i.bpm&&(this.detectedBPM=i.bpm,this.updateBPMDisplay())}catch(i){console.warn("Using placeholder waveform:",i),this.waveformData=St(this.options.samples)}this.drawWaveform(),this.renderMarkers(),this.initMediaSession(),this.options.onLoad&&this.options.onLoad(this)}catch(a){console.error("Failed to load audio:",a),this.onError(a)}finally{this.setLoading(!1)}}async loadTrack(e,a=null,i=null,r={}){this.isPlaying&&this.pause(),this.audio.src="",this.audio.load(),this.hasError=!1,this.errorEl&&(this.errorEl.style.display="none"),this.canvas&&(this.canvas.style.opacity="1"),this.playBtn&&(this.playBtn.disabled=!1),this.progress=0,this.waveformData=[],this.options=X(this.options,{url:e,title:a||this.options.title,subtitle:i||this.options.subtitle,...r}),r.preload&&(this.audio.preload=r.preload),this.subtitleEl&&(i?(this.subtitleEl.textContent=i,this.subtitleEl.style.display=""):i===""&&(this.subtitleEl.style.display="none")),r.artwork&&this.artworkEl&&(this.artworkEl.src=r.artwork),r.markers&&(this.options.markers=r.markers),await this.load(e),this.play()}setWaveformData(e){if(typeof e=="string")try{let a=JSON.parse(e);this.waveformData=Array.isArray(a)?a:[]}catch{this.waveformData=e.split(",").map(Number)}else this.waveformData=Array.isArray(e)?e:[];this.drawWaveform()}drawWaveform(){!this.ctx||this.waveformData.length===0||vt(this.ctx,this.canvas,this.waveformData,this.progress,{...this.options,waveformStyle:this.options.waveformStyle||"bars",color:this.options.waveformColor,progressColor:this.options.progressColor})}resizeCanvas(){if(!this.canvas||this.isDestroying)return;let e=window.devicePixelRatio||1,a=this.canvas.getBoundingClientRect();this.canvas.width=a.width*e,this.canvas.height=this.options.height*e,this.canvas.style.height=this.options.height+"px",this.canvas.parentElement.style.height=this.options.height+"px",this.drawWaveform()}renderMarkers(){!this.options.showMarkers||!this.options.markers?.length||!this.markersContainer||(this.markersContainer.innerHTML="",!(!this.audio||!this.audio.duration||this.audio.duration===0)&&this.options.markers.forEach((e,a)=>{if(e.time>this.audio.duration){console.warn(`Marker "${e.label}" at ${e.time}s exceeds audio duration of ${this.audio.duration}s`);return}let i=e.time/this.audio.duration*100,r=document.createElement("button");r.className="waveform-marker",r.style.left=`${i}%`,r.style.backgroundColor=e.color||"rgba(255, 255, 255, 0.5)",r.setAttribute("aria-label",e.label),r.setAttribute("data-time",e.time);let o=document.createElement("span");o.className="waveform-marker-tooltip",o.textContent=e.label,r.appendChild(o),r.addEventListener("click",s=>{s.stopPropagation(),this.seekTo(e.time),this.options.playOnSeek&&!this.isPlaying&&this.play()}),this.markersContainer.appendChild(r)}))}handleCanvasClick(e){if(!this.audio.duration)return;let a=this.canvas.getBoundingClientRect(),i=e.clientX-a.left,r=Math.max(0,Math.min(1,i/a.width));this.seekToPercent(r)}setLoading(e){this.isLoading=e,this.loadingEl&&(this.loadingEl.style.display=e?"block":"none")}onMetadataLoaded(){this.isDestroying||(this.totalTimeEl&&(this.totalTimeEl.textContent=K(this.audio.duration)),this.renderMarkers())}onPlay(){if(this.isDestroying)return;this.isPlaying=!0,this.playBtn.classList.add("playing");let e=this.playBtn.querySelector(".waveform-icon-play"),a=this.playBtn.querySelector(".waveform-icon-pause");e&&(e.style.display="none"),a&&(a.style.display="flex"),this.startSmoothUpdate(),this.container.dispatchEvent(new CustomEvent("waveformplayer:play",{bubbles:!0,detail:{player:this,url:this.options.url}})),this.options.onPlay&&this.options.onPlay(this)}onPause(){if(this.isDestroying)return;this.isPlaying=!1,this.playBtn.classList.remove("playing");let e=this.playBtn.querySelector(".waveform-icon-play"),a=this.playBtn.querySelector(".waveform-icon-pause");e&&(e.style.display="flex"),a&&(a.style.display="none"),this.stopSmoothUpdate(),this.container.dispatchEvent(new CustomEvent("waveformplayer:pause",{bubbles:!0,detail:{player:this,url:this.options.url}})),this.options.onPause&&this.options.onPause(this)}onEnded(){this.isDestroying||(this.progress=0,this.audio.currentTime=0,this.drawWaveform(),this.currentTimeEl&&(this.currentTimeEl.textContent="0:00"),this.container.dispatchEvent(new CustomEvent("waveformplayer:ended",{bubbles:!0,detail:{player:this,url:this.options.url}})),this.onPause(),this.options.onEnd&&this.options.onEnd(this))}onError(e){this.isDestroying||(console.error("Audio error:",e),this.hasError=!0,this.setLoading(!1),this.errorEl&&(this.errorEl.style.display="flex"),this.canvas&&(this.canvas.style.opacity="0.2"),this.playBtn&&(this.playBtn.disabled=!0),this.options.onError&&this.options.onError(e,this))}startSmoothUpdate(){this.stopSmoothUpdate();let e=()=>{this.isPlaying&&this.audio.duration&&(this.updateProgress(),this.updateTimer=requestAnimationFrame(e))};this.updateTimer=requestAnimationFrame(e)}stopSmoothUpdate(){this.updateTimer&&(cancelAnimationFrame(this.updateTimer),this.updateTimer=null)}updateProgress(){if(!this.audio.duration)return;let e=this.audio.currentTime/this.audio.duration;Math.abs(e-this.progress)>.001&&(this.progress=e,this.drawWaveform()),this.currentTimeEl&&(this.currentTimeEl.textContent=K(this.audio.currentTime)),this.container.dispatchEvent(new CustomEvent("waveformplayer:timeupdate",{bubbles:!0,detail:{player:this,currentTime:this.audio.currentTime,duration:this.audio.duration,url:this.options.url}})),this.options.onTimeUpdate&&this.options.onTimeUpdate(this.audio.currentTime,this.audio.duration,this)}updateBPMDisplay(){this.bpmEl&&this.bpmValueEl&&this.detectedBPM&&(this.bpmValueEl.textContent=Math.round(this.detectedBPM),this.bpmEl.style.display="inline-flex")}updateSpeedUI(){let e=this.container.querySelector(".speed-value");if(e){let a=this.audio.playbackRate;e.textContent=a===1?"1x":`${a}x`}this.container.querySelectorAll(".speed-option").forEach(a=>{a.classList.toggle("active",parseFloat(a.dataset.rate)===this.audio.playbackRate)})}play(){this.options.singlePlay&&w.currentlyPlaying&&w.currentlyPlaying!==this&&w.currentlyPlaying.pause(),w.currentlyPlaying=this,this.audio.play()}pause(){w.currentlyPlaying===this&&(w.currentlyPlaying=null),this.audio.pause()}togglePlay(){this.isPlaying?this.pause():this.play()}seekTo(e){this.audio&&this.audio.duration&&(this.audio.currentTime=Math.max(0,Math.min(e,this.audio.duration)),this.updateProgress())}seekToPercent(e){this.audio&&this.audio.duration&&(this.audio.currentTime=this.audio.duration*Math.max(0,Math.min(1,e)),this.updateProgress())}setVolume(e){this.audio&&(this.audio.volume=Math.max(0,Math.min(1,e)))}setPlaybackRate(e){if(!this.audio)return;let a=Math.max(.5,Math.min(2,e));this.audio.playbackRate=a,this.options.playbackRate=a,this.updateSpeedUI()}destroy(){this.isDestroying=!0,this.pause(),this.stopSmoothUpdate(),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.resizeHandler&&(window.removeEventListener("resize",this.resizeHandler),this.resizeHandler=null),w.instances.delete(this.id),w.currentlyPlaying===this&&(w.currentlyPlaying=null),this.audio&&(this.audio.pause(),this.audio.src="",this.audio.load(),this.audio=null),this.container.innerHTML="",this.canvas=null,this.ctx=null,this.playBtn=null,this.waveformData=[]}static getInstance(e){if(typeof e=="string"){let a=this.instances.get(e);if(a)return a;let i=document.getElementById(e);if(i)return Array.from(this.instances.values()).find(r=>r.container===i)}if(e instanceof HTMLElement)return Array.from(this.instances.values()).find(a=>a.container===e)}static getAllInstances(){return Array.from(this.instances.values())}static destroyAll(){this.instances.forEach(e=>e.destroy()),this.instances.clear()}static async generateWaveformData(e,a=200){try{return(await Z(e,a)).peaks}catch(i){throw console.error("Failed to generate waveform:",i),i}}};function D(){typeof document>"u"||document.querySelectorAll("[data-waveform-player]").forEach(t=>{if(t.dataset.waveformInitialized!=="true")try{new A(t),t.dataset.waveformInitialized="true"}catch(e){console.error("Failed to initialize WaveformPlayer:",e,t)}})}typeof document<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",D):D());A.init=D;typeof window<"u"&&(window.WaveformPlayer=A);var _=A;var Tt=100;function At(t){return t.ownerDocument.defaultView.getComputedStyle(t)}function Lt(t){let e=At(t).color,a=v(e).alpha(.3).toRgbString(),i=v(e).alpha(.6).toRgbString();return{textColor:e,waveformColor:a,progressColor:i}}function It({url:t,title:e,artist:a,artwork:i,waveformColor:r,progressColor:o,buttonColor:s,height:n=Tt}){let l=document.createElement("div");return l.setAttribute("data-waveform-player",""),l.setAttribute("data-url",t),l.setAttribute("data-height",String(n)),l.setAttribute("data-waveform-style","bars"),l.setAttribute("data-waveform-color",r),l.setAttribute("data-progress-color",o),l.setAttribute("data-button-color",s),l.setAttribute("data-text-color",s),l.setAttribute("data-text-secondary-color",s),e&&l.setAttribute("data-title",e),a&&l.setAttribute("data-subtitle",a),i&&l.setAttribute("data-artwork",i),l}function Rt(t,e){let i=v(e).isDark()?"#ffffff":"#000000";t.querySelectorAll("svg path").forEach(o=>{o.style.fill=i})}function Bt(t,{play:e="Play",pause:a="Pause"}={}){let i=t.querySelector(".waveform-btn");if(!i)return;i.setAttribute("aria-label",e);let r=()=>i.setAttribute("aria-label",a),o=()=>i.setAttribute("aria-label",e);return t.addEventListener("waveformplayer:play",r),t.addEventListener("waveformplayer:pause",o),t.addEventListener("waveformplayer:ended",o),()=>{t.removeEventListener("waveformplayer:play",r),t.removeEventListener("waveformplayer:pause",o),t.removeEventListener("waveformplayer:ended",o)}}function L(t){t.name!=="AbortError"&&console.error("Playlist play error:",t)}function tt(t,{src:e,title:a,artist:i,image:r,autoPlay:o,onEnded:s,labels:n}){let{textColor:l,waveformColor:h,progressColor:u}=Lt(t),c=It({url:e,title:a,artist:i,artwork:r,waveformColor:h,progressColor:u,buttonColor:l});t.appendChild(c);let m=new _(c),f,d={ready:()=>{Rt(c,l),f=Bt(c,n),o&&m.play()?.catch(L)},ended:()=>s?.()};return c.addEventListener("waveformplayer:ready",d.ready),c.addEventListener("waveformplayer:ended",d.ended),{instance:m,container:c,destroy:()=>{f?.(),c.removeEventListener("waveformplayer:ready",d.ready),c.removeEventListener("waveformplayer:ended",d.ended),m.destroy(),c.remove()}}}var N=new WeakMap,{state:Ht}=Wt("core/playlist",{state:{playlists:{},get isCurrentTrack(){let{currentId:t,uniqueId:e}=H();return t===e}},actions:{changeTrack(){let t=H();t.currentId=t.uniqueId}},callbacks:{initWaveformPlayer(){let t=H(),{ref:e}=Dt();if(!t.currentId||!e)return;let a=Ht.playlists[t.playlistId]?.tracks[t.currentId];if(!a?.url)return;let i=N.get(e);if(i?.url===a.url)return;let r=!!i?.url;Nt(e,a,r,t)}}},{lock:!0});function Nt(t,e,a,i){let r=N.get(t);if(r?.instance){r.instance.loadTrack(e.url,e.title,e.artist,{artwork:e.image}).then(()=>{r.url=e.url,a&&r.instance.play()?.catch(L)}).catch(L);return}let o={play:t.dataset.labelPlay,pause:t.dataset.labelPause},s=tt(t,{src:e.url,title:e.title,artist:e.artist,image:e.image,autoPlay:a,labels:o,onEnded:()=>{let n=i.tracks.findIndex(h=>h===i.currentId),l=i.tracks[n+1];l&&(i.currentId=l)}});N.set(t,{url:e.url,instance:s.instance,destroy:s.destroy})}
64 +`,this.playBtn=this.container.querySelector(".waveform-btn"),this.canvas=this.container.querySelector("canvas"),this.ctx=this.canvas.getContext("2d"),this.titleEl=this.container.querySelector(".waveform-title"),this.artistEl=this.container.querySelector(".waveform-artist"),this.artworkEl=this.container.querySelector(".waveform-artwork, .waveform-btn-artwork"),this.bindArtworkFallback(this.artworkEl),this.currentTimeEl=this.container.querySelector(".time-current"),this.totalTimeEl=this.container.querySelector(".time-total"),this.bpmEl=this.container.querySelector(".waveform-bpm"),this.bpmValueEl=this.container.querySelector(".bpm-value"),this.loadingEl=this.container.querySelector(".waveform-loading"),this.errorEl=this.container.querySelector(".waveform-error"),this.markersContainer=this.container.querySelector(".waveform-markers"),this.speedBtn=this.container.querySelector(".speed-btn"),this.speedMenu=this.container.querySelector(".speed-menu"),this.resizeCanvas(),this.updateBPMDisplay()}bindArtworkFallback(t){t&&t.addEventListener("error",()=>{t.src.startsWith("data:")||(t.src=Be)},{signal:this._ac.signal})}createArtworkElement(){let t=document.createElement("img");return t.className="waveform-artwork",t.style.width="40px",t.style.height="40px",t.style.borderRadius="4px",t.style.objectFit="cover",t.style.flexShrink="0",this.bindArtworkFallback(t),t}createButtonArtworkElement(){let t=document.createElement("img");return t.className="waveform-btn-artwork",t.alt="",t.setAttribute("aria-hidden","true"),this.bindArtworkFallback(t),t}createArtistElement(){let t=document.createElement("span");return t.className="waveform-artist",t}syncArtist(t){if(this.options.artist=t||null,!!this.options.showInfo){if(!t){this.artistEl?.remove(),this.artistEl=null;return}if(!this.artistEl){let i=this.container.querySelector(".waveform-title");if(!i)return;this.artistEl=this.createArtistElement(),i.after(this.artistEl)}this.artistEl.textContent=t,this.artistEl.style.display=""}}syncButtonArtwork(t){if(this.playBtn){if(!t){this.artworkEl?.remove(),this.artworkEl=null,this.playBtn.classList.remove("waveform-btn-has-artwork");return}this.artworkEl||(this.artworkEl=this.createButtonArtworkElement(),this.playBtn.prepend(this.artworkEl)),this.artworkEl.src=t,this.playBtn.classList.add("waveform-btn-has-artwork")}}syncArtwork(t,i=""){if(this.options.artwork=t||null,this.options.artworkAlt=i||"",this.options.artworkPosition==="button"){this.syncButtonArtwork(this.options.artwork);return}if(this.options.showInfo){if(!t){this.artworkEl?.remove(),this.artworkEl=null;return}if(!this.artworkEl){let r=this.container.querySelector(".waveform-text");if(!r)return;this.artworkEl=this.createArtworkElement(),r.before(this.artworkEl)}this.artworkEl.src=t,this.artworkEl.alt=i||""}}createAudio(){if(this.options.audioMode==="external"){this.audio=null;return}this.audio=new Audio,this.audio.preload=this.options.preload||"metadata",this.options.crossOrigin&&(this.audio.crossOrigin=this.options.crossOrigin)}initPlaybackSpeed(){this.audio&&this.options.playbackRate&&this.options.playbackRate!==1&&(this.audio.playbackRate=this.options.playbackRate),this.options.showPlaybackSpeed&&this.initSpeedControls()}initSpeedControls(){let t=this.container.querySelector(".speed-btn"),i=this.container.querySelector(".speed-menu");if(!t||!i)return;let r=()=>Array.from(i.querySelectorAll(".speed-option")),a=()=>i.style.display!=="none",s=l=>{if(i.style.display=l?"block":"none",t.setAttribute("aria-expanded",l?"true":"false"),l){let h=r();(h.find(u=>u.getAttribute("aria-checked")==="true")||h[0])?.focus()}},o=l=>{let h=r();h.length&&h[(l+h.length)%h.length].focus()},n=l=>{this.setPlaybackRate(parseFloat(l.dataset.rate)),s(!1),t.focus()};t.addEventListener("click",l=>{l.stopPropagation(),s(!a())},{signal:this._ac.signal}),document.addEventListener("click",()=>s(!1),{signal:this._ac.signal}),i.addEventListener("click",l=>{l.stopPropagation();let h=l.target.closest(".speed-option");h&&n(h)},{signal:this._ac.signal}),t.closest(".waveform-speed")?.addEventListener("keydown",l=>{let h=r(),u=h.indexOf(document.activeElement);if(!a()){(l.key==="ArrowDown"||l.key==="ArrowUp")&&document.activeElement===t&&(l.preventDefault(),s(!0));return}switch(l.key){case"ArrowDown":l.preventDefault(),o(u<0?0:u+1);break;case"ArrowUp":l.preventDefault(),o(u<0?h.length-1:u-1);break;case"Home":l.preventDefault(),o(0);break;case"End":l.preventDefault(),o(h.length-1);break;case"Escape":l.preventDefault(),s(!1),t.focus();break;case"Tab":s(!1);break}},{signal:this._ac.signal}),this.updateSpeedUI()}initKeyboardControls(){this.container.setAttribute("tabindex","-1"),this.container.addEventListener("click",t=>{t.target.closest(We)||(w.getAllInstances().forEach(i=>{i!==this&&i.container.setAttribute("tabindex","-1")}),this.container.setAttribute("tabindex","0"),this.container.focus())},{signal:this._ac.signal}),this.container.addEventListener("keydown",t=>{if(document.activeElement!==this.container)return;let i=t.key,r=!!this.audio,a=r?this.audio.currentTime:0;if(r&&i>="0"&&i<="9"){t.preventDefault(),this.seekToPercent(parseInt(i)/10);return}let s={" ":()=>this.togglePlay()};r&&(s.ArrowLeft=()=>this.seekTo(b(a-5,0,this.audio.duration)),s.ArrowRight=()=>this.seekTo(b(a+5,0,this.audio.duration)),s.ArrowUp=()=>this.setVolume(b(this.audio.volume+.1)),s.ArrowDown=()=>this.setVolume(b(this.audio.volume-.1)),s.m=s.M=()=>this.audio.muted=!this.audio.muted),s[i]&&(t.preventDefault(),s[i]())},{signal:this._ac.signal})}initSeekControl(){this.options.accessibleSeek&&(this.seekEl=this.container.querySelector(".waveform-container"),this.seekEl&&(this.seekEl.setAttribute("role","slider"),this.seekEl.setAttribute("tabindex","0"),this.seekEl.setAttribute("aria-valuemin","0"),this.applySeekLabel(),this.updateSeekAccessibility(),this.seekEl.addEventListener("keydown",t=>{if(t.key===" "||t.key==="Spacebar"){t.preventDefault(),t.stopPropagation(),this.togglePlay();return}let i=this.getSeekDuration();if(!i)return;let r=this.getSeekCurrentTime(),a;switch(t.key){case"ArrowLeft":case"ArrowDown":a=r-Nt;break;case"ArrowRight":case"ArrowUp":a=r+Nt;break;case"PageDown":a=r-$t;break;case"PageUp":a=r+$t;break;case"Home":a=0;break;case"End":a=i;break;default:return}t.preventDefault(),t.stopPropagation(),this.seekToSeconds(a)},{signal:this._ac.signal})))}getSeekDuration(){return this.options.audioMode==="external"?this._extDuration||0:this.audio&&Number.isFinite(this.audio.duration)?this.audio.duration:0}getSeekCurrentTime(){return this.options.audioMode==="external"?this.progress*(this._extDuration||0):this.audio&&Number.isFinite(this.audio.currentTime)?this.audio.currentTime:0}seekToSeconds(t){let i=this.getSeekDuration();if(!i)return;let r=b(t,0,i);if(this.options.audioMode==="external"){this._requestSeek(r/i),this.updateSeekAccessibility();return}this.seekTo(r)}applySeekLabel(t=this.options.title){if(!this.seekEl)return;let i=this.options.seekLabel||t||"Seek";this.seekEl.setAttribute("aria-label",i)}updateSeekAccessibility(){if(!this.seekEl)return;let t=this.getSeekDuration(),i=Math.min(this.getSeekCurrentTime(),t);this.seekEl.setAttribute("aria-valuemax",String(Math.round(t))),this.seekEl.setAttribute("aria-valuenow",String(Math.round(i))),this.seekEl.setAttribute("aria-valuetext",pe(this.options.seekValueText||"%1$s of %2$s",R(i),R(t)))}initMediaSession(){if(!("mediaSession"in navigator)||!this.options.enableMediaSession||!this.audio)return;this._applyMediaMetadata(),navigator.mediaSession.setActionHandler("play",()=>this.play()),navigator.mediaSession.setActionHandler("pause",()=>this.pause()),navigator.mediaSession.setActionHandler("seekbackward",()=>{this.seekTo(b(this.audio.currentTime-10,0,this.audio.duration))}),navigator.mediaSession.setActionHandler("seekforward",()=>{this.seekTo(b(this.audio.currentTime+10,0,this.audio.duration))}),navigator.mediaSession.setActionHandler("seekto",r=>{r.seekTime!==null&&this.seekTo(r.seekTime)});let t=this.options.onNextTrack,i=this.options.onPreviousTrack;try{navigator.mediaSession.setActionHandler("nexttrack",typeof t=="function"?()=>t(this):null)}catch{}try{navigator.mediaSession.setActionHandler("previoustrack",typeof i=="function"?()=>i(this):null)}catch{}}_applyMediaMetadata(){!("mediaSession"in navigator)||!this.options.enableMediaSession||(navigator.mediaSession.metadata=new MediaMetadata({title:this.options.title||this.options.unknownTrackText,artist:this.options.artist||"",album:this.options.album||"",artwork:this.options.artwork?[{src:this.options.artwork,sizes:"512x512",type:"image/jpeg"}]:[]}))}_updateMediaSession(t){if(!(!("mediaSession"in navigator)||!this.options.enableMediaSession||!this.audio))try{t==="playing"&&this.initMediaSession(),navigator.mediaSession.playbackState=t;let i=this.audio.duration;navigator.mediaSession.setPositionState&&i&&isFinite(i)&&navigator.mediaSession.setPositionState({duration:i,playbackRate:this.audio.playbackRate||1,position:b(this.audio.currentTime,0,i)})}catch{}}bindEvents(){this.playBtn&&this.playBtn.addEventListener("click",()=>this.togglePlay()),this.audio&&(this.audio.addEventListener("loadstart",()=>this.setLoading(!0)),this.audio.addEventListener("loadedmetadata",()=>this.onMetadataLoaded()),this.audio.addEventListener("canplay",()=>this.setLoading(!1)),this.audio.addEventListener("play",()=>this.onPlay()),this.audio.addEventListener("pause",()=>this.onPause()),this.audio.addEventListener("ended",()=>this.onEnded()),this.audio.addEventListener("error",i=>this.onError(i))),this.canvas.addEventListener("click",i=>this.handleCanvasClick(i)),this._dragging=!1,this._seekHover=!1,this._handleNear=!1,this.canvas.addEventListener("pointerenter",()=>{this._seekHover=!0,this.drawWaveform(),this._updateSeekHandle()}),this.canvas.addEventListener("pointerleave",()=>{this._seekHover=!1,this._handleNear=!1,this._dragging||this._hideHoverTip(),this.drawWaveform(),this._updateSeekHandle()}),this.canvas.addEventListener("pointerdown",i=>{if(!(i.pointerType==="mouse"&&i.button!==0)){this._dragging=!0;try{this.canvas.setPointerCapture(i.pointerId)}catch{}this._scrubTo(i.clientX)}}),this.canvas.addEventListener("pointermove",i=>{if(this._dragging){this._scrubTo(i.clientX);return}let r=this.canvas.getBoundingClientRect();r.width&&(this._handleNear=Math.abs(i.clientX-r.left-this.progress*r.width)<=10,this._updateSeekHandle())});let t=i=>{if(this._dragging){this._dragging=!1,this._suppressClick=!0;try{this.canvas.releasePointerCapture(i.pointerId)}catch{}this._seekFromPointer(i.clientX),!this._seekHover&&!this.options.showHoverTime&&this._hideHoverTip(),this._updateSeekHandle()}};this.canvas.addEventListener("pointerup",t),this.canvas.addEventListener("pointercancel",t),this.setupHoverTime(),this.setupSeekHandle(),this.resizeHandler=ve(()=>this.resizeCanvas(),100),window.addEventListener("resize",this.resizeHandler)}setupResizeObserver(){"ResizeObserver"in window&&(this.resizeObserver=new ResizeObserver(()=>{this.resizeCanvas()}),this.canvas?.parentElement&&this.resizeObserver.observe(this.canvas.parentElement))}async load(t){try{this.setLoading(!0),this.progress=0,this.hasError=!1,this.container.classList.remove("waveform-is-placeholder");let i=!!this.options.waveform;i&&this.setWaveformData(this.options.waveform);let r=this.options.title||zt(t);if(this.titleEl&&(this.titleEl.textContent=r),this.applySeekLabel(r),this.audio&&(this.audio.src=t,this.audio.preload!=="none"&&await new Promise((a,s)=>{let o=()=>{this.audio.removeEventListener("loadedmetadata",o),this.audio.removeEventListener("error",n),a()},n=l=>{this.audio.removeEventListener("loadedmetadata",o),this.audio.removeEventListener("error",n),s(l)};this.audio.addEventListener("loadedmetadata",o),this.audio.addEventListener("error",n)})),!i)try{let a=await Ht(t,this.options.samples,this.options.showBPM);this.waveformData=a.peaks,a.bpm&&(this.detectedBPM=a.bpm,this.updateBPMDisplay())}catch(a){console.warn("[WaveformPlayer] Using placeholder waveform:",a),this.waveformData=xe(this.options.samples),this.container.classList.add("waveform-is-placeholder")}this.drawWaveform(),this.renderMarkers(),this.options.onLoad&&this.options.onLoad(this)}catch(i){this.onError(i)}finally{this.setLoading(!1)}}async loadTrack(t,i=null,r=null,a={}){let s=Object.prototype.hasOwnProperty.call(a,"artwork"),o=Object.prototype.hasOwnProperty.call(a,"artworkAlt");this.isPlaying&&this.pause(),this.audio&&(this.audio.src="",this.audio.load()),this.hasError=!1,this.errorEl&&(this.errorEl.style.display="none"),this.canvas&&(this.canvas.style.opacity="1"),this.playBtn&&(this.playBtn.disabled=!1),this.progress=0,this.waveformData=[],this.options=It(Mt(this.options,{url:t,title:i===null?this.options.title:i,artist:r===null?this.options.artist:r,...a})),s&&(this.options.artwork=a.artwork||null),o?this.options.artworkAlt=a.artworkAlt||"":s&&(this.options.artworkAlt=this.options.artwork?at.artworkAlt:""),a.preload&&this.audio&&(this.audio.preload=this.options.preload),a.crossOrigin&&this.audio&&(this.audio.crossOrigin=this.options.crossOrigin),r!==null&&this.syncArtist(r),(s||o)&&this.syncArtwork(s?a.artwork:this.options.artwork,o?a.artworkAlt:this.options.artworkAlt),this.options.markers=a.markers?ot(a.markers):[],this.options.waveform=a.waveform||null,await this.load(t),a.autoplay!==!1&&this.play()?.catch(()=>{})}setWaveformData(t){if(typeof t=="string"&&t.trim().endsWith(".json")){fetch(t.trim()).then(i=>i.json()).then(i=>{this.waveformData=Array.isArray(i)?i:i.peaks||[],i.markers&&!this.options.markers?.length&&(this.options.markers=ot(i.markers),this.renderMarkers()),this.drawWaveform()}).catch(()=>{});return}this.waveformData=ht(t,{fallback:[]}),this.drawWaveform()}drawWaveform(){!this.ctx||this.waveformData.length===0||Ee(this.ctx,this.canvas,this.waveformData,this.progress,{...this.options,waveformStyle:this.options.waveformStyle||"bars",color:this.options.waveformColor,progressColor:this.options.progressColor,seekActive:this._seekHover||this._dragging})}resizeCanvas(){if(!this.canvas||this.isDestroying)return;let t=window.devicePixelRatio||1,i=this.canvas.parentElement.getBoundingClientRect();this.canvas.width=i.width*t,this.canvas.height=this.options.height*t,this.canvas.parentElement.style.height=this.options.height+"px",this.drawWaveform()}renderMarkers(){if(!this.markersContainer||(this.markersContainer.innerHTML="",this._activeMarkerIndex=-1,clearTimeout(this._markerLabelTimer),!this.options.showMarkers||!this.options.markers?.length))return;let t=this.getSeekDuration();t&&this.options.markers.forEach((i,r)=>{if(i.time>t){console.warn(`[WaveformPlayer] Marker "${i.label}" at ${i.time}s exceeds audio duration of ${t}s`);return}let a=i.time/t*100,s=document.createElement("button");s.className="waveform-marker",s.style.left=`${a}%`,s.style.backgroundColor=i.color||"rgba(255, 255, 255, 0.5)",s.setAttribute("aria-label",i.label),s.setAttribute("data-time",i.time);let o=document.createElement("span");o.className="waveform-marker-tooltip",o.textContent=i.label,s.appendChild(o),s.addEventListener("click",n=>{n.stopPropagation(),this.seekTo(i.time),this.options.playOnSeek&&!this.isPlaying&&this.play()}),this.markersContainer.appendChild(s)})}setActiveMarker(t){this.markersContainer&&this.markersContainer.querySelectorAll(".waveform-marker").forEach((i,r)=>i.classList.toggle("active",r===t))}updateActiveMarker(){if(!this.markersContainer)return;let t=this.markersContainer.querySelectorAll(".waveform-marker");if(!t.length)return;let i=this.getSeekDuration(),r=i?this.progress*i:0,a=-1,s=-1/0;t.forEach((o,n)=>{let l=parseFloat(o.getAttribute("data-time"));Number.isFinite(l)&&l<=r+.05&&l>s&&(s=l,a=n)}),a!==this._activeMarkerIndex&&(this._activeMarkerIndex=a,this.setActiveMarker(a),clearTimeout(this._markerLabelTimer),t.forEach((o,n)=>o.classList.toggle("show-label",n===a)),a>=0&&(this._markerLabelTimer=setTimeout(()=>{this.markersContainer?.querySelectorAll(".waveform-marker").forEach(o=>o.classList.remove("show-label"))},2500)))}setupHoverTime(){if(!this.seekEl)return;let t=document.createElement("div");t.className="waveform-hover-time",t.setAttribute("aria-hidden","true"),this.seekEl.appendChild(t),this.hoverTimeEl=t,this.options.showHoverTime&&(this.seekEl.addEventListener("pointermove",i=>{this._dragging||this._updateHoverTip(i.clientX)}),this.seekEl.addEventListener("pointerleave",()=>{this._dragging||this._hideHoverTip()}))}_updateHoverTip(t){let i=this.hoverTimeEl;if(!i)return;let r=this.getSeekDuration();if(!r){i.style.opacity="0";return}let a=this.canvas.getBoundingClientRect(),s=b((t-a.left)/a.width);i.textContent=R(s*r),i.style.left=s*100+"%",i.style.opacity="1"}_hideHoverTip(){this.hoverTimeEl&&(this.hoverTimeEl.style.opacity="0")}_scrubTo(t){let i=this.canvas.getBoundingClientRect();if(!i.width)return;this.progress=b((t-i.left)/i.width),this.drawWaveform(),this._updateSeekHandle();let r=this.getSeekDuration();r&&this.currentTimeEl?(this.currentTimeEl.textContent=R(this.progress*r),this._hideHoverTip()):this._updateHoverTip(t)}setupSeekHandle(){if(!this.options.seekHandle||this.options.waveformStyle!=="seekbar"||!this.seekEl)return;let t=document.createElement("div");t.className="waveform-seek-handle",t.setAttribute("aria-hidden","true"),this.seekEl.appendChild(t),this.seekHandleEl=t}_updateSeekHandle(){let t=this.seekHandleEl;t&&(t.style.left=this.progress*100+"%",t.classList.toggle("is-visible",this._seekHover||this._dragging),t.classList.toggle("is-active",this._dragging||this._handleNear))}handleCanvasClick(t){if(this._suppressClick){this._suppressClick=!1;return}this._seekFromPointer(t.clientX)}_seekFromPointer(t){let i=this.canvas.getBoundingClientRect();if(!i.width)return;let r=b((t-i.left)/i.width);if(this.options.audioMode==="external"){this._requestSeek(r);return}!this.audio||!this.audio.duration||this.seekToPercent(r)}setLoading(t){if(this.isLoading=t,this.loadingEl){let i=t&&this.waveformData.length===0;this.loadingEl.style.display=i?"block":"none"}this.seekEl&&this.seekEl.setAttribute("aria-busy",t?"true":"false")}onMetadataLoaded(){this.isDestroying||(this.totalTimeEl&&(this.totalTimeEl.textContent=R(this.audio.duration)),this.renderMarkers(),this.updateSeekAccessibility())}setPlayButtonState(t){if(!this.playBtn)return;this.playBtn.classList.toggle("playing",t);let i=this.playBtn.querySelector(".waveform-icon-play"),r=this.playBtn.querySelector(".waveform-icon-pause");i&&(i.style.display=t?"none":"flex"),r&&(r.style.display=t?"flex":"none")}onPlay(){this.isDestroying||(this.isPlaying=!0,this.setPlayButtonState(!0),this.startSmoothUpdate(),this._updateMediaSession("playing"),this._emit("waveformplayer:play",{player:this,url:this.options.url}),this.options.onPlay&&this.options.onPlay(this))}onPause(){this.isDestroying||(this.isPlaying=!1,this.setPlayButtonState(!1),this.stopSmoothUpdate(),this._updateMediaSession("paused"),this._emit("waveformplayer:pause",{player:this,url:this.options.url}),this.options.onPause&&this.options.onPause(this))}onEnded(){if(this.isDestroying)return;let t=this.audio.duration;this.progress=0,this.audio.currentTime=0,this.drawWaveform(),this.currentTimeEl&&(this.currentTimeEl.textContent="0:00"),this._emit("waveformplayer:ended",{player:this,url:this.options.url,currentTime:t,duration:t}),this.onPause(),this.options.onEnd&&this.options.onEnd(this)}onError(t){this.isDestroying||(console.error("[WaveformPlayer] Audio error:",t),this.hasError=!0,this.setLoading(!1),this.errorEl&&(this.errorEl.style.display="flex"),this.canvas&&(this.canvas.style.opacity="0.2"),this.playBtn&&(this.playBtn.disabled=!0),this.options.onError&&this.options.onError(t,this))}startSmoothUpdate(){this.stopSmoothUpdate();let t=()=>{this.isPlaying&&this.audio&&this.audio.duration&&(this.updateProgress(),this.updateTimer=requestAnimationFrame(t))};this.updateTimer=requestAnimationFrame(t)}stopSmoothUpdate(){this.updateTimer&&(cancelAnimationFrame(this.updateTimer),this.updateTimer=null)}updateProgress(){if(!this.audio||!this.audio.duration||this._dragging)return;let t=this.audio.currentTime/this.audio.duration;Math.abs(t-this.progress)>.001&&(this.progress=t,this.drawWaveform(),this._updateSeekHandle()),this.currentTimeEl&&(this.currentTimeEl.textContent=R(this.audio.currentTime)),this._emit("waveformplayer:timeupdate",{player:this,currentTime:this.audio.currentTime,duration:this.audio.duration,progress:this.progress,url:this.options.url}),this.options.onTimeUpdate&&this.options.onTimeUpdate(this.audio.currentTime,this.audio.duration,this),this.updateActiveMarker(),this.updateSeekAccessibility()}updateBPMDisplay(){let t=this.options.bpm||this.detectedBPM;this.bpmEl&&this.bpmValueEl&&t&&(this.bpmValueEl.textContent=Math.round(t),this.bpmEl.style.display="inline-flex")}refreshTheme(){if(!this._autoTheme)return;this._scheme=V(this.container);let t=Wt(this.options.colorPreset,this.container);for(let i of this._presetKeys||[])i in t&&(this.options[i]=t[i]);this._applyThemeColors()}_applyThemeColors(){this.container.classList.toggle("waveform-theme-light",this._scheme==="light"),this.canvas&&this.drawWaveform()}static _watchTheme(){if(w._themeWatch||typeof document>"u")return;let t=()=>requestAnimationFrame(()=>{w.instances.forEach(s=>{try{s.refreshTheme()}catch{}})}),i={attributes:!0,attributeFilter:["class","data-theme","data-color-scheme","style"]},r=new MutationObserver(t);r.observe(document.documentElement,i),document.body&&r.observe(document.body,i);let a=null;try{a=window.matchMedia("(prefers-color-scheme: dark)"),a.addEventListener("change",t)}catch{}w._themeWatch={obs:r,mq:a,refresh:t}}updateSpeedUI(){if(!this.audio)return;let t=this.container.querySelector(".speed-value");if(t){let i=this.audio.playbackRate;t.textContent=i===1?"1x":`${i}x`}this.container.querySelectorAll(".speed-option").forEach(i=>{let r=parseFloat(i.dataset.rate)===this.audio.playbackRate;i.classList.toggle("active",r),i.setAttribute("aria-checked",r?"true":"false")})}play(){if(this.options.singlePlay&&w.currentlyPlaying&&w.currentlyPlaying!==this&&w.currentlyPlaying.pause(),this.options.audioMode==="external"){this._emit("waveformplayer:request-play",this._buildTrackDetail(),!0).defaultPrevented||(w.currentlyPlaying=this);return}return w.currentlyPlaying=this,this.audio.play()}pause(){if(w.currentlyPlaying===this&&(w.currentlyPlaying=null),this.options.audioMode==="external"){this._emit("waveformplayer:request-pause",this._buildTrackDetail(),!0);return}this.audio.pause()}_buildTrackDetail(){return{url:this.options.url,title:this.options.title,artist:this.options.artist,artwork:this.options.artwork,markers:this.options.markers,waveform:this.options.waveform,id:this.id,player:this}}setPlayingState(t){let i=this.isPlaying;this.isPlaying=!!t,this.setPlayButtonState(this.isPlaying),this.isPlaying&&!i?(this.startSmoothUpdate?.(),this._emit("waveformplayer:play",{player:this,url:this.options.url}),this.options.onPlay&&this.options.onPlay(this)):!this.isPlaying&&i&&(this.stopSmoothUpdate?.(),this._emit("waveformplayer:pause",{player:this,url:this.options.url}),this.options.onPause&&this.options.onPause(this))}setProgress(t,i){!i||i<=0||(this.progress=b(t/i),this.currentTimeEl&&(this.currentTimeEl.textContent=R(t)),this._extDuration=i,this.totalTimeEl&&(!this.totalTimeEl.dataset._extSet||this.totalTimeEl.dataset._extDur!==String(i))&&(this.totalTimeEl.textContent=R(i),this.totalTimeEl.dataset._extSet="1",this.totalTimeEl.dataset._extDur=String(i)),this.drawWaveform?.(),this.updateActiveMarker(),this._emit("waveformplayer:timeupdate",{player:this,currentTime:t,duration:i,progress:this.progress,url:this.options.url}),this.options.onTimeUpdate&&this.options.onTimeUpdate(t,i,this),this.progress>=1?this._extEnded||(this._extEnded=!0,this._emit("waveformplayer:ended",{player:this,url:this.options.url,currentTime:i,duration:i}),this.options.onEnd&&this.options.onEnd(this)):this._extEnded=!1,this.updateSeekAccessibility())}togglePlay(){this.isPlaying?this.pause():this.play()}seekTo(t){this.audio&&this.audio.duration&&(this.audio.currentTime=b(t,0,this.audio.duration),this.updateProgress())}seekToPercent(t){this.audio&&this.audio.duration&&(this.audio.currentTime=this.audio.duration*b(t),this.updateProgress())}setVolume(t){let i=Number(t);this.audio&&Number.isFinite(i)&&(this.audio.volume=b(i))}setPlaybackRate(t){if(!this.audio)return;let i=J(t,null,{min:ut,max:dt});i!==null&&(this.audio.playbackRate=i,this.options.playbackRate=i,this.updateSpeedUI())}destroy(){this.isDestroying=!0,this._emit("waveformplayer:destroy",{player:this,url:this.options.url}),this.pause(),this.stopSmoothUpdate(),clearTimeout(this._markerLabelTimer),this._ac?.abort(),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.resizeHandler&&(window.removeEventListener("resize",this.resizeHandler),this.resizeHandler=null),w.instances.delete(this.id),w.currentlyPlaying===this&&(w.currentlyPlaying=null),this.audio&&(this.audio.pause(),this.audio.src="",this.audio.load(),this.audio=null),this.container.innerHTML="",delete this.container.dataset.waveformInitialized,this.canvas=null,this.ctx=null,this.playBtn=null,this.waveformData=[]}static getInstance(t){if(typeof t=="string"){let i=this.instances.get(t);if(i)return i;let r=document.getElementById(t);if(r)return Array.from(this.instances.values()).find(a=>a.container===r)}if(t instanceof HTMLElement)return Array.from(this.instances.values()).find(i=>i.container===t)}static getAllInstances(){return Array.from(this.instances.values())}static destroyAll(){this.instances.forEach(t=>t.destroy()),this.instances.clear()}static async generateWaveformData(t,i=1800){try{return(await Ht(t,i)).peaks}catch(r){throw console.error("[WaveformPlayer] Failed to generate waveform:",r),r}}static getPeaksUrl(t){if(!t)return;let i=t.replace(/\.(mp3|wav|ogg|flac|m4a|aac)(\?[^#]*)?(#.*)?$/i,".json$2$3");return i===t?void 0:i}};I.utils={formatTime:R,extractTitleFromUrl:zt,escapeHtml:M,isSafeHref:he,parseDataAttributes:Ft,detectColorScheme:V};var ct=()=>typeof window<"u"&&typeof document<"u",Ie=()=>!0;function Ot(e){if(!(e.dataset.waveformInitialized==="true"||I.getInstance(e)))try{new I(e),e.dataset.waveformInitialized="true"}catch(t){console.error("[WaveformPlayer] Failed to initialize:",t,e)}}function nt(e=document){if(!ct())return;let t=e||document;t.matches?.("[data-waveform-player]")&&Ot(t),t.querySelectorAll("[data-waveform-player]").forEach(Ot)}ct()&&!Ie()&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>nt()):nt());I.init=nt;ct()&&(window.WaveformPlayer=I);var Jt=I;var Ne=100,$e="Seek";function Qt(e){return e.ownerDocument.defaultView.getComputedStyle(e)}function Yt(e){let t=e?.trim().match(/^[\w-]+-gradient\((.*)\)$/i);if(!t)return[];let i=[],r=0,a="";for(let s of t[1]){if(s==="("?++r:s===")"&&--r,s===","&&r===0){i.push(a.trim()),a="";continue}a+=s}return a.trim()&&i.push(a.trim()),i}function Oe(e){let t=e.match(/^([\w-]+)\(/);if(!t||!["color","color-mix","hsl","hsla","hwb","lab","lch","oklab","oklch","rgb","rgba","var"].includes(t[1].toLowerCase()))return;let r=0,a=!1;for(let s=0;s<e.length;s++){let o=e[s];if(o==="("?(a=!0,++r):o===")"&&--r,a&&r===0)return e.slice(0,s+1)}}function qe(e){let t=Oe(e);if(t)return t;let[i]=e.split(/\s+/);if(k(i).isValid())return i}function Fe(e){let i=Yt(e)[0],r=i?.match(/^(-?\d+(?:\.\d+)?)deg$/i);if(r){let n=(Number(r[1])%360+360)%360;return n===90||n===270?"horizontal":n===0||n===180?"vertical":"diagonal"}if(!i?.startsWith("to "))return;let a=i.toLowerCase().replace(/^to\s+/,""),s=a.includes("left")||a.includes("right"),o=a.includes("top")||a.includes("bottom");if(s&&o)return"diagonal";if(s)return"horizontal";if(o)return"vertical"}function ze(e,t){if(!t||k(t).isValid())return t;let i=e.ownerDocument.createElement("span");if(i.style.color=t,!i.style.color)return t;e.appendChild(i);let r=Qt(i).color;return i.remove(),r&&k(r).isValid()?r:t}function pt(e,t){let i=Ue(t)?.map(r=>ze(e,r)).filter(r=>k(r).isValid());return i?.length>1?i:void 0}function Kt(e,t){return Array.isArray(e)?e.map(i=>k(i).alpha(t).toRgbString()):k(e).alpha(t).toRgbString()}function Zt(e){return Array.isArray(e)?e[e.length-1]:e}function Ue(e){let t=Yt(e).map(qe).filter(Boolean);return t.length>1?t:void 0}function Xt(e){return Array.isArray(e)?JSON.stringify(e):e}function je(e,t,i,r){let a=i||Qt(e).color,s=pt(e,r),o=s||t||a,n=Kt(o,.3),l=Kt(o,.6),h=s?Fe(r):void 0;return{textColor:a,waveformColor:n,progressColor:l,...h&&{waveformGradient:h}}}function Ge({url:e,title:t,artist:i,artwork:r,waveformColor:a,progressColor:s,waveformGradient:o,buttonColor:n,seekLabel:l,seekValueText:h,height:u=Ne,waveformStyle:c="bars"}){let p=document.createElement("div");return p.setAttribute("data-waveform-player",""),p.setAttribute("data-url",e),p.setAttribute("data-height",String(u)),p.setAttribute("data-waveform-style",c),p.setAttribute("data-waveform-color",Xt(a)),p.setAttribute("data-progress-color",Xt(s)),o&&p.setAttribute("data-waveform-gradient",o),p.setAttribute("data-button-color",n),p.setAttribute("data-seek-label",te(l)),h&&p.setAttribute("data-seek-value-text",h),p.setAttribute("data-text-color",n),p.setAttribute("data-text-secondary-color",n),t&&p.setAttribute("data-title",t),i&&p.setAttribute("data-artist",i),r&&p.setAttribute("data-artwork",r),p}function Ve(e,{backgroundColor:t,backgroundGradient:i,textColor:r,playButtonColor:a,playButtonGradient:s}={}){let o=e.querySelector(".waveform-container"),n=e.querySelector(".waveform-btn"),l=Zt(pt(e,s)||a);l?e.style.setProperty("--wfp-button-color",l):e.style.removeProperty("--wfp-button-color"),r?(e.style.setProperty("--wfp-text-color",r),e.style.setProperty("--wfp-text-secondary-color",r)):(e.style.removeProperty("--wfp-text-color"),e.style.removeProperty("--wfp-text-secondary-color")),n&&(s?n.style.background=s:n.style.removeProperty("background")),o&&(i?o.style.background=i:t?(o.style.removeProperty("background"),o.style.backgroundColor=t):(o.style.removeProperty("background"),o.style.removeProperty("background-color")))}function Je(e,t){let r=k(t).isDark()?"#ffffff":"#000000";e.querySelectorAll("svg path").forEach(s=>{s.style.fill=r})}function Ke(e,{play:t="Play",pause:i="Pause"}={}){let r=e.querySelector(".waveform-btn");if(!r)return;r.setAttribute("aria-label",t);let a=()=>r.setAttribute("aria-label",i),s=()=>r.setAttribute("aria-label",t);return e.addEventListener("waveformplayer:play",a),e.addEventListener("waveformplayer:pause",s),e.addEventListener("waveformplayer:ended",s),()=>{e.removeEventListener("waveformplayer:play",a),e.removeEventListener("waveformplayer:pause",s),e.removeEventListener("waveformplayer:ended",s)}}function te(e){return e||$e}function ee(e,t){let i=te(t);e.options.seekLabel=i,e.applySeekLabel?.(i);let r=e?.container?.querySelector(".waveform-container");r&&r.setAttribute("aria-label",i)}function mt(e,t){if(!t){e.classList.remove("has-play-button-artwork"),e.style.removeProperty("--wp--playlist--play-button-artwork");return}e.classList.add("has-play-button-artwork"),e.style.setProperty("--wp--playlist--play-button-artwork",`url(${JSON.stringify(t)})`)}function q(e){e.name!=="AbortError"&&console.error("Playlist play error:",e)}function ie(e,{src:t,title:i,artist:r,image:a,imageAlt:s,waveformColor:o,waveformGradient:n,textColor:l,backgroundColor:h,backgroundGradient:u,autoPlay:c,onEnded:p,labels:y,waveformStyle:g,showPlayButtonArtwork:m=!1}){let f=m?void 0:a,{textColor:v,waveformColor:d,progressColor:E,waveformGradient:P}=je(e,o,l,n),C=pt(e,n),_=Zt(C||o),T=Ge({url:t,title:i,artist:r,artwork:f,waveformColor:d,progressColor:E,waveformGradient:P,buttonColor:v,seekLabel:i||y?.seek,seekValueText:y?.seekValueText,waveformStyle:g});e.appendChild(T);let N=new Jt(T);N.artworkEl&&(N.artworkEl.alt=s||""),Ve(T,{backgroundColor:h,backgroundGradient:u,textColor:v,playButtonColor:m?void 0:_,playButtonGradient:m?void 0:n});let yt,z={ready:()=>{Je(T,_||v),m&&mt(T,a),yt=Ke(T,y),c&&N.play()?.catch(q)},ended:()=>p?.()};return T.addEventListener("waveformplayer:ready",z.ready),T.addEventListener("waveformplayer:ended",z.ended),{instance:N,container:T,destroy:()=>{yt?.(),T.removeEventListener("waveformplayer:ready",z.ready),T.removeEventListener("waveformplayer:ended",z.ended),N.destroy(),T.remove()}}}var X=new WeakMap,ft=new Map,{state:re}=Xe("core/playlist",{state:{playlists:{},get isCurrentTrack(){let{currentId:e,trackId:t}=F();return e===t},get isCurrentTrackPlaying(){let{currentId:e,isPlaying:t,trackId:i}=F();return e===i&&!!t},get trackButtonActionLabel(){let{labelPauseTrack:e,labelSelectTrack:t}=F();return re.isCurrentTrackPlaying?e:t}},actions:{changeTrack(){let e=F();if(e.currentId===e.trackId){let t=ft.get(e.playlistId)?.instance;t?.isPlaying?(e.isPlaying=!1,t.pause()):t?.play()?.catch(q);return}e.isPlaying=!1,e.currentId=e.trackId}},callbacks:{initWaveformPlayer(){let e=F(),{ref:t}=Qe();if(!e.currentId||!t)return;let i=re.playlists[e.playlistId]?.tracks[e.currentId];if(!i?.url)return;let r=X.get(t);if(r?.url===i.url)return;let a=!!r?.url;Ye(t,i,a,e)}}},{lock:!0});function Ye(e,t,i,r){let a=X.get(e),s=r.showPlayButtonArtwork===!0,o=s?"":t.image;if(a?.instance)if(!!a.instance.artworkEl!=!!o)a.destroy?.(),X.delete(e);else{ft.set(r.playlistId,a),a.instance.loadTrack(t.url,t.title,t.artist,{artwork:o,artworkAlt:o?t.imageAlt:""}).then(()=>{a.url=t.url,a.instance.artworkEl&&(a.instance.artworkEl.alt=t.imageAlt||""),ee(a.instance,t.title||e.dataset.labelSeek),s&&mt(a.container,t.image),i&&a.instance.play()?.catch(q)}).catch(q);return}let n={play:e.dataset.labelPlay,pause:e.dataset.labelPause,seek:e.dataset.labelSeek,seekValueText:e.dataset.labelSeekValue},l=ie(e,{src:t.url,title:t.title,artist:t.artist,image:t.image,imageAlt:t.imageAlt,waveformColor:e.dataset.waveformPlayerColor,waveformGradient:e.dataset.waveformPlayerGradient,backgroundColor:e.dataset.waveformPlayerBackgroundColor,backgroundGradient:e.dataset.waveformPlayerBackgroundGradient,autoPlay:i,labels:n,waveformStyle:r.waveformStyle,showPlayButtonArtwork:s,onEnded:()=>{let g=r.tracks.findIndex(f=>f===r.currentId),m=r.tracks[g+1];m&&(r.currentId=m)}}),h=g=>{r.isPlaying=g},u=()=>h(!0),c=()=>h(!1);l.container.addEventListener("waveformplayer:play",u),l.container.addEventListener("waveformplayer:pause",c),l.container.addEventListener("waveformplayer:ended",c);let p=()=>{l.container.removeEventListener("waveformplayer:play",u),l.container.removeEventListener("waveformplayer:pause",c),l.container.removeEventListener("waveformplayer:ended",c),l.destroy()},y={url:t.url,instance:l.instance,container:l.container,destroy:p};X.set(e,y),ft.set(r.playlistId,y)}
63 65 //# sourceMappingURL=view.min.js.map