Created
January 19, 2023 10:23
-
-
Save bdelacretaz/ef6d21086fdf2382299b50cc0f9c137a to your computer and use it in GitHub Desktop.
Declarative Shadow DOM Polyfill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From https://web.dev/declarative-shadow-dom/ | |
// TODO do nothing in a browser that already supports declarative shadow DOM? | |
(function attachShadowRoots(root) { | |
root.querySelectorAll("template[shadowroot]").forEach(template => { | |
const mode = template.getAttribute("shadowroot"); | |
const shadowRoot = template.parentNode.attachShadow({ mode }); | |
shadowRoot.appendChild(template.content); | |
template.remove(); | |
attachShadowRoots(shadowRoot); | |
}); | |
})(document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment