@alegendstale/holly-components
Version:
Reusable UI components created using lit
29 lines (28 loc) • 1.06 kB
JavaScript
import d from "../gentle-register-property.js";
import a from "../Bug.js";
new a({
name: "ADOPTED_STYLE_SHEET",
detect() {
let e = document.createElement("div");
if (document.body.append(e), e.attachShadow({ mode: "open" }), Object.isFrozen(e.shadowRoot.adoptedStyleSheets))
return e.remove(), !1;
d("--style-observer-adopted-style-sheet-bug", {
syntax: "<number>",
inherits: !0,
initialValue: 0
});
let t = new CSSStyleSheet();
t.insertRule(`
:host {
/* This declaration shouldn't be empty for the bug to trigger */
color: transparent;
}
`), e.shadowRoot.adoptedStyleSheets.push(t);
let r = t.cssRules[0].style;
r.setProperty("--style-observer-adopted-style-sheet-bug", "1");
let o = getComputedStyle(e), s = o.getPropertyValue("--style-observer-adopted-style-sheet-bug");
r.removeProperty("--style-observer-adopted-style-sheet-bug"), o = getComputedStyle(e);
let l = o.getPropertyValue("--style-observer-adopted-style-sheet-bug");
return e.remove(), s === l;
}
});