• Stars
    star
    1,137
  • Rank 40,971 (Top 0.9 %)
  • Language
    HTML
  • License
    BSD 3-Clause "New...
  • Created over 5 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Web Components Polyfills

Web Components Polyfills

Test Status

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.

If you use Custom Elements, Shadow DOM, or the <template> element, either 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:

npm install --save @webcomponents/webcomponentsjs

Load the polyfills loader before any of your application code:

<html>
  <head>
    <!-- If your application is compiled to ES5, then load this script first. -->
    <script src="./node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>

    <!-- Add support for Web Components to older browsers. -->
    <script src="./node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>

    <!-- Load your application code anytime after loader.js -->
  </head>
  <body>
    <!-- Your custom elements will work in older browsers like IE11. -->
    <my-custom-element></my-custom-element>
  </body>
</html>

For more ways to load the Web Components polyfills, see the webcomponentsjs 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.

  • 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.

Registering styles

  • To use a style in the main document that sets or consumes a CSS Custom Property, register it with addCustomStyle.

  • To use a style in a Custom Element, pass the element's template to prepareTemplate before first cloning it. (Note that LitElement and the Polymer Library perform this registration step automatically.)

Packages

This repo is a monorepo. Each package lives under packages/<package>.

Published on npm webcomponentsjs

Documentation | Changelog | Issues

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.


Published on npm custom-elements

Documentation | Changelog | Issues

Polyfill for Custom Elements (MDN, Spec)


Published on npm template

Documentation | Changelog | Issues

Polyfill for Template Element (MDN, Spec)


Published on npm shadydom

Documentation | Changelog | Issues

Polyfill for Shadow DOM (MDN, Spec)


Published on npm shadycss

Documentation | Changelog | Issues

Polyfill for Scoped CSS (Spec)


Published on npm html-imports

Documentation | Changelog | Issues

Polyfill for HTML Imports (Spec)

Note that HTML Imports are deprecated in favor of JavaScript 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:

More Repositories

1

webcomponentsjs

A suite of polyfills supporting the HTML Web Components specs
HTML
3,874
star
2

custom-elements-everywhere

Custom Element + Framework Interoperability Tests.
JavaScript
1,169
star
3

gold-standard

1,029
star
4

webcomponents.github.io

WebComponents.org is where community-members document Web Components best practices
JavaScript
734
star
5

custom-elements

A polyfill for HTML Custom Elements v1
HTML
455
star
6

polymer-boilerplate

Fork this repo if you want to start your own Web Component using Polymer
HTML
369
star
7

webcomponents.org

Home of the web components community
TypeScript
366
star
8

custom-elements-manifest

A file format for describing custom elements
TypeScript
365
star
9

react-integration

Converts web components into React components so that you can use them as first class citizens in your React components.
JavaScript
306
star
10

element-boilerplate

Fork this repo if you want to start your own Web Component using VanillaJS
HTML
271
star
11

shadycss

HTML
197
star
12

shadydom

ShadowDOM v1 shim
HTML
162
star
13

hello-world-element

Web Component example using VanillaJS
HTML
151
star
14

chrome-webcomponents-extension

Google Chrome extension to identify all Custom Elements used on a site
JavaScript
81
star
15

html-imports

HTML Imports polyfill
HTML
73
star
16

angular-interop

A demo of interoperability between Polymer and AngularJS
TypeScript
72
star
17

template

Minimal polyfill for <template>
HTML
69
star
18

hello-world-polymer

Web Component example using Polymer
HTML
58
star
19

xtag-boilerplate

Fork this repo if you want to start your own Web Component using X-Tag
HTML
52
star
20

sass-interop

A demo of interoperability between Sass and Polymer
CSS
46
star
21

slush-element

Slush generator to create Custom Elements using Polymer, X-Tag or VanillaJS
JavaScript
41
star
22

webcomponents-icons

Collection of high resolution Web Components icons for presentations, blog posts or whatever
CSS
40
star
23

template-shadowroot

TypeScript
38
star
24

community

A space for the webcomponents community
JavaScript
26
star
25

hello-world-xtag

Web Component example using X-Tag
HTML
24
star
26

webcomponents-platform

Very minimal platform related polyfills
JavaScript
23
star
27

less-interop

A demo of interoperability between Less and Polymer
CSS
20
star
28

webcomponents-lite

Web Components Polyfills minus Shadow DOM
JavaScript
16
star
29

wc-catalog

11
star
30

custom-elements-manifest-tools

Tools for working with custom elements manifests
TypeScript
7
star
31

apply-shim

Shim for CSS @apply mixins
JavaScript
5
star
32

.allstar

1
star