Skip to content

Truly independent web browser

1.6 KB
Raw Blame
<!DOCTYPE html>
<script src="../../include.js"></script>
<script src="../../work-test.js"></script>
<script src="structural-matrix.js"></script>
<style>
    #queried { --state: off }
    #queried.changed { --state: on }
    #unqueried.changed { background-color: blue }
    @container style(--state: on) {
        #dependent { color: rgb(1, 2, 3) }
    }
</style>
<div id="unqueried"><div><span></span><span></span></div></div>
<div id="queried"><div><span id="dependent"></span></div></div>
<script>
    test(() => {
        const dependent = document.getElementById("dependent");
        const queried = document.getElementById("queried");
        const unqueried = document.getElementById("unqueried");

        // A style change on an element has to reach the descendants whose style container queries
        // resolved against it. A change on anything else must leave the dependent unaffected.
        println(`dependent before: ${getComputedStyle(dependent).color}`);
        internals.updateStyle();

        printPassWithStyleWork("a change on an element no query names styles only that element",
            styleWork(() => unqueried.classList.add("changed")));
        println(`unqueried background-color: ${getComputedStyle(unqueried).backgroundColor}`);
        println(`dependent after unrelated change: ${getComputedStyle(dependent).color}`);

        printPassWithStyleWork("a change on the query container styles its subtree",
            styleWork(() => queried.classList.add("changed")));
        println(`dependent after: ${getComputedStyle(dependent).color}`);
    });
</script>