import{d as z,G as j,u as p,D as X,H as B,J as T,e as d,h as ce,w as R,a3 as ue,b as v,K as D,r as y,f as b,a4 as k,c as S,ag as de,n as V,F as M,O as F,a$ as fe,ae as $,a2 as me,j as O,m as ve,W as pe}from"./lucide-8Ndi-dzR.js";import{e as Z,$ as Y,_ as ye,P as ee,s as N}from"./index-B4UsuA0L.js";import{S as he,q as ge,r as _e,s as be,t as ke}from"./reka-ui-BHSAaj2P.js";import{l as te}from"./vueuse-BJLUrvf_.js";import{_ as Le}from"./Spinner.vue_vue_type_script_setup_true_lang-Dunh1tEM.js";const xe=z({__name:"ScrollBar",props:{orientation:{default:"vertical"},forceMount:{type:Boolean},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array],default:void 0}},setup(i){const e=i,a=te(e,"class");return(o,u)=>(d(),j(p(he),X({"data-slot":"scroll-area-scrollbar"},p(a),{class:p(Z)("flex touch-none p-px transition-colors select-none",i.orientation==="vertical"&&"h-full w-2.5 border-l border-l-transparent",i.orientation==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent",e.class)}),{default:B(()=>[T(p(ge),{"data-slot":"scroll-area-thumb",class:"bg-border relative flex-1 rounded-full"})]),_:1},16,["class"]))}}),Se=z({__name:"ScrollArea",props:{type:{},dir:{},scrollHideDelay:{},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},setup(i){const e=i,a=te(e,"class");return(o,u)=>(d(),j(p(_e),X({"data-slot":"scroll-area"},p(a),{class:p(Z)("relative",e.class)}),{default:B(()=>[T(p(be),{"data-slot":"scroll-area-viewport",class:"focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1"},{default:B(()=>[ce(o.$slots,"default")]),_:3}),T(xe),T(p(ke))]),_:3},16,["class"]))}}),ae=(i,e,a)=>{const o=parseInt(i),u=parseInt(e);let n=0;if(a){const h=a.replace(/[.:]/,".");n=Math.round(parseFloat(h)*1e3)}return(o*60*1e3+u*1e3+n)/1e3},we=i=>{const e=/<(\d+):(\d+)([.:]\d+)?>\s*([^<]*)/g,a=[];let o;for(;(o=e.exec(i))!==null;){const u=ae(o[1],o[2],o[3]),n=o[4].trim();n&&a.push({time:u,text:n})}return a.length>0?a:void 0},Ie=i=>{const e=i.match(/\[(\d+):(\d+)([.:]\d+)?\](.*)/);if(e){const a=ae(e[1],e[2],e[3]),o=e[4],u=we(o),n=u?u.map(h=>h.text).join(" "):o.trim()||" ";return{time:a,text:n,words:u}}return{time:0,text:i.trim()||" "}},Me={class:"lyrics-container"},Te={key:0,class:"lyrics-loading"},Ce={key:1,class:"lyrics-empty"},Ae={key:0,class:"lyrics-intro"},Pe={class:"artist-name"},Be={class:"lyrics-coming-soon"},Ee={class:"lyrics-content"},Fe=2,P=7,$e=1,Ne=z({__name:"LyricsViewer",props:{mediaItem:{default:void 0},position:{default:void 0},duration:{default:void 0},streamDetails:{default:void 0},textColor:{default:"#FFFFFF"},debugMode:{type:Boolean,default:!1},lyrics:{default:void 0},lrcLyrics:{default:void 0},anticipation:{default:0},externalLoading:{type:Boolean,default:!1}},setup(i){fe(t=>({d587eb32:t.textColor}));const e=i,a=y([]),o=y(new Set),u=y(!1),n=y(-1),h=y(null),w=y(null),g=y(null),L=new Map,I=y(0),C=y(!1),se=(t,s)=>{t?L.set(s,t):L.delete(s)},q=S(()=>{if(!E.value||!a.value.length)return!1;const t=a.value[0].time,s=e.position||0;return n.value===-1&&s<t-e.anticipation}),re=S(()=>{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(s=>s.name).join(", ")}return"media_type"in e.mediaItem&&e.mediaItem.media_type==="artist"?e.mediaItem.name:""}),G=()=>e.lyrics??e.mediaItem?.metadata?.lyrics??null,U=()=>e.lrcLyrics??e.mediaItem?.metadata?.lrc_lyrics??null,E=S(()=>{if(a.value.some(r=>r.time>0))return!0;const t=U(),s=G();return!!(t&&t.includes("[")||s&&/\[\d+:\d+[.:]?\d*\]/.test(s))}),le=()=>{u.value=!0;try{const t=U()||"",s=G()||"";let r="",l=!1;if(t?(r=t,l=!0):s&&/\[\d+:\d+[.:]?\d*\]/.test(s)?(r=s,l=!0):s&&(r=s,l=!1),l){const f=r.split(`
`).filter(m=>m.trim()).map(m=>Ie(m)).sort((m,oe)=>m.time-oe.time),x=new Set;for(const m of f)!m.text.trim()&&m.time>0&&x.add(m.time);o.value=x,a.value=f.filter(m=>m.text.trim())}else if(r){const c=r.split(`
`).filter(f=>f.trim());a.value=c.map(f=>({time:0,text:f.trim()})).filter(f=>f.text)}else a.value=[]}catch(t){console.error(`[LyricsViewer] Error processing lyrics: ${t}`),a.value=[]}finally{u.value=!1}},W=S(()=>{const t=new Map,s=a.value,r=o.value;if(!r.size)return t;for(let l=0;l<s.length-1;l++){const c=s[l].time,f=s[l+1].time;let x=!1;for(const m of r)if(m>c&&m<f){x=!0;break}x&&t.set(l,{gapStart:c+Fe,gapEnd:f})}return t}),A=y(!1),_=y(-1),K=S(()=>{if(!A.value||_.value<0)return{filled:P,percent:100};const t=W.value.get(_.value);if(!t)return{filled:P,percent:100};const s=e.position||0,r=t.gapEnd-t.gapStart,c=Math.max(0,s-t.gapStart)/r*P;return{filled:Math.min(P,Math.floor(c)),percent:Math.round((c-Math.floor(c))*100)}}),H=S(()=>K.value.filled),Q=S(()=>K.value.percent),ne=t=>(e.position||0)>=t,ie=t=>{let s=-1;for(let r=0;r<a.value.length&&Math.round(a.value[r].time*1e3)<=t;r++)s=r;return s},J=t=>{const s=L.get(t),r=w.value;if(!s||!r)return;const c=r.clientHeight*.35,f=s.offsetTop,x=s.offsetHeight;I.value=c-f-x/2};return R([()=>e.mediaItem?.item_id,()=>e.lyrics,()=>e.lrcLyrics],()=>{n.value=-1,_.value=-1,A.value=!1,I.value=99999,C.value=!1,L.clear(),le(),O(()=>{const t=w.value;t&&E.value&&(I.value=t.clientHeight)})},{immediate:!0}),R(q,(t,s)=>{s&&!t&&!C.value&&(C.value=!0,O(()=>J(0)))}),R(()=>e.position,t=>{if(t===void 0||!a.value.length||!E.value)return;const s=Math.round((t+$e)*1e3),r=ie(s);r!==n.value&&r>=0&&(C.value=!0,n.value=r,O(()=>J(r)));const l=W.value.get(n.value);l&&t>=l.gapStart&&t<l.gapEnd?(A.value=!0,_.value=n.value):(A.value=!1,_.value>=0&&n.value>_.value+1&&(_.value=-1))}),ue(()=>{L.clear()}),(t,s)=>(d(),v("div",Me,[u.value||i.externalLoading?(d(),v("div",Te,[T(p(Le),{class:"size-6"}),b("div",null,k(p(Y)("loading_lyrics")),1)])):a.value.length?E.value?(d(),v("div",{key:2,ref_key:"syncedContainerRef",ref:w,class:"synced-container"},[T(de,{name:"intro-fade"},{default:B(()=>[q.value?(d(),v("div",Ae,[b("div",{class:"song-title",style:V({color:i.textColor})},k(e.mediaItem?.name),5),b("div",Pe,k(re.value),1),b("div",Be,k(p(Y)("lyrics_will_appear_soon")),1)])):D("",!0)]),_:1}),b("div",{ref_key:"syncedContentRef",ref:g,class:"synced-content",style:V({transform:`translateY(${I.value}px)`,transition:C.value?void 0:"none"})},[(d(!0),v(M,null,F(a.value,(r,l)=>(d(),v(M,{key:l},[b("div",{ref_for:!0,ref:c=>se(c,l),class:$(["lyrics-line",{active:n.value===l,"lyrics-line--hidden":n.value>=0?l<n.value-1||l>n.value+2:l>2}])},[r.words&&n.value===l?(d(!0),v(M,{key:0},F(r.words,(c,f)=>(d(),v("span",{key:f,class:$(["lyrics-word",{"lyrics-word--active":ne(c.time)}])},k(c.text),3))),128)):(d(),v(M,{key:1},[me(k(r.text),1)],64))],2),_.value===l?(d(),v("div",{key:0,class:$(["lyrics-line",{active:A.value,"lyrics-line--hidden":n.value>=0&&(l<n.value-2||l>n.value+1)}])},[(d(),v(M,null,F(P,c=>b("span",{key:c,class:$(["break-note",{"break-note--filled":c<=H.value,"break-note--filling":c===H.value+1}]),style:V(c===H.value+1?{backgroundImage:`linear-gradient(to right, ${i.textColor} ${Q.value}%, color-mix(in srgb, ${i.textColor} 35%, transparent) ${Q.value}%)`,backgroundClip:"text","-webkit-background-clip":"text","-webkit-text-fill-color":"transparent"}:void 0)},"♫",6)),64))],2)):D("",!0)],64))),128))],4)],512)):e.anticipation?D("",!0):(d(),j(p(Se),{key:3,ref_key:"scrollAreaRef",ref:h,class:"h-full w-full static-lyrics"},{default:B(()=>[b("div",Ee,[(d(!0),v(M,null,F(a.value,(r,l)=>(d(),v("div",{key:l,class:"lyrics-line active"},k(r.text),1))),128))])]),_:1},512)):(d(),v("div",Ce,k(p(Y)("no_lyrics_available")),1))]))}}),ze=ye(Ne,[["__scopeId","data-v-7b85e347"]]);function He(i,e,a){if(i===void 0||e===void 0||a!==void 0&&a!==ee.PLAYING)return i;const o=e*1e3,u=Date.now(),h=Math.max(0,u-o)/1e3;return i+h}function je(i){const e=y(0);let a=null;const o=()=>{const g=N.activePlayerQueue;g?.elapsed_time!=null&&g?.elapsed_time_last_updated!=null&&(e.value=He(g.elapsed_time,g.elapsed_time_last_updated,N.activePlayer?.playback_state)??0),a=requestAnimationFrame(o)},u=()=>{a||(a=requestAnimationFrame(o))},n=()=>{a&&(cancelAnimationFrame(a),a=null)};let h=!1;const w=()=>{document.visibilityState==="visible"&&h?u():n()};return document.addEventListener("visibilitychange",w),ve(()=>{const g=N.activePlayer?.playback_state===ee.PLAYING,L=N.activePlayerQueue,I=i?i.value:!0;h=g&&!!L?.active&&I,h&&document.visibilityState==="visible"?u():n()}),pe(()=>{n(),document.removeEventListener("visibilitychange",w)}),{elapsedTime:e,start:u,stop:n}}export{ze as L,Se as _,He as c,je as u};
