JSPM

@w0s/shadow-append-css

1.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q10006F
  • License MIT

Appending CSS into the shadow DOM

Package Exports

  • @w0s/shadow-append-css
  • @w0s/shadow-append-css/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@w0s/shadow-append-css) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Appending CSS into the shadow DOM

npm version Workflow status

Demo

Examples

<script type="importmap">
  {
    "imports": {
      "@w0s/shadow-append-css": "..."
    }
  }
</script>
<script type="module">
  import shadowAppendCss from '@w0s/shadow-append-css';

  class MyElement extends HTMLElement {
    constructor() {
      super();

      const shadow = this.attachShadow({ mode: 'open' });
      shadow.innerHTML = '<slot></slot>';

      const cssString = `
        :host {
          display: block flow;
          align-content: center;
          background: #f00;
          block-size: 10em;
          inline-size: 10em;
          text-align: center;
          color: #000;
        }
      `;

      shadowAppendCss(shadow, cssString);
    }
  }

  customElements.define('my-element', MyElement);
</script>

<my-element>
  <p>text</p>
</my-element>