1.0.0 • Published 5 years ago

custom-elements-module v1.0.0

Weekly downloads
6
License
CC0-1.0, BSD-3-Cl...
Repository
github
Last release
5 years ago

custom-elements-module

NPM Version Build Status Support Chat

custom-elements-module is a polyfill for HTML Custom Elements recompiled from @webcomponents/custom-elements.

This recompiled version is functionally identical, except that it does not assume browser globals and it provides control over which window object is polyfilled, allowing usage in and out of browser environments.

<script src="https://unpkg.com/custom-elements-module"></script>
<script>
polyfillCustomElements(window)

customElements.define(
  'x-h',
  class CustomH extends HTMLElement {
    constructor () {
      super()

      this.attachShadow({ mode: 'open' }).appendChild(
        document.createElement('slot')
      )
    }
  }
)
</script>
import polyfillCustomElements from 'custom-elements-module'
import jsdom from 'jsdom'

const { window } = new jsdom.JSDOM(`<x-h>Custom H</x-h>`, {
  beforeParse (window) {
    polyfillCustomElements(window)
  }
})

const { customElements, document, HTMLElement } = window

customElements.define(
  'x-h',
  class CustomH extends HTMLElement {
    constructor () {
      super()

      this.attachShadow({ mode: 'open' }).appendChild(
        document.createElement('slot')
      )
    }
  }
)

There are no other differences between this polyfill and @webcomponents/custom-elements. Although, due to gzipping representation, this version ends up being 357 bytes smaller.