mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-14 08:15:02 -05:00
3 lines
7.4 KiB
JavaScript
3 lines
7.4 KiB
JavaScript
import{_ as v,o as n,c as o,F as y,f as k,q as C,a as c,D as I,t as a,E as b,I as T,e as w,U as S,r as p,d as x,g as P,k as f}from"./index.js";import{C as M}from"./CoverArtwork.js";import{M as E}from"./ModalDialogQueueItem.js";import"./spotify-web-api.js";const L={name:"LyricsPane",data(){return this.lastIndex=-1,this.scrollingTimer=null,this.lastItemId=-1,{autoScrolling:!0}},computed:{is_playing(){return this.player.state==="play"},verse_index(){if(this.lyrics.length&&this.lyrics[0].time){const s=this.player.item_progress_ms/1e3,e=this.lyrics,g=this.player.item_id!==this.lastItemId,_=this.lastIndex>=0&&this.lastIndex<e.length&&e[this.lastIndex].time>s;if((g||_)&&this.reset_scrolling(),this.lastIndex<e.length-1&&e[this.lastIndex+1].time>s||this.lastIndex===e.length-1)return this.lastIndex;if(this.lastIndex<e.length-2&&e[this.lastIndex+2].time>s)return this.lastIndex+1;let r=0,t=e.length-1,i;for(;r<=t;){i=r+t>>1;const h=e[i],l=e[i+1];if(h.time<=s&&((l==null?void 0:l.time)>s||!l))return i;h.time<s?r=i+1:t=i-1}return-1}else return this.reset_scrolling(),-1},lyrics(){const s=this.$store.getters.lyrics,e=[];if(s){const g=/(\[(\d+):(\d+)(?:\.\d+)?\] ?)?(.*)/;s.split(`
|
|
`).forEach((_,r)=>{const t=g.exec(_);if(t&&t[4]){const i={text:t[4],time:t[2]*60+t[3]*1};e.push(i)}}),e.forEach((_,r,t)=>{const h=(r<t.length-1?t[r+1].time-_.time:3)/_.text.length;let l=0;_.words=_.text.match(/\S+\s*/g).map(m=>{const u=m.length*h;return l+=u,{duration:u,delay:l,text:m}})})}return e},player(){return this.$store.state.player}},watch:{verse_index(){this.autoScrolling&&this.scroll_to_verse(),this.lastIndex=this.verse_index}},methods:{reset_scrolling(){this.player.item_id!=this.lastItemId&&this.$refs.lyrics&&this.$refs.lyrics.scrollTo(0,0),this.lastItemId=this.player.item_id,this.lastIndex=-1},start_scrolling(s){(s.screenX||s.screenX!=0||s.screenY||s.screenY!=0)&&(this.autoScrolling=!1,this.scrollingTimer&&clearTimeout(this.scrollingTimer),this.scrollingTimer=setTimeout(this.autoScrolling=!0,2e3))},scroll_to_verse(){const s=this.$refs.lyrics;if(this.verse_index===-1){s.scrollTo(0,0);return}const e=s.children[this.verse_index];s.scrollBy({top:e.offsetTop-(s.offsetHeight>>1)+(e.offsetHeight>>1)-s.scrollTop,left:0,behavior:"smooth"})}}},N=["textContent"],A={key:1};function B(s,e,g,_,r,t){return n(),o("div",{ref:"lyrics",class:"lyrics",onTouchstart:e[0]||(e[0]=i=>r.autoScrolling=!1),onTouchend:e[1]||(e[1]=i=>r.autoScrolling=!0),onScrollPassive:e[2]||(e[2]=(...i)=>t.start_scrolling&&t.start_scrolling(...i)),onWheelPassive:e[3]||(e[3]=(...i)=>t.start_scrolling&&t.start_scrolling(...i))},[(n(!0),o(y,null,k(t.lyrics,(i,h)=>(n(),o(y,{key:h},[h===t.verse_index?(n(),o("div",{key:0,class:C({"is-highlighted":t.is_playing})},[(n(!0),o(y,null,k(i.words,l=>(n(),o("span",{key:l,class:"has-text-weight-bold is-size-5"},[c("span",{style:I({"animation-duration":`${l.delay}s`}),textContent:a(l.text)},null,12,N)]))),128))],2)):(n(),o("div",A,a(i.text),1))],64))),128))],544)}const D=v(L,[["render",B],["__scopeId","data-v-d4edaddb"]]),d=1e3,V={name:"PageNowPlaying",components:{ControlSlider:b,CoverArtwork:M,LyricsPane:D,ModalDialogQueueItem:E},data(){return{cursor:T,INTERVAL:d,interval_id:0,is_dragged:!1,selected_item:{},show_details_modal:!1}},computed:{is_live(){return this.track.length_ms===0},lyrics_visible(){return this.$store.getters.lyrics_pane},player(){return this.$store.state.player},track(){return this.$store.getters.now_playing},track_progress:{get(){return Math.floor(this.player.item_progress_ms/d)},set(s){this.player.item_progress_ms=s*d}},track_progress_max(){return this.is_live?1:Math.floor(this.track.length_ms/d)},track_elapsed_time(){return this.$filters.durationInHours(this.track_progress*d)},track_total_time(){return this.is_live?this.$t("page.now-playing.live"):this.$filters.durationInHours(this.track.length_ms)},settings_option_show_composer_now_playing(){return this.$store.getters.settings_option_show_composer_now_playing},settings_option_show_composer_for_genre(){return this.$store.getters.settings_option_show_composer_for_genre},composer(){return this.settings_option_show_composer_now_playing&&(!this.settings_option_show_composer_for_genre||this.track.genre&&this.settings_option_show_composer_for_genre.toLowerCase().split(",").findIndex(s=>this.track.genre.toLowerCase().indexOf(s.trim())>=0)>=0)?this.track.composer:null},settings_option_show_filepath_now_playing(){return this.$store.getters.settings_option_show_filepath_now_playing},filepath(){return this.settings_option_show_filepath_now_playing?this.track.path:null}},watch:{player(){this.interval_id>0&&(window.clearTimeout(this.interval_id),this.interval_id=0),this.player.state==="play"&&(this.interval_id=window.setInterval(this.tick,d))}},created(){w.player_status().then(({data:s})=>{this.$store.commit(S,s),this.player.state==="play"&&(this.interval_id=window.setInterval(this.tick,d))})},unmounted(){this.interval_id>0&&(window.clearTimeout(this.interval_id),this.interval_id=0)},methods:{tick(){this.is_dragged||(this.track_progress+=1)},start_dragging(){this.is_dragged=!0},end_dragging(){this.is_dragged=!1},seek(){this.is_live||w.player_seek_to_pos(this.track_progress*d)},open_dialog(s){this.selected_item=s,this.show_details_modal=!0}}},H={class:"hero is-full-height"},U={key:0,class:"hero-body is-flex is-align-items-center"},q={class:"container has-text-centered",style:{"max-width":"500px"}},z={class:"is-flex is-justify-content-space-between"},Y=["textContent"],F=["textContent"],R=["textContent"],X=["textContent"],j=["textContent"],O=["textContent"],Q=["textContent"],W={key:1,class:"hero-body is-flex is-align-items-center"},G={class:"container has-text-centered"},J=["textContent"],K=["textContent"];function Z(s,e,g,_,r,t){const i=p("cover-artwork"),h=p("lyrics-pane"),l=p("control-slider"),m=p("modal-dialog-queue-item");return n(),o("div",H,[t.track.id>0?(n(),o("div",U,[c("div",q,[x(i,{artwork_url:t.track.artwork_url,artist:t.track.artist,album:t.track.album,class:C(["is-clickable fd-has-shadow fd-cover-big-image",{"is-masked":t.lyrics_visible}]),onClick:e[0]||(e[0]=u=>t.open_dialog(t.track))},null,8,["artwork_url","artist","album","class"]),t.lyrics_visible?(n(),P(h,{key:0})):f("",!0),x(l,{value:t.track_progress,"onUpdate:value":e[1]||(e[1]=u=>t.track_progress=u),class:"mt-5",disabled:t.is_live,max:t.track_progress_max,cursor:r.cursor,onChange:t.seek,onMousedown:t.start_dragging,onMouseup:t.end_dragging},null,8,["value","disabled","max","cursor","onChange","onMousedown","onMouseup"]),c("div",z,[c("p",{class:"subtitle is-7",textContent:a(t.track_elapsed_time)},null,8,Y),c("p",{class:"subtitle is-7",textContent:a(t.track_total_time)},null,8,F)]),c("p",{class:"title is-5",textContent:a(t.track.title)},null,8,R),c("p",{class:"title is-6",textContent:a(t.track.artist)},null,8,X),t.composer?(n(),o("p",{key:1,class:"subtitle is-6 has-text-grey has-text-weight-bold",textContent:a(t.composer)},null,8,j)):f("",!0),t.track.album?(n(),o("p",{key:2,class:"subtitle is-6",textContent:a(t.track.album)},null,8,O)):f("",!0),t.filepath?(n(),o("p",{key:3,class:"subtitle is-6 has-text-grey",textContent:a(t.filepath)},null,8,Q)):f("",!0)])])):(n(),o("div",W,[c("div",G,[c("p",{class:"title is-5",textContent:a(s.$t("page.now-playing.title"))},null,8,J),c("p",{class:"subtitle",textContent:a(s.$t("page.now-playing.info"))},null,8,K)])])),x(m,{show:r.show_details_modal,item:r.selected_item,onClose:e[2]||(e[2]=u=>r.show_details_modal=!1)},null,8,["show","item"])])}const it=v(V,[["render",Z]]);export{it as default};
|