(() => { const stage = document.querySelector('deck-stage'); if (!stage || !('BroadcastChannel' in window)) return; const channel = new BroadcastChannel('omniagent-deck-sync'); let applyingRemote = false; const publish = (index) => { if (!applyingRemote) channel.postMessage({ type: 'slide', index }); }; stage.addEventListener('slidechange', (event) => { publish(event.detail && typeof event.detail.index === 'number' ? event.detail.index : stage.index || 0); }); channel.onmessage = (event) => { const data = event.data || {}; if (data.type === 'hello') { publish(stage.index || 0); return; } if (data.type !== 'goto' || typeof data.index !== 'number') return; if (typeof stage.goTo !== 'function') return; applyingRemote = true; stage.goTo(data.index); applyingRemote = false; }; })();