Detalhes do pacote

@floogulinc/construct-style-sheets-polyfill

floogulinc18MIT3.2.0

Constructible style sheets/adopted style sheets polyfill

CSS, CSS in JS, constructible style sheets, constructable style sheets

readme (leia-me)

Constructible style sheets polyfill

CI npm version codecov

This package is a polyfill for the constructible style sheets/adopted style sheets specification. The full specificaiton is enabled by default in Google Chrome as of version 73.

Currently Mozilla is considering implementation of the feature, marking it as "worth prototyping" while Apple has not publically signaled, they have been active in the standards discussions surrounding it.

Use case

The constructible style sheets proposal is intended to allow for the dynamic creation and sharing of style sheets, even across shadow boundaries. By adopting a style sheet into a shadow root, the same sheet can be applied to multiple nodes, including the document.

How it works

This polyfill will create a new style element for every DocumentOrShadowRoot into which the sheet is adopted. This is counter to the current proposal, but updates to the style sheet using the replace or replaceSync methods should update the relevant style elements with the updated content across all adopters.

No changes will occur in a browser that supports the feature by default.

Support

This polyfill supports all modern browsers and IE 11.

For browsers that do not support the web components specification (currently IE 11 and Edge) only the document-level style sheets adoption works.

IE 11

To make this polyfill work with IE 11 you need the following tools:

Installation

This package is available on npm under the name construct-style-sheet-polyfill and can be installed with npm, yarn, unpkg or however else you consume dependencies.

Example commands:

npm:

npm i construct-style-sheets-polyfill

yarn:

yarn add construct-style-sheets-polyfill

unpkg:

import 'https://unpkg.com/construct-style-sheets-polyfill';

Usage

const everythingTomato = new CSSStyleSheet();
everythingTomato
  .replace(
    `
* {
    color: tomato;
}
`,
  )
  .then(console.log); // will log the CSSStyleSheet object

document.adoptedStyleSheets = [everythingTomato];

class TestEl extends HTMLElement {
  constructor() {
    super();
    this.attachShadow({mode: 'open'});
    this.shadowRoot.adoptedStyleSheets = [everythingTomato];
  }

  connectedCallback() {
    this.shadowRoot.innerHTML = `<h1>This will be tomato colored, too</h1>`;
  }
}

customElements('test-el', TestEl);

const testEl = new TestEl();
document.body.appendChild(testEl);

The polyfill will append new style tags to the designated DocumentOrShadowRoot. Manually removing the style node will cause a re-insertion of the styles at the designated root. To remove a style sheet, you must remove the style element from the element.adoptedStyleSheets array. The behavior here is supposed to emulate a FrozenArray, so modifying the array in question will have no effect until the value is changed using a setter.

A note about versioning

This packages doesn't necessarily follow semantic versioning. As the spec is still under consideration and implementation by browser vendors, the features supported by this package will change (generally following Chrome's implementation).

changelog (log de mudanças)

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

3.0.6 (2022-01-30)

3.0.5 (2021-12-09)

3.0.4 (2021-10-13)

3.0.3 (2021-10-02)

3.0.2 (2021-10-01)

Bug Fixes

  • resolve issue with broken coverage & update dependencies (dde9152)
  • update Typescript code (d49fabb)

3.0.1 (2021-09-12)

Bug Fixes

  • resolve issue with broken coverage & update dependencies (dde9152)
  • update Typescript code (d49fabb)

3.0.0 (2021-08-12)

3.0.0-0 (2021-06-18)

