skatejs / cloudydom

ShadowDOM v1 shim
12 stars 2 forks source link

cloudydom

cloudydom is a shim for ShadowDOM. It is a fork of webcomponents/shadydom, with some bug fixes not present in that project.

Install

Yarn:

yarn add cloudydom

Why fork

shadydom is maintained by the Polymer team. They've done fantastic work creating a workable polyfill. However some problems have persisted:

cloudydom seeks only to address these community issues. Our plan is to:

Usage

Usage of the shim is transparent when attachShadow is unavailable. Elements are patched as needed to report ShadowDOM correct DOM information. Only DOM tree accessors and mutation api is maintained. Some DOM api (for example MutationObservers) is not shimmed.

To force cloudydom to be used even when native ShadowDOM is available, set the ShadyDOM = {force: true} in a script prior to loading the polyfill.

Example

<div id="host"></div>
<script>
  host.attachShadow({mode: 'open'});
  host.shadowRoot.appendChild(document.createElement('a'));
</script>

Building and Testing

For building and testing, first run

npm install
bower install

To build, make sure gulp is installed and gulp.

To test, run npm test

Limitations

cloudydom distribution is asynchronous for performance reasons. This means that the composed DOM will be available 1 microtask after the DOM mutation occurs. For testing, ShadyDOM.flush may be called to force synchronous composition.

ShadowDOM compatible styling is not provided with the ShadyDOM shim. To shim ShadowDOM styling, use the shadycss shim.