// quiet-bar.mjs — the slide window's control bar, out of sight while // presenting (templates/present.html styles it by [data-quiet] on the // surface; without scripts the attribute is never set and the bar stays). // A pointer moving, or focus entering the bar, shows it. It goes after two // seconds of stillness while the pointer is off it and focus is outside, // and when the talk moves (the slide, the step or the blackout the window // draws). Focus inside the bar holds it, whatever the talk does. // static/present.js carries a small copy: a classic script cannot import. export function quietBar (root, wait = 2000) { let timer const focused = () => root.querySelector('[slides-bar]:focus-within') const hide = () => { clearTimeout(timer); root.setAttribute('data-quiet', '') } const rest = () => { clearTimeout(timer) timer = setTimeout(() => { if (!focused() && !root.querySelector('[slides-bar]:hover')) hide() }, wait) } const show = () => { root.removeAttribute('data-quiet'); rest() } hide() root.addEventListener('pointermove', show) root.addEventListener('pointerleave', () => { if (!root.hasAttribute('data-quiet')) rest() }) root.addEventListener('focusin', e => { if (e.target.closest('[slides-bar]')) show() }) root.addEventListener('focusout', e => { if (e.target.closest('[slides-bar]')) show() }) const seen = ['data-slide', 'data-step', 'data-blackout'] new MutationObserver(records => { if (!focused() && records.some(r => r.target.getAttribute(r.attributeName) !== r.oldValue)) hide() }).observe(root, { attributes: true, attributeFilter: seen, attributeOldValue: true }) }