Last active
January 12, 2024 20:06
-
-
Save knowler/ab3bcc7aa7ffd5584f22480db53e7b6b to your computer and use it in GitHub Desktop.
Pug mixin for an open Declarative Shadow DOM that polyfills itself.
This file contains hidden or 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
mixin shadow | |
template(shadowrootmode="open") | |
block | |
script. | |
{ | |
const element = document.currentScript.parentElement; | |
if (!element.shadowRoot) { | |
element.attachShadow({ mode: "open"}) | |
const template = element.querySelector(":scope > template[shadowrootmode=open]"); | |
if (template) element.shadowRoot.appendChild(template.content.cloneNode(true)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment