Truly independent web browser
<!DOCTYPE html>
<style>
#outer {
--theme: 1px;
}
.child {
--own: 2px;
margin-left: var(--own);
}
</style>
<div id="outer"></div>
<script src="../include.js"></script>
<script src="../work-test.js"></script>
<script>
test(() => {
const outer = document.getElementById("outer");
for (let i = 0; i < 20; i++) {
const child = document.createElement("div");
child.className = "child";
child.textContent = "child";
outer.append(child);
}
getComputedStyle(outer.lastChild).marginLeft;
const work = styleWork(() => outer.style.setProperty("--theme", "2px"));
println("margin after change: " + getComputedStyle(outer.lastChild).marginLeft);
println("every child keeps its own margin: " + [...outer.children].every(child => getComputedStyle(child).marginLeft === "2px"));
println("every child inherits the new theme: " + [...outer.children].every(child => getComputedStyle(child).getPropertyValue("--theme") === "2px"));
// No child reads --theme, so none of them computes its style again: the moved environment
// reaches each child directly.
println(`restyled: [${work.restyled().map(shortStyleName).join(", ")}]`);
println(`children that only took the moved environment: ${work.count({ event: "restyle", outcome: "kept" })}`);
});
</script>