From e78e71528864cff13c440a736feee42d3704fb84 Mon Sep 17 00:00:00 2001
From: Owen Buckley --- Constructable Stylesheets and adoptedStyleSheets enable adding styles directly to shadow roots without creating new DOM elements. Because a single stylesheet object can be adopted by multiple scopes, it also allows sharing of styles that can be centrally modified. Summary or proposal based on current status; paragraph(s) and code. The following is an example of what this would look like in practice. --- From their standards position tracker, Safari has highlighted some of the following concerns:Links
Description
- Status
Initial API Summary/Quick API Proposal
-
+ const sheet = new CSSStyleSheet();
+ sheet.replaceSync('a { color: red; }');
+
+ // Apply the stylesheet to a document:
+ document.adoptedStyleSheets = [sheet];
+
+ // Apply the stylesheet to a Shadow Root:
+ const node = document.createElement('div');
+ const shadow = node.attachShadow({ mode: 'open' });
+ shadow.adoptedStyleSheets = [sheet];
+
Key Scenarios
-
+
Concerns
-
-
+
+
+
Constructable Stylesheets and adoptedStyleSheets enable adding styles directly to shadow roots without creating new DOM elements. Because a single stylesheet object can be adopted by multiple scopes, it also allows sharing of styles that can be centrally modified.
+Constructable Stylesheets and adoptedStyleSheets enable adding styles directly to DOM trees, e.g. `document` and shadow roots, without creating new DOM elements. Because a single stylesheet object can be adopted by multiple scopes, it also allows sharing of styles that can be centrally modified.