import * as controller from './controller.js' import * as player from './player.js' import * as browser from './browser.js' import * as queue from './queue.js' export { player, browser, queue } export function State() { player.State() browser.State() queue.State() } export async function Init() { await controller.Init() await player.Init() await browser.Init() await queue.Init() hiss.view.panels = [ hiss.view.player, hiss.view.browser, hiss.view.queue ] hiss.view.modules = [ player, browser, queue ] hiss.view.index = 1 Display() } export function Display() { let module = hiss.view.modules[hiss.view.index] document.body.querySelector('section.open')?.classList.remove('open') Panel().root.classList.add('open') module.Open() } export function Next() { hiss.view.index = wrapValue(hiss.view.index - 1, 0, hiss.view.panels.length) Display() } export function Prev() { hiss.view.index = wrapValue(hiss.view.index + 1, 0, hiss.view.panels.length) Display() } export function wrapValue(value, min, max) { if(value < min) { value = max - 1 } else if(value >= max) { value = min } return value } export function populateTrackInfo(eTrack, ele) { let title = document.createElement('b') let artist = document.createElement('cite') title.innerText = eTrack.name artist.innerText = eTrack.artist ?? "Unknown Artist" ele.appendChild(title) ele.appendChild(artist) } export function FormatTime(iSeconds) { let minutes = Math.floor(iSeconds / 60).toString() let seconds = Math.floor(iSeconds % 60).toString() return minutes.padStart(2, '0') + ':' + seconds.padStart(2, '0') } export function ScrollInListTo(target) { let c = Array.from(target.parentNode.children) let i = c.indexOf(target) c[Math.max(i - 4, 0)].scrollIntoView() } export function PrevElement(element) { return element.previousElementSibling ?? element.parentNode.lastElementChild } export function NextElement(element) { return element.nextElementSibling ?? element.parentNode.firstElementChild } export function FocusPrev(element = Panel().focus) { let p = PrevElement(element) ScrollInListTo(p) Focus(p) } export function FocusNext(element = Panel().focus) { let n = NextElement(element) ScrollInListTo(n) Focus(n) } export function Panel() { return hiss.view.panels[hiss.view.index] } export function Focus(focus, context = Panel()) { context.focus?.classList.remove('focus') context.focus = focus focus.classList.add('focus') }