Skip to content

Truly independent web browser

3.6 KB
Raw Blame
<!DOCTYPE html>
<script src="../include.js"></script>
<style>
    #outer { color: rgb(10, 20, 30); font-size: 20px; --decoration-color: rgb(40, 50, 60); }
    #inner { font-size: 10px; --decoration-color: rgb(70, 80, 90); }
    #outer::selection { color: rgb(100, 110, 120); background-color: rgb(130, 140, 150); text-decoration-color: var(--decoration-color); }
    #inner::selection { text-shadow: rgb(160, 170, 180) 1em 0; text-decoration-color: var(--decoration-color); }
    #unset::selection { color: unset; background-color: unset; }
    #initial::selection { background-color: initial; }
    #currentcolor::selection { color: currentColor; background-color: currentColor; }
    #host::selection { background-color: rgb(190, 200, 210); }
    #slot-host::selection { background-color: rgb(220, 230, 240); }
</style>
<div id="outer"><span id="inner">inner <span id="unset">unset</span> <span id="initial">initial</span> <span id="currentcolor">currentcolor</span></span></div>
<div id="root-level">root level</div>
<div id="host"></div>
<div id="slot-host"><span id="slotted">slotted</span></div>
<script>
    test(() => {
        const style = element => getComputedStyle(element, "::selection");
        const describe = element => `${style(element).color} / ${style(element).backgroundColor}`;

        const report = () => {
            println(`outer: ${describe(outer)}`);
            println(`inner inherits both colors: ${describe(inner)}`);
            println(`inner keeps its own text-shadow: ${style(inner).textShadow}`);
            println(`inner resolves em against its own font-size: ${style(inner).fontSize}`);
            println(`decoration colors use each originating element's custom property: ${style(outer).textDecorationColor}, ${style(inner).textDecorationColor}`);
            println(`unset inherits: ${describe(unset)}`);
            println(`unset inherits the computed text-shadow: ${style(unset).textShadow}`);
            println(`initial background: ${style(initial).backgroundColor}`);
            println(`currentColor is the originating element's color: ${describe(currentcolor)}`);
            println(`root-level color falls back to the originating element's: ${describe(document.getElementById("root-level"))}`);
        };

        host.attachShadow({ mode: "open" }).innerHTML = "<span id='shadow-inner'>shadow</span>";
        document.getElementById("slot-host").attachShadow({ mode: "open" }).innerHTML = "<slot></slot>";
        const shadowInner = host.shadowRoot.getElementById("shadow-inner");

        println("--- without a selection");
        report();
        println(`shadow tree inherits from the host: ${style(shadowInner).backgroundColor}`);
        println(`slotted content inherits through the slot: ${style(slotted).backgroundColor}`);

        const range = document.createRange();
        range.selectNodeContents(document.body);
        getSelection().addRange(range);
        internals.updateStyle();

        println("--- with a selection");
        report();
        println(`shadow tree inherits from the host: ${style(shadowInner).backgroundColor}`);
        println(`slotted content inherits through the slot: ${style(slotted).backgroundColor}`);

        inner.style.fontSize = "30px";
        println(`text-shadows after the originating font-size change: ${style(inner).textShadow}, ${style(unset).textShadow}`);
        document.styleSheets[0].cssRules[2].style.backgroundColor = "rgb(1, 2, 3)";
        println(`inner background after the parent's rule change: ${style(inner).backgroundColor}`);
        println(`unset background after the parent's rule change: ${style(unset).backgroundColor}`);
    });
</script>