Truly independent web browser
<!doctype html>
<script src="../include.js"></script>
<script src="../work-test.js"></script>
<style>
@scope (li:first-child) { .in-first { color: rgb(0, 128, 0); } }
@scope (.a + .b) { .in-next { color: rgb(0, 128, 0); } }
@scope (.card:has(.on)) { .in-card { color: rgb(0, 128, 0); } }
@scope (:nth-child(1 of .x)) { .in-of { color: rgb(0, 128, 0); } }
.plain:first-child { margin-left: 1px; }
.plain + .plain { margin-left: 2px; }
</style>
<div id="unrelated"><div class="plain"><span>x</span></div><div class="plain"><span>x</span></div></div>
<ul id="list"><li><a class="in-first">x</a></li></ul>
<script>
// What a bound of `@scope` tests restyles the subtrees of the elements it matched or matches, rather than those of
// the children of any parent whose children read where they stand, or the whole document.
test(() => {
const unrelated = document.getElementById("unrelated");
const list = document.getElementById("list");
const link = list.querySelector("a");
const restyledBy = change => {
const work = styleWork(change);
const restyled = `[${work.restyled().map(shortStyleName).join(", ")}]`;
return work.passes().includes("FULL") ? `full pass, ${restyled}` : restyled;
};
const newcomer = document.createElement("div");
println(`arrival among children read by a plain rule: ${restyledBy(() => unrelated.prepend(newcomer))}`);
println(`departure among children read by a plain rule: ${restyledBy(() => newcomer.remove())}`);
println(`a class nothing tests: ${restyledBy(() => unrelated.classList.add("untested"))}`);
const pushed = document.createElement("li");
println(`arrival moving a root: ${restyledBy(() => list.prepend(pushed))}`);
println(`moved root: ${getComputedStyle(link).color}`);
pushed.remove();
println(`moved back: ${getComputedStyle(link).color}`);
});
</script>