// slide-window.mjs — the slide window (templates/present.html, GET // /p/{session}) of a session with a position, for whoever may drive it: // the projector, moving at once. // // The server draws the slide, and with scripts off the bar's forms post // and redirect. This holds the talk (talk-driver.mjs), takes the same // keys as the presenter window, and swaps the slide in one task from // memory: a step in place, the slide whole, never a blank stage. When // the network is gone and this window is not the one pressing, it holds // still and says it is waiting. Every word comes from the page // (data-text-* on the surface). // // The follow link, the remote and sessions begun before positions keep // static/present.js. import { createDriver, bindForms } from './talk-driver.mjs' import { createKeys, takeEarlyKeys } from './presenter-keys.mjs' import { quietBar } from './quiet-bar.mjs' import { install, reveal, fill, talkPlace, indexOf, mountClips } from './talk-draw.mjs' import { mountSceneLayer, scenePositions, talkMove } from './scene-layer.mjs' export function mountSlideWindow (root) { const T = root.dataset const stage = root.querySelector('[slides-stage]') const note = root.querySelector('[slides-blackout]') const waiting = root.querySelector('[slides-waiting]') const region = root.querySelector('[slides-announce]') if (!stage) return quietBar(root) // The scenes on the slide run over it, from the talk (scene-layer.mjs). let held = null const scenes = mountSceneLayer({ root, deck: () => held }) // And its clips play over their posters (clip.mjs). mountClips({ root: stage }) // counterText is the counter's own words: the line after the label // only a screen reader hears. function counterText (text) { const counter = root.querySelector('[slides-counter]') if (!counter) return const last = counter.lastChild if (last && last.nodeType === Node.TEXT_NODE) last.textContent = ' ' + text else counter.append(' ' + text) } // The empty talk (every slide parked or gone): the empty state the // server rendered for it, hidden until now, and no slide left up. const empty = root.querySelector('[slides-empty]') const controls = root.querySelector('[slides-bar]') function drawEmpty (to, store) { root.setAttribute('data-empty', '') stage.replaceChildren() stage.hidden = true if (controls) controls.hidden = true if (empty) empty.hidden = false counterText('') if (region && empty && region.textContent !== empty.innerText) region.textContent = empty.innerText root.setAttribute('data-slide', '') root.setAttribute('data-step', '0') root.setAttribute('data-mode', to.mode) root.setAttribute('data-blackout', to.black ? 'true' : 'false') root.setAttribute('data-deck-seq', String(store.deckSeq)) if (note) note.hidden = !to.black scenes.show('', []) } function draw (to, from, { fresh, store }) { const s = to.slide ? store.slide(to.slide) : null if (!s) { if (!to.slide) drawEmpty(to, store) return } const wasEmpty = root.hasAttribute('data-empty') if (wasEmpty) { root.removeAttribute('data-empty') stage.hidden = false if (controls) controls.hidden = false if (empty) empty.hidden = true } const view = store.view const same = !wasEmpty && !fresh && from && from.slide === to.slide if (!same) { install(stage, s.html, to.step) const said = fill(T.textAnnounce, { n: s.number, total: store.slides.length, title: s.title }) root.setAttribute('data-announce', said) if (region && region.textContent !== said) region.textContent = said } else if (from.step !== to.step) { reveal(stage, to.step) } held = store scenes.show(to.slide, scenePositions(stage), { jump: !talkMove(store, from, to) }) const place = talkPlace(view, to.mode, indexOf(view, to.slide)) counterText(fill(T.textProgress, place)) const bar = root.querySelector('[slides-progress]') if (bar) { bar.setAttribute('value', String(place.n)) bar.setAttribute('max', String(place.total)) } root.setAttribute('data-slide', String(s.number)) root.setAttribute('data-step', String(to.step)) root.setAttribute('data-mode', to.mode) root.setAttribute('data-blackout', to.black ? 'true' : 'false') root.setAttribute('data-deck-seq', String(store.deckSeq)) if (note) note.hidden = !to.black const u = new URL(location.href) if (u.searchParams.has('slide') || u.searchParams.has('step')) { u.searchParams.delete('slide') u.searchParams.delete('step') history.replaceState(history.state, '', u.href) } } const driver = createDriver({ root, talkHref: T.talk, streamHref: T.stream, action: T.command, token: root.getAttribute('data-remote-token') || '', draw, onLoad: (store, at) => { held = store; scenes.show(at.slide, scenePositions(stage), { jump: true }) }, onProgress: p => root.setAttribute('data-loaded', p.finished && !p.failed ? 'all' : String(p.done)), onStatus: s => { if (!waiting) return waiting.textContent = T.textWaiting waiting.hidden = s !== 'offline' } }) bindForms(root, T.command, driver) const onKey = createKeys({ act (a) { if (a.move) driver.move(a.move) else if (a.jump) driver.jump(a.jump) else if (a.timer) driver.timerReset() else if (a.open && T.presenter) window.open(T.presenter, 'slides-presenter') else if (a.escape) { if (document.fullscreenElement) document.exitFullscreen() const f = document.activeElement if (f && f !== document.body && f.blur) f.blur() } } }) document.addEventListener('keydown', onKey) // And the keys pressed before this script was here (static/presskeys.js). takeEarlyKeys(onKey) // A swipe on a touch screen is a press too. let startX = null root.addEventListener('touchstart', e => { startX = e.changedTouches[0].clientX }, { passive: true }) root.addEventListener('touchend', e => { if (startX === null) return const dx = e.changedTouches[0].clientX - startX startX = null if (Math.abs(dx) >= 60) driver.move({ op: dx < 0 ? 'next' : 'back' }) }, { passive: true }) }