From a7ece9830aef70e9470e5365f0820a18186f18ea Mon Sep 17 00:00:00 2001
From: Kurt Catti-Schmidt DocumentOrShadowRoot Interface Mixin:
+
+
+ shadowrootclonableshadowrootserializableshadowrootcustomelementregistryshadowrootadoptedstylesheets
The shadowrootadoptedstylesheets content
+ contributes to the host's
+ adoptedStyleSheets.
The template contents of a template element are not children of the element itself.
The stylesheet adopting steps for template elements are:
If the value of + shadowrootadoptedstylesheets is + empty, then return.
Let adoptedStyleSheets be an empty array.
For each unordered set of unique space-separated tokens specifier in + shadowrootadoptedstylesheets:
+Let url be the result of resolving + a module specifier given moduleScript and specifier.
If + any errors occur, then continue.Let settingsObject be the current settings object.
Let moduleType be "css".
Let moduleMap be settingsObject's module map.
Let moduleScript be + moduleMap[(url, moduleType)].
If moduleScript is null, then continue.
Extract the CSSStyleSheet from moduleScript's
+ record and append it to
+ adoptedStyleSheets. If any error occurs, then continue.
Extend host's + adoptedStyleSheets with adoptedStyleSheets.
This example demonstrates two equivalent methods to import CSS module scripts, the
+ first using the JavaScript import method and the second using the
+ shadowrootadoptedstylesheets
+ attribute.
+<script type="importmap">
+{
+ "imports": {
+ "foo": "data:text/css,div {color:blue}"
+ }
+}
+</script>
+<div id="host">
+ <template shadowrootmode="open">
+ <script type="module">
+ import styles from "foo" with { type: "css"};
+ document.getElementById("host").shadowRoot.adoptedStyleSheets = [styles];
+ </script>
+ <div>test</div>
+ </template>
+</div>
+<div id="host_shadowrootadoptedstylesheets_attribute">
+ <template shadowrootmode="open" shadowrootadoptedstylesheets="foo">
+ <div>test</div>
+ </template>
+</div>
+
+ If templateStartTag has a shadowrootadoptedstylesheets
+ attribute, then perform the stylesheet adopting steps on template.
shadowrootdelegatesfocus;
shadowrootclonable;
shadowrootserializable;
- shadowrootcustomelementregistry
+ shadowrootcustomelementregistry;
+ shadowrootadoptedstylesheets
HTMLTemplateElementoption
shadowrootadoptedstylesheets
+ template
+ shadowrootclonable
template
From b576c0949c8412dd616b6dd2b1b63a5c7e12dbb8 Mon Sep 17 00:00:00 2001
From: Kurt Catti-Schmidt CSSStyleSheetCSSStyleSheetLet url be the result of resolving - a module specifier given moduleScript and specifier.
If + a module specifier with specifier. If any errors occur, then continue.Let settingsObject be the current settings object.
Let moduleType be "css".
Let moduleScript be moduleMap[(url, moduleType)].
If moduleScript is null, then continue.
If moduleScript is null:
+Set moduleScript to the result of create a CSS module script with an empty + source and settingsObject.
Set moduleMap[(url, moduleType)] to + moduleScript.
Fetch a single module script given url,
+ settingsObject, "style", the
+ default script fetch options, settingsObject, "client", true, and with the following steps given result:
If result is null, then continue.
Extract the CSSStyleSheet from result's record and replaceSync on the
+ underlying CSSStyleSheet with the contents of result.
Extract the CSSStyleSheet from moduleScript's
record and append it to
adoptedStyleSheets. If any error occurs, then continue.
client", true, and with the following steps given result:
If result is null, then continue.
Extract the CSSStyleSheet from result's record and replaceSync on the
- underlying CSSStyleSheet with the contents of result.
If result is null, then abort these steps.
Let fetchedSheet be the CSSStyleSheet extracted from
+ result's record.
Let existingSheet be the CSSStyleSheet extracted from
+ moduleScript's record.
Call replaceSync on existingSheet given the + CSS text of + fetchedSheet.
Let moduleScript be moduleMap[(url, moduleType)].
If moduleScript is null:
-Set moduleScript to the result of create a CSS module script with an empty - source and settingsObject.
Set moduleMap[(url, moduleType)] to - moduleScript.
Fetch a single module script given url,
- settingsObject, "style", the
- default script fetch options, settingsObject, "client", true, and with the following steps given result:
If result is null, then abort these steps.
Let fetchedSheet be the CSSStyleSheet extracted from
- result's record.
Let existingSheet be the CSSStyleSheet extracted from
- moduleScript's record.
Call replaceSync on existingSheet given the - CSS text of - fetchedSheet.
If moduleScript is null, fetch a single module script given
+ url, settingsObject, "style", the
+ default script fetch options, settingsObject, "client", true
Extract the CSSStyleSheet from moduleScript's
record and append it to
adoptedStyleSheets. If any error occurs, then continue.
Set moduleMap[(url,
moduleType)] to "fetching".
If destination is "style", then:
Let emptyStyleScript be the result of creating a CSS module + script with an empty source and settingsObject
set moduleMap[(url,
+ moduleType)] to emptyStyleScript, retaining the "fetching" status.
Let request be a new request whose
URL is url, mode is " If the MIME type essence of mimeType is "cors", text/css"
and moduleType is "css", then set moduleScript to
- the result of creating a CSS module script given sourceText and
- settingsObject.
If mimeType is a JSON MIME type and
moduleType is "json", then set moduleScript to
@@ -117978,6 +117966,32 @@ document.querySelector("button").addEventListener("click", bound);
+
To update a CSS module script, given a + string source and a script module script :
+ +Let sheet be the default export of script
Run the steps to synchronously replace the rules of a CSSStyleSheet
+ on sheet given source.
If this throws an exception, catch it, and set script's parse error to that exception, and return + script.
+ +The steps to synchronously replace the rules of a
+ CSSStyleSheet will throw if source contains any @import rules. This is by-design for now because there is not yet an
+ agreement on how to handle these for CSS module scripts; therefore they are blocked altogether
+ until a consensus is reached.
Return script.
To create a JSON module script, given a string source and an environment settings object settings:
From 7eff3003b3bff1e23ad53e28b569a1db4bc364dd Mon Sep 17 00:00:00 2001 From: Kurt Catti-SchmidtLet adoptedStyleSheets be an empty array.
For each unordered set of unique space-separated tokens specifier in +
For each ordered set of unique space-separated tokens specifier in shadowrootadoptedstylesheets:
Let url be the result of resolving @@ -154143,7 +154143,7 @@ interface External {
shadowrootadoptedstylesheets
template
shadowrootclonable
template
From ed9b8f730f5cc6ce9aa40743efe6280ca6f6c528 Mon Sep 17 00:00:00 2001
From: Kurt Catti-Schmidt Note that these two examples are functionally equivalent, but the example with + shadowrootadoptedstylesheets + might initially render without styles applied.
+Extract the CSSStyleSheet from moduleScript's
record and append it to
- adoptedStyleSheets. If any error occurs, then continue.
CSSStyleSheet from adoptedStyleSheetsand continue.
Extend host's @@ -144705,6 +144707,11 @@ document.body.appendChild(text);
If shadow's clonable is set, then append
" shadowrootclonable=""".
If shadow's shadowrootadoptedstylesheets is set, then append
+ the value of shadowrootadoptedstylesheets
Let shouldAppendRegistryAttribute be the result of running these steps:
From 389718895924e1fa585ffd9b1ad135a7a0d7e4e3 Mon Sep 17 00:00:00 2001 From: Kurt Catti-SchmidtLet adoptedStyleSheets be an empty array.
For each ordered set of unique space-separated tokens specifier in - shadowrootadoptedstylesheets:
+Split the attribute's value on ASCII + whitespace, and let specifiers be the resulting tokens.
For each specifier of specifiers:
Let url be the result of resolving a module specifier with specifier.
If