astro/packages/integrations/lit/client-shim.js
2023-07-03 20:59:43 +08:00

22 lines
512 B
JavaScript

async function polyfill() {
const { hydrateShadowRoots } = await import(
'@webcomponents/template-shadowroot/template-shadowroot.js'
);
window.addEventListener('DOMContentLoaded', () => hydrateShadowRoots(document.body), {
once: true,
});
}
const polyfillCheckEl = new DOMParser()
.parseFromString(
`<p><template shadowroot="open" shadowrootmode="open"></template></p>`,
'text/html',
{
includeShadowRoots: true,
}
)
.querySelector('p');
if (!polyfillCheckEl?.shadowRoot) {
polyfill();
}