class FloatingOverlay extends HTMLElement { connectedCallback() { this.attachShadow({ mode: 'open' }); this.shadowRoot.innerHTML = `
`; this.setupEventListeners(); this.updateButtonStates(); } setupEventListeners() { this.shadowRoot.getElementById('undo-btn').addEventListener('click', () => { this.dispatchEvent(new CustomEvent('undo')); }); this.shadowRoot.getElementById('redo-btn').addEventListener('click', () => { this.dispatchEvent(new CustomEvent('redo')); }); this.shadowRoot.getElementById('ai-btn').addEventListener('click', () => { this.dispatchEvent(new CustomEvent('generate')); }); this.shadowRoot.getElementById('run-btn').addEventListener('click', () => { this.dispatchEvent(new CustomEvent('run')); }); } updateButtonStates() { const canUndo = this.hasAttribute('can-undo'); const canRedo = this.hasAttribute('can-redo'); const isExecuting = this.hasAttribute('is-executing'); const undoBtn = this.shadowRoot.getElementById('undo-btn'); const redoBtn = this.shadowRoot.getElementById('redo-btn'); const runBtn = this.shadowRoot.getElementById('run-btn'); undoBtn.classList.toggle('disabled', !canUndo); redoBtn.classList.toggle('disabled', !canRedo); runBtn.classList.toggle('disabled', isExecuting); if (isExecuting) { runBtn.innerHTML = ''; } else { runBtn.innerHTML = ''; } } static get observedAttributes() { return ['can-undo', 'can-redo', 'is-executing']; } attributeChangedCallback(name, oldValue, newValue) { if (name === 'can-undo' || name === 'can-redo' || name === 'is-executing') { this.updateButtonStates(); } } } customElements.define('floating-overlay', FloatingOverlay);