WebComponents Polyfills
A suite of polyfills supporting the Web Components specs
README
Web Components Polyfills
Getting Started | Usage | Packages | Roadmap
The Web Components polyfills are a suite of JavaScript libraries that implement
Web Components APIs
for browsers that don't have built-in support.
directly or through a library like
LitElement, then you can use these
polyfills to make your app work in older browsers like IE11.
We're also working on polyfills for cutting edge new APIs for Web Components
that aren't built into all modern browsers yet, like Shadow Parts and Adopted
Stylesheets.
Getting Started
Install the webcomponentsjs package to get all of the Web Components
polyfills and a _loader_ that automatically downloads only the polyfills each
browser needs:
- ``` sh
- npm install --save @webcomponents/webcomponentsjs
- ```
Load the polyfills loader before any of your application code:
- ``` html
- <html>
- <head>
- <script src="./node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
- <script src="./node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
- </head>
- <body>
- <my-custom-element></my-custom-element>
- </body>
- </html>
- ```
For more ways to load the Web Components polyfills, see the
package.
Usage
The Web Components polyfills handle many usage patterns automatically, but
there are certain patterns that require direct interaction with the library:
Setting Custom Properties
- To set a CSS custom property value imperatively, pass the value to
[styleSubtree](https://github.com/webcomponents/polyfills/tree/master/packages/shadycss#imperative-values-for-custom-properties).
- To re-compute CSS custom properties after a DOM mutuation that affects the
matching condition of a CSS rule containing a custom property (e.g. changing
a class attribute), call [styleSubtree](https://github.com/webcomponents/polyfills/tree/master/packages/shadycss#imperative-values-for-custom-properties).
Registering styles
- To use a style in the main document that sets or consumes a CSS Custom
Property, register it with
[addCustomStyle](https://github.com/webcomponents/polyfills/tree/master/packages/shadycss#about-customstyleinterface).
- To use a style in a Custom Element, pass the element's template to
[prepareTemplate](https://github.com/webcomponents/polyfills/tree/master/packages/shadycss#usage)
before first cloning it. (Note that
LitElement and the [Polymer
Library](https://polymer-library.polymer-project.org) perform this
registration step automatically.)
Packages
Loader and pre-minimized bundles for the full suite of Web Components
polyfills.
Most users only need to install this package, but it is also possible to
separately install any of the individual polyfills listed below.
Polyfill for Scoped CSS (Spec)
Polyfill for HTML Imports (Spec)
Note that HTML Imports are
in favor of [JavaScript
modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules).
As of Chrome 81, HTML Imports are no longer natively supported by any browser.
The current version of the Web Components loader does not automatically
polyfill HTML Imports. Applications that still depend on HTML Imports are
recommended to install @webcomponents/html-imports and load it separately.
Roadmap
The following APIs are on the roadmap for 2020:
- CSS Shadow Parts
(MDN,