GithubHelp home page GithubHelp logo

developers81828182 / polyfills Goto Github PK

View Code? Open in Web Editor NEW

This project forked from webcomponents/polyfills

0.0 1.0 0.0 32.07 MB

Web Components Polyfills

License: BSD 3-Clause "New" or "Revised" License

JavaScript 29.23% TypeScript 8.39% CSS 0.21% HTML 62.18%

polyfills's Introduction

Web Components Polyfills

Test Status

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

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 Custom Elements (MDN, Spec)


Polyfill for Template Element (MDN, Spec)


Polyfill for Shadow DOM (MDN, Spec)


Polyfill for Scoped CSS (Spec)


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:

polyfills's People

Contributors

bicknellr avatar dfreedm avatar valdrinkoshi avatar timvdlippe avatar kevinpschaaf avatar justinfagnani avatar aomarks avatar notwaldorf avatar addyosmani avatar abdonrd avatar rictic avatar sorvell avatar fluorescenthallucinogen avatar garlicnation avatar nazar-pc avatar calebdwilliams avatar ebidel avatar web-padawan avatar tomalec avatar talee avatar nevir avatar eeid26 avatar gotcha avatar jmcgavin avatar ruphin avatar bbsteventill avatar treshugart avatar rslawik avatar manolakis avatar koenkivits avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.