Skip to content

Truly independent web browser

1.2 KB
Raw Blame
<!DOCTYPE html>
<script src="../../include.js"></script>
<style id="sheet">
    .a { color: rgb(1, 0, 0) }
    .b { color: rgb(2, 0, 0) }
    .c { color: rgb(3, 0, 0) }
</style>
<div id="target" tabindex="0"></div>
<script>
    test(() => {
        const sheet = document.getElementById("sheet").sheet;
        const target = document.getElementById("target");
        document.body.offsetWidth;

        // Editing a sheet moves one rule; the rules around it are untouched.
        sheet.insertRule("#target:focus { color: rgb(0, 128, 0) }", 1);

        // The rule landed where it was asked to, and it routes.
        target.focus();
        println(`target colour: ${getComputedStyle(target).color}`);
        println(`rule index 1: ${sheet.cssRules[1].selectorText}`);

        // Its selector can change without the sheet being rebuilt, and the old selector stops
        // reaching anything.
        sheet.cssRules[1].selectorText = "#target:focus, .unrelated";
        println(`target colour after edit: ${getComputedStyle(target).color}`);

        sheet.deleteRule(1);
        println(`target colour after delete: ${getComputedStyle(target).color}`);
    });
</script>