(() => {
'use strict';
const $ = id => document.getElementById(id);
const state = {slides:[],index:0,active:true,hover:false,focus:false,paused:false,article:null,original:false};
// Animate the transform on the compositor instead of stepping a wide bar
// from a JavaScript timer. Its timeline is also the carousel's single clock.
const progress = $('progress').animate([{transform:'scaleX(0)'},{transform:'scaleX(1)'}],{duration:8000,easing:'linear',fill:'both'});
progress.pause();
function syncPlayback(){
const running=state.active&&!document.hidden&&!state.hover&&!state.focus&&!state.paused&&!state.article&&state.slides.length>1;
if(running)progress.play();else progress.pause();
}
progress.onfinish=()=>select(state.index+1);
const emit = (type,id) => window.chrome?.webview?.postMessage({type,id});
function renderSlide(notify=false) {
const slide=state.slides[state.index]; if(!slide)return;
if(slide.image)$('cover').src=slide.image;else $('cover').removeAttribute('src'); $('slide-title').textContent=slide.title; $('slide-teaser').textContent=slide.teaser; $('slide-date').textContent=slide.date;
$('slide-translation').textContent=slide.previewTranslated?'中文 · 自动翻译':slide.translationStatus||'正在自动翻译…';
$('counter').textContent=`${String(state.index+1).padStart(2,'0')} / ${String(state.slides.length).padStart(2,'0')}`;
$('dots').replaceChildren(...state.slides.map((s,i)=>{const b=document.createElement('button');b.setAttribute('aria-label',`第 ${i+1} 条:${s.title}`);b.setAttribute('aria-current',String(i===state.index));b.onclick=()=>select(i);return b;}));
$('previous').disabled=$('next').disabled=state.slides.length<2;
if(notify)emit('select',slide.id);
}
function select(index){if(!state.slides.length)return;state.index=(index+state.slides.length)%state.slides.length;progress.currentTime=0;renderSlide(true);syncPlayback();}
function renderArticle(){
const a=state.article;if(!a)return;
if(a.image)$('article-cover').src=a.image;else $('article-cover').removeAttribute('src');$('article-cover').alt=a.originalTitle;$('article-date').textContent=a.date;
$('article-title').textContent=state.original?a.originalTitle:a.title;
$('article-translation').textContent=state.original?'英文原文':a.bodyTranslated?'中文 · 自动翻译':a.translationStatus?.includes('暂不可用')?a.translationStatus:'正在自动翻译全文…';
$('language').textContent=state.original?'显示中文':'显示原文';
const body=state.original?a.originalBody:a.body;
$('article-body').replaceChildren(...body.split(/\n+/).filter(p=>p.trim()).map(text=>{const p=document.createElement('p');p.textContent=text;return p;}));
}
$('previous').onclick=()=>select(state.index-1);$('next').onclick=()=>select(state.index+1);
$('open-article').onclick=$('read-more').onclick=()=>emit('open',state.slides[state.index]?.id);
$('pause').onclick=()=>{state.paused=!state.paused;$('pause').textContent=state.paused?'▶':'Ⅱ';$('pause').setAttribute('aria-label',state.paused?'继续自动轮播':'暂停自动轮播');syncPlayback();};
$('carousel').onpointerenter=()=>{state.hover=true;syncPlayback();};$('carousel').onpointerleave=()=>{state.hover=false;syncPlayback();};
$('carousel').onfocusin=()=>{state.focus=true;syncPlayback();};$('carousel').onfocusout=e=>{state.focus=$('carousel').contains(e.relatedTarget);syncPlayback();};
document.addEventListener('visibilitychange',syncPlayback);
$('carousel').onkeydown=e=>{if(e.key==='ArrowLeft'){e.preventDefault();select(state.index-1);}if(e.key==='ArrowRight'){e.preventDefault();select(state.index+1);}};
$('language').onclick=()=>{state.original=!state.original;renderArticle();};$('official').onclick=()=>emit('official',state.article?.id);
window.galnet={
setSlides(slides){const id=state.slides[state.index]?.id;state.slides=slides;const index=slides.findIndex(a=>a.id===id);state.index=index<0?0:index;if(index<0)progress.currentTime=0;renderSlide();syncPlayback();},
setArticle(article){const changed=state.article?.id!==article.id;state.article=article;if(changed)state.original=false;document.body.className='reader-mode';$('reader').hidden=false;renderArticle();syncPlayback();},
setActive(active){state.active=active;syncPlayback();},
inspect(){return {index:state.index,count:state.slides.length,paused:state.paused,article:state.article?.id,progress:Number(progress.currentTime??0),active:state.active};}
};
emit('ready');
})();
(() => {
'use strict';
const $ = id => document.getElementById(id);
const state = {slides:[],index:0,active:true,hover:false,focus:false,paused:false,article:null,original:false};
// Animate the transform on the compositor instead of stepping a wide bar
// from a JavaScript timer. Its timeline is also the carousel's single clock.
const progress = $('progress').animate([{transform:'scaleX(0)'},{transform:'scaleX(1)'}],{duration:8000,easing:'linear',fill:'both'});
progress.pause();
function syncPlayback(){
const running=state.active&&!document.hidden&&!state.hover&&!state.focus&&!state.paused&&!state.article&&state.slides.length>1;
if(running)progress.play();else progress.pause();
}
progress.onfinish=()=>select(state.index+1);
const emit = (type,id) => window.chrome?.webview?.postMessage({type,id});
function renderSlide(notify=false) {
const slide=state.slides[state.index]; if(!slide)return;
if(slide.image)$('cover').src=slide.image;else $('cover').removeAttribute('src'); $('slide-title').textContent=slide.title; $('slide-teaser').textContent=slide.teaser; $('slide-date').textContent=slide.date;
$('slide-translation').textContent=slide.previewTranslated?'中文 · 自动翻译':slide.translationStatus||'正在自动翻译…';
$('counter').textContent=`${String(state.index+1).padStart(2,'0')} / ${String(state.slides.length).padStart(2,'0')}`;
$('dots').replaceChildren(...state.slides.map((s,i)=>{const b=document.createElement('button');b.setAttribute('aria-label',`第 ${i+1} 条:${s.title}`);b.setAttribute('aria-current',String(i===state.index));b.onclick=()=>select(i);return b;}));
$('previous').disabled=$('next').disabled=state.slides.length<2;
if(notify)emit('select',slide.id);
}
function select(index){if(!state.slides.length)return;state.index=(index+state.slides.length)%state.slides.length;progress.currentTime=0;renderSlide(true);syncPlayback();}
function renderArticle(){
const a=state.article;if(!a)return;
if(a.image)$('article-cover').src=a.image;else $('article-cover').removeAttribute('src');$('article-cover').alt=a.originalTitle;$('article-date').textContent=a.date;
$('article-title').textContent=state.original?a.originalTitle:a.title;
$('article-translation').textContent=state.original?'英文原文':a.bodyTranslated?'中文 · 自动翻译':a.translationStatus?.includes('暂不可用')?a.translationStatus:'正在自动翻译全文…';
$('language').textContent=state.original?'显示中文':'显示原文';
const body=state.original?a.originalBody:a.body;
$('article-body').replaceChildren(...body.split(/\n+/).filter(p=>p.trim()).map(text=>{const p=document.createElement('p');p.textContent=text;return p;}));
}
$('previous').onclick=()=>select(state.index-1);$('next').onclick=()=>select(state.index+1);
$('open-article').onclick=$('read-more').onclick=()=>emit('open',state.slides[state.index]?.id);
$('pause').onclick=()=>{state.paused=!state.paused;$('pause').textContent=state.paused?'▶':'Ⅱ';$('pause').setAttribute('aria-label',state.paused?'继续自动轮播':'暂停自动轮播');syncPlayback();};
$('carousel').onpointerenter=()=>{state.hover=true;syncPlayback();};$('carousel').onpointerleave=()=>{state.hover=false;syncPlayback();};
$('carousel').onfocusin=()=>{state.focus=true;syncPlayback();};$('carousel').onfocusout=e=>{state.focus=$('carousel').contains(e.relatedTarget);syncPlayback();};
document.addEventListener('visibilitychange',syncPlayback);
$('carousel').onkeydown=e=>{if(e.key==='ArrowLeft'){e.preventDefault();select(state.index-1);}if(e.key==='ArrowRight'){e.preventDefault();select(state.index+1);}};
$('language').onclick=()=>{state.original=!state.original;renderArticle();};$('official').onclick=()=>emit('official',state.article?.id);
window.galnet={
setSlides(slides){const id=state.slides[state.index]?.id;state.slides=slides;const index=slides.findIndex(a=>a.id===id);state.index=index<0?0:index;if(index<0)progress.currentTime=0;renderSlide();syncPlayback();},
setArticle(article){const changed=state.article?.id!==article.id;state.article=article;if(changed)state.original=false;document.body.className='reader-mode';$('reader').hidden=false;renderArticle();syncPlayback();},
setActive(active){state.active=active;syncPlayback();},
inspect(){return {index:state.index,count:state.slides.length,paused:state.paused,article:state.article?.id,progress:Number(progress.currentTime??0),active:state.active};}
};
emit('ready');
})();