1.0.0 • Published 5 years ago
custom-elements-module v1.0.0
custom-elements-module
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.
1.0.0
5 years ago