<my-ce></my-ce>

<script>
  class MyCe extends HTMLElement {
    constructor() {
      super()
      const shadow = this.attachShadow({ mode: 'open' })
      shadow.innerHTML = '<button>Click me</button>'

      shadow.querySelector('button').addEventListener('click', () => {
        this.dispatchEvent(new CustomEvent('my-event', { detail: 'Hello, World!' }))
      })
    }
  }
  customElements.define('my-ce', MyCe)
</script>

Done 🎉

Now your element can emit any custom event you imagine.