// The settings panel: analysis params, pre-roll and the auto-advance mode. import {$, remember} from './util.js'; // The three analysis controls, read straight from the DOM. Deliberately no // hardcoded fallbacks: the inputs are seeded from /api/config at startup, so // web.py's MARGIN_DB / MIN_GAP_SECONDS / MIN_DURATION_SECONDS stay the single // source of truth. An empty input sends an empty param, which _qs_float() // falls back to the server default for. export const analysisParams = () => ({ margin: $('margin-input').value, minGap: $('min-gap-input').value, minDur: $('min-duration-input').value, }); // Same values as one string; a highlights panel built with other values is // stale and gets recomputed on the next expand export const hlParams = () => Object.values(analysisParams()).join('|'); export const getPreroll = () => { const v = parseFloat($('preroll-input').value); return isNaN(v) || v < 0 ? 0 : v; }; export const advanceMode = () => document.querySelector('input[name="clip-adv"]:checked')?.value || 'off'; // Does a server-side cached analysis match the current control values? // Auto-loading on a mismatch would silently recompute every file. export function cachedParamsMatch(ca) { const p = analysisParams(); return ca != null && Number(ca.margin) === parseFloat(p.margin) && Number(ca.min_gap) === parseFloat(p.minGap) && Number(ca.min_duration) === parseFloat(p.minDur); } // Seed the analysis params from /api/config, and restore the per-browser // conveniences. Margin/gap/min-duration are not remembered client-side: a // stale browser value would quietly disagree with the server's defaults. export function initSettings(cfg) { if (cfg.margin != null) $('margin-input').value = cfg.margin; if (cfg.min_gap != null) $('min-gap-input').value = cfg.min_gap; if (cfg.min_duration != null) $('min-duration-input').value = cfg.min_duration; const pre = remember.get('preroll'); if (pre != null) $('preroll-input').value = pre; $('preroll-input').addEventListener('change', e => remember.set('preroll', e.target.value)); const adv = remember.get('advance'); const radio = adv && document.querySelector(`input[name="clip-adv"][value="${adv}"]`); if (radio) radio.checked = true; document.querySelectorAll('input[name="clip-adv"]').forEach(r => r.addEventListener('change', () => remember.set('advance', r.value))); const panel = $('settings'); panel.open = remember.get('settingsOpen') === '1'; panel.addEventListener('toggle', () => remember.set('settingsOpen', panel.open ? '1' : '0')); }