class GameOver extends HTMLElement { static get observedAttributes() { return ['visible']; } constructor() { super(); this.attachShadow({ mode: 'open' }); this.visible = 'false'; } connectedCallback() { this.render(); } attributeChangedCallback(name, oldValue, newValue) { if (name === 'visible') { this.visible = newValue; this.render(); } } render() { this.shadowRoot.innerHTML = `

GAME OVER

`; if (this.visible === 'true') { const button = this.shadowRoot.querySelector('.restart-btn'); button.addEventListener('click', () => { this.dispatchEvent(new CustomEvent('restart-game')); }); feather.replace(); } } } customElements.define('custom-game-over', GameOver);