custom-elements-module

1.0.0 • Public • Published

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.

Package Sidebar

Install

npm i custom-elements-module

Weekly Downloads

115

Version

1.0.0

License

CC0-1.0, BSD-3-Clause

Unpacked Size

353 kB

Total Files

10

Last publish

Collaborators

  • jonathantneal