import{d as se,w as S,a3 as ne,c as v,G as le,K,r as b,J as j,e as k,u as T,a4 as L,g as _,ag as re,H as Q,n as $,F as N,P as V,ae as J,a2 as oe,b2 as ce,b as f,j as D,m as ue,W as de}from"./lucide-6UWTdd2w.js";import{_ as fe}from"./ScrollArea.vue_vue_type_script_setup_true_lang-Dps0Zj2p.js";import{_ as me}from"./Spinner.vue_vue_type_script_setup_true_lang-D2YA2hGp.js";import{P as Z,$ as H,_ as ve,s as P}from"./index-CPxkwG0x.js";function ye(c,e,s){if(c===void 0||e===void 0||s!==void 0&&s!==Z.PLAYING)return c;const y=e*1e3,l=Date.now(),u=Math.max(0,l-y)/1e3;return c+u}const pe=c=>{const e=c.match(/\[(\d+):(\d+)([.:]\d+)?\](.*)/);if(e){const s=parseInt(e[1]),y=parseInt(e[2]);let l=0;if(e[3]){const p=e[3].replace(/[.:]/,".");l=Math.round(parseFloat(p)*1e3)}return{time:(s*60*1e3+y*1e3+l)/1e3,text:e[4].trim()||" "}}return{time:0,text:c.trim()||" "}},he={class:"lyrics-container"},ge={key:0,class:"lyrics-loading"},_e={key:1,class:"lyrics-empty"},ke={key:0,class:"lyrics-intro"},Le={class:"artist-name"},be={class:"lyrics-coming-soon"},Ie={class:"lyrics-content"},W=5,Te=5,I=7,X=.5,xe=se({__name:"LyricsViewer",props:{mediaItem:{default:void 0},position:{default:void 0},streamDetails:{default:void 0},textColor:{default:"#FFFFFF"},lyrics:{default:void 0},lrcLyrics:{default:void 0},anticipation:{default:0},externalLoading:{type:Boolean,default:!1},highlightAhead:{type:Boolean,default:!0}},setup(c){ce(t=>({v42f55e5a:ae.value,v60a9a7a8:t.textColor}));const e=c,s=b([]),y=b(!1),l=b(-1),m=b(null),u=new Map,p=b(0),d=b(!1),C=(t,a)=>{t?u.set(a,t):u.delete(a)},x=_(()=>{if(!w.value||!s.value.length)return!1;const t=s.value[0].time;return t<2?!1:(e.position||0)<t-e.anticipation}),ee=_(()=>{if(!e.mediaItem)return"";if("media_type"in e.mediaItem&&e.mediaItem.media_type==="track"){const t=e.mediaItem;if(t.artists?.length)return t.artists.map(a=>a.name).join(", ")}return"media_type"in e.mediaItem&&e.mediaItem.media_type==="artist"?e.mediaItem.name:""}),O=()=>e.lyrics??e.mediaItem?.metadata?.lyrics??null,Y=()=>e.lrcLyrics??e.mediaItem?.metadata?.lrc_lyrics??null,w=_(()=>{if(s.value.some(i=>i.time>0))return!0;const t=Y(),a=O();return!!(t&&t.includes("[")||a&&/\[\d+:\d+[.:]?\d*\]/.test(a))}),te=()=>{y.value=!0;try{const t=Y()||"",a=O()||"";let i="",n=!1;if(t?(i=t,n=!0):a&&/\[\d+:\d+[.:]?\d*\]/.test(a)?(i=a,n=!0):a&&(i=a,n=!1),n){const o=i.split(`
`).filter(r=>r.trim()).map(r=>pe(r)).sort((r,B)=>r.time-B.time),g=new Set;for(const r of o)!r.text.trim()&&r.time>0&&g.add(r.time);const h=o.filter(r=>r.text.trim()),E=[];if(h.length>0){const r=h[0].time;r>=W&&E.push({time:r-W,text:"",isBreak:!0,breakEnd:r})}for(let r=0;r<h.length;r++)if(E.push({time:h[r].time,text:h[r].text,isBreak:!1}),r<h.length-1){const B=h[r].time,F=h[r+1].time;let M=null;for(const R of g)if(R>B&&R<F){M=R;break}M!==null&&F-M>=Te&&E.push({time:M,text:"",isBreak:!0,breakEnd:F})}s.value=E}else i?s.value=i.split(`
`).filter(o=>o.trim()).map(o=>({time:0,text:o.trim(),isBreak:!1})).filter(o=>o.text):s.value=[]}catch(t){console.error(`[LyricsViewer] Error processing lyrics: ${t}`),s.value=[]}finally{y.value=!1}},U=_(()=>{const t=l.value;if(t<0)return{filled:I,percent:100};const a=s.value[t];if(!a?.isBreak||!a.breakEnd)return{filled:I,percent:100};const i=e.position||0,n=a.breakEnd-z.value-a.time;if(n<=0)return{filled:I,percent:100};const g=Math.max(0,i-a.time)/n*I;return{filled:Math.min(I,Math.floor(g)),percent:Math.round((g-Math.floor(g))*100)}}),A=_(()=>U.value.filled),q=_(()=>U.value.percent),ae=_(()=>`${X}s`),z=_(()=>e.highlightAhead?X:0),ie=t=>{let a=-1;for(let i=0;i<s.value.length&&Math.round(s.value[i].time*1e3)<=t;i++)a=i;return a},G=t=>{const a=u.get(t),i=m.value;if(!a||!i)return;const o=i.clientHeight*(e.anticipation>0?.5:.35),g=a.offsetTop,h=a.offsetHeight;p.value=o-g-h/2};return S([()=>e.mediaItem?.item_id,()=>e.lyrics,()=>e.lrcLyrics],()=>{l.value=-1,p.value=99999,d.value=!1,u.clear(),te(),D(()=>{const t=u.get(0),a=m.value;t&&a&&(p.value=a.clientHeight-t.offsetTop+40)})},{immediate:!0}),S(()=>e.position,t=>{if(t===void 0||!s.value.length||!w.value)return;const a=Math.round((t+z.value)*1e3),i=ie(a);if(i!==l.value)if(i>=0)d.value=!0,l.value=i,D(()=>G(i));else{l.value=-1,d.value=!0;const n=u.get(0),o=m.value;n&&o&&(p.value=o.clientHeight-n.offsetTop+40)}}),S(x,t=>{!t&&s.value.length&&(d.value=!0,D(()=>G(0)))}),ne(()=>{u.clear()}),(t,a)=>(f(),v("div",he,[y.value||c.externalLoading?(f(),v("div",ge,[j(T(me),{class:"size-6"}),k("div",null,L(T(H)("loading_lyrics")),1)])):s.value.length?w.value?(f(),v("div",{key:2,ref_key:"syncedContainerRef",ref:m,class:"synced-container"},[j(re,{name:"intro-fade"},{default:Q(()=>[x.value?(f(),v("div",ke,[k("div",{class:"song-title",style:$({color:c.textColor})},L(e.mediaItem?.name),5),k("div",Le,L(ee.value),1),k("div",be,L(T(H)("lyrics_will_appear_soon")),1)])):K("",!0)]),_:1}),k("div",{class:"synced-content",style:$({transform:`translateY(${p.value}px)`,transition:d.value?void 0:"none"})},[(f(!0),v(N,null,V(s.value,(i,n)=>(f(),v("div",{key:n,ref_for:!0,ref:o=>C(o,n),class:J(["lyrics-line",{active:l.value===n,"lyrics-line--far":l.value>=0&&(n===l.value+2||n===l.value-1),"lyrics-line--hidden":l.value>=0?n<l.value-1||n>l.value+2:n>2}])},[i.isBreak?(f(),v(N,{key:1},V(I,o=>k("span",{key:o,class:J(["break-note",{"break-note--filled":l.value===n&&o<=A.value,"break-note--filling":l.value===n&&o===A.value+1}]),style:$(l.value===n&&o===A.value+1?{backgroundImage:`linear-gradient(to right, ${c.textColor} ${q.value}%, color-mix(in srgb, ${c.textColor} 35%, transparent) ${q.value}%)`,backgroundClip:"text","-webkit-background-clip":"text","-webkit-text-fill-color":"transparent"}:void 0)},"♫",6)),64)):(f(),v(N,{key:0},[oe(L(i.text),1)],64))],2))),128))],4)],512)):e.anticipation?K("",!0):(f(),le(T(fe),{key:3,class:"h-full w-full static-lyrics"},{default:Q(()=>[k("div",Ie,[(f(!0),v(N,null,V(s.value,(i,n)=>(f(),v("div",{key:n,class:"lyrics-line active"},L(i.text),1))),128))])]),_:1})):(f(),v("div",_e,L(T(H)("no_lyrics_available")),1))]))}}),Ce=ve(xe,[["__scopeId","data-v-ee0f6db2"]]);function we(c){const e=b(0);let s=null;const y=()=>{const d=P.activePlayerQueue;d?.elapsed_time!=null&&d?.elapsed_time_last_updated!=null&&(e.value=ye(d.elapsed_time,d.elapsed_time_last_updated,P.activePlayer?.playback_state)??0),s=requestAnimationFrame(y)},l=()=>{s||(s=requestAnimationFrame(y))},m=()=>{s&&(cancelAnimationFrame(s),s=null)};let u=!1;const p=()=>{document.visibilityState==="visible"&&u?l():m()};return document.addEventListener("visibilitychange",p),ue(()=>{const d=P.activePlayer?.playback_state===Z.PLAYING,C=P.activePlayerQueue,x=c?c.value:!0;u=d&&!!C?.active&&x,u&&document.visibilityState==="visible"?l():m()}),de(()=>{m(),document.removeEventListener("visibilitychange",p)}),{elapsedTime:e,start:l,stop:m}}export{Ce as L,ye as c,we as u};
