Truly independent web browser
<!DOCTYPE html>
<meta charset="utf-8">
<script src="../../include.js"></script>
<script src="../../work-test.js"></script>
<div id="host"></div>
<script>
function settle(triggerElement) {
getComputedStyle(triggerElement).animationName;
getComputedStyle(triggerElement).animationName;
internals.updateStyle();
}
function addBystanders(parent, count) {
for (let i = 0; i < count; ++i) {
const bystander = document.createElement("div");
bystander.textContent = `bystander ${i}`;
parent.appendChild(bystander);
}
}
function dumpWork(label, mutate) {
const work = styleWork(mutate);
const fullPass = work.passes().includes("FULL") ? " (full pass)" : "";
println(`${label}: restyled [${work.restyled().map(shortStyleName).join(", ")}]${fullPass}`);
}
test(() => {
const host = document.getElementById("host");
const shadowRoot = host.attachShadow({ mode: "open" });
const hostStyle = document.createElement("style");
hostStyle.textContent = ":host { animation-name: fade; animation-duration: 1s; }";
shadowRoot.appendChild(hostStyle);
// Bystanders inside the shadow subtree highlight the work that a
// shadow-scope-broad invalidation does even though only the host
// (which lives outside the shadow subtree, but matches via :host)
// actually depends on the new keyframes.
addBystanders(shadowRoot, 25);
settle(host);
// Adding a sheet whose only effect is declaring @keyframes fade should
// dirty just the host, whose computed animation-name is "fade" via
// the earlier :host rule.
// Nothing but the arriving style element: the host's animation is planned again without a
// restyle.
dumpWork("@keyframes only sheet add (host animation-name via :host)", () => {
const keyframesStyle = document.createElement("style");
keyframesStyle.textContent = "@keyframes fade { from { opacity: 0.25; } to { opacity: 0.25; } }";
shadowRoot.appendChild(keyframesStyle);
getComputedStyle(host).animationName;
});
println(`host opacity: ${getComputedStyle(host).opacity}`);
});
</script>