class UploadButton extends HTMLElement { connectedCallback() { this.attachShadow({ mode: 'open' }); this.shadowRoot.innerHTML = ` `; const button = this.shadowRoot.querySelector('.upload-btn'); const fileInput = this.shadowRoot.querySelector('input[type="file"]'); button.addEventListener('click', () => fileInput.click()); fileInput.addEventListener('change', (e) => this.handleFileSelect(e)); } handleFileSelect(event) { const file = event.target.files[0]; if (file) { this.dispatchEvent(new CustomEvent('file-uploaded', { detail: { file }, bubbles: true, composed: true })); } } } customElements.define('upload-button', UploadButton);