⚠ BREAKING CHANGES

  • project re-write

  • Rewrite project to make it smaller, faster and more understandable (#72) (ad64cf5), closes #72

2.4.16 (2021-02-14)

Bug Fixes

  • add support for closed shadow roots (82ab33b)

2.4.15 (2021-02-14)

2.4.14 (2021-02-14)

Bug Fixes

  • apply styles to element created during document loading (#70) (35b0236), closes #67

2.4.13 (2021-02-14)

Bug Fixes

  • apply styles to element created during document loading (#70) (35b0236), closes #67

2.4.12 (2021-02-14)

Bug Fixes

  • apply styles to element created during document loading (#70) (35b0236), closes #67

2.4.11 (2021-02-13)

Bug Fixes

  • on adopt insert after last child (c7083ad)

2.4.10 (2021-02-13)

Bug Fixes

  • on adopt insert after last child (c7083ad)

2.4.9 (2021-02-07)

Bug Fixes

2.4.8 (2021-02-07)

Bug Fixes

2.4.7 (2021-02-07)

Bug Fixes

2.4.6 (2020-12-29)

Bug Fixes

2.4.5 (2020-12-29)

2.4.4 (2020-12-29)

Bug Fixes

  • ensure referential integrity, match chromes behavior (99bdde3)
  • loosen import regex, update import tests and invocation tests (c62fde6)

2.4.3 (2020-11-18)

Bug Fixes

  • abort mutation callback if document doesn't exist anymore (28b4223)

2.4.2 (2020-09-25)

Bug Fixes

  • move attachShadow override to Element per spec (1e11b32)

2.4.1 (2020-09-06)

Bug Fixes

  • remove console.log from dist (be23440)

2.4.0 (2020-08-19)

Features

Bug Fixes

2.3.5 (2020-02-06)

2.3.4 (2020-02-06)

2.3.3 (2020-02-06)

Bug Fixes

  • polyfill: Fix a race condition with adopting stylesheets in Firefox (15ce973)

2.3.2 (2019-11-20)

2.3.1 (2019-11-16)

Bug Fixes

  • use element itself instead of shadow root if ShadyCSS is used (e3fa425)

2.3.0 (2019-10-31)

Bug Fixes

  • add a couple of small fixes (4363c65)

Features

  • add typings and tests for them (b29f1a6)

2.2.11 (2019-10-19)

Bug Fixes

  • allow overriding the CSSStyleSheet prototype methods (b076dab)
  • move styles adopted before page is ready to body (78da6f7)
  • adopt: adoptStyleSheets will now allow both polyfill and script to be placed in head (58620e6)

2.2.10 (2019-09-13)

Bug Fixes

  • add some more fixes (3d0d28c)
  • add various fixes to make IE & ShadyCSS working (1a462f8)
  • drop support for ShadyCSS (209fe3b)
  • miscellaneous improvements (2895c86)
  • adopt: adoptStyleSheets will now allow both polyfill and script to be placed in head (58620e6)
  • IE11, docs: Added potential fix for #24 and #23 (0bf415e)
  • move styles adopted before page is ready to body (78da6f7)

2.2.9 (2019-09-13)

Bug Fixes

  • add some more fixes (3d0d28c)
  • add various fixes to make IE & ShadyCSS working (1a462f8)
  • drop support for ShadyCSS (209fe3b)
  • miscellaneous improvements (2895c86)
  • adopt: adoptStyleSheets will now allow both polyfill and script to be placed in head (58620e6)
  • IE11, docs: Added potential fix for #24 and #23 (0bf415e)
  • move styles adopted before page is ready to body (78da6f7)

2.2.8 (2019-09-13)

Bug Fixes

  • add some more fixes (3d0d28c)
  • add various fixes to make IE & ShadyCSS working (1a462f8)
  • drop support for ShadyCSS (209fe3b)
  • miscellaneous improvements (2895c86)
  • adopt: adoptStyleSheets will now allow both polyfill and script to be placed in head (58620e6)
  • IE11, docs: Added potential fix for #24 and #23 (0bf415e)
  • move styles adopted before page is ready to body (78da6f7)

2.2.7 (2019-09-06)

Bug Fixes

  • add some more fixes (3d0d28c)
  • add various fixes to make IE & ShadyCSS working (1a462f8)
  • drop support for ShadyCSS (209fe3b)
  • miscellaneous improvements (2895c86)

2.2.6 (2019-08-31)

Bug Fixes

2.2.5 (2019-08-29)

Bug Fixes

  • polyfill: Aligned adoptedStyleSheet set errors with Chrome and double check presence of ShadowRoot (c753d3b)

2.2.4 (2019-08-29)

2.2.3 (2019-08-29)

Bug Fixes

  • polyfill: Remove duplicate call to initPolyfill (bf17b94)

2.2.2 (2019-08-29)

Bug Fixes

  • polyfill: Polyfill can not be used in the HTML document's head (b55e632)
  • polyfill: The polyfill now behaves properly when loaded in the document's head (5b3115e)

2.2.1 (2019-08-29)

2.2.0 (2019-08-28)

Bug Fixes

  • add fixes for 2 issues (5546c8b)
  • fix mistakes & override the CSSStyleSheet prototype on each construction (688d963)
  • make error messages to be equal with Chrome's (22be5d5)
  • solve the methods application issue (2d9f601)

Features

  • allow remembering last applied action and resuming from it. (1a7b6d2)
  • improve error messages (70e095a)

2.1.0 (2019-08-18)

Bug Fixes

  • polyfill: Fix issue where removing style node does not reappend the sheet (a1c7a13)
  • polyfill: Remove document.body.removeChild on iframe to fix DeadObject error in Firefox (204bf3b)

Features

  • allow passing the instanceof check (d65aaf4)

2.0.3 (2019-07-31)

Bug Fixes

  • polyfill: Fix issue where removing style node does not reappend the sheet (a1c7a13)

2.0.2 (2019-06-14)

2.0.1 (2019-05-13)

2.0.0 (2019-05-13)

Bug Fixes

  • Now works in Firefox (2259520)
  • package.json: Added keywords (4d707e2)
  • polyfill: Enabled multiple replacements of CSS text. (48a74a1)
  • polyfill: Performance improvements (8c286c5)
  • polyfill: Polyfill will now allow the removal of style sheets via adoptedStyleSheets setter (7120bfa)
  • polyfill: Remove document.body.removeChild on iframe to fix DeadObject error in Firefox (204bf3b)
  • polyfill: Removed the iframe after collecting contentWindow (09b7d7f)

Documentation

Features

  • polyfill: Shadow DOM nodes created before being connected now wire themselves up when connected. (33191f9)
  • stylesheets: Sheets now persist (decaf7c)

BREAKING CHANGES

  • Initial release

1.0.3 (2019-04-04)

Bug Fixes

  • polyfill: Removed the iframe after collecting contentWindow (09b7d7f)

1.0.2 (2019-03-29)

Bug Fixes

  • polyfill: Performance improvements (8c286c5)

1.0.1 (2019-02-05)

Bug Fixes

  • package.json: Added keywords (4d707e2)

1.0.0 (2019-02-05)

Documentation

BREAKING CHANGES

  • Initial release

0.3.2 (2019-02-05)

Bug Fixes

0.3.1 (2019-01-24)

Bug Fixes

  • polyfill: Polyfill will now allow the removal of style sheets via adoptedStyleSheets setter (7120bfa)

0.3.0 (2019-01-21)

Features

  • polyfill: Shadow DOM nodes created before being connected now wire themselves up when connected. (33191f9)

0.2.0 (2019-01-20)

Features

  • stylesheets: Sheets now persist (decaf7c)

0.1.3 (2019-01-20)

0.1.2 (2019-01-19)

Bug Fixes

  • polyfill: Enabled multiple replacements of CSS text. (48a74a1)

0.1.1 (2019-01-18)

Bug Fixes

  • adoptedStyleSheets: Refactored for prerelease (e6536a6)