class UiDialog extends HTMLElement { connectedCallback() { this.attachShadow({ mode: 'open' }); this.shadowRoot.innerHTML = `

${this.getAttribute('title') || ''}

`; const dialog = this.shadowRoot.querySelector('dialog'); this.shadowRoot.querySelector('.close-btn').addEventListener('click', () => this.close()); dialog.addEventListener('click', e => { if (e.target === dialog) this.close(); }); document.addEventListener('keydown', e => { if (e.key === 'Escape') this.close(); }); if (window.lucide) lucide.createIcons({ root: this.shadowRoot }); } open() { this.shadowRoot?.querySelector('dialog')?.showModal(); } close() { this.shadowRoot?.querySelector('dialog')?.close(); this.dispatchEvent(new CustomEvent('ui:close', { bubbles: true, composed: true })); } } customElements.define('ui-dialog', UiDialog);