Skip to content

Truly independent web browser

1.7 KB
Raw Blame
<!DOCTYPE html>
<script src="../../include.js"></script>
<div id="host"><div id="slottable"></div></div>
<script>
    test(() => {
        const host = document.getElementById("host");
        const slottable = document.getElementById("slottable");
        const shadowRoot = host.attachShadow({ mode: "open" });
        shadowRoot.innerHTML = `
            <style>::slotted(div) { --assignment: remaining-slot }</style>
            <slot id="first"></slot>
            <slot id="second"><div></div></slot>
        `;
        const first = shadowRoot.getElementById("first");
        const second = shadowRoot.getElementById("second");
        document.body.offsetWidth;

        first.remove();

        println(`assigned to remaining slot: ${slottable.assignedSlot === second}`);
        println(`slotted style after reassignment: ${getComputedStyle(slottable).getPropertyValue("--assignment")}`);

        const hostWithoutReplacement = document.createElement("div");
        hostWithoutReplacement.style.color = "rgb(255, 0, 0)";
        const slottableWithoutReplacement = document.createElement("span");
        hostWithoutReplacement.appendChild(slottableWithoutReplacement);
        document.body.appendChild(hostWithoutReplacement);
        const rootWithoutReplacement = hostWithoutReplacement.attachShadow({ mode: "open" });
        rootWithoutReplacement.innerHTML = `<style>slot { color: rgb(0, 0, 255) }</style><slot></slot>`;
        getComputedStyle(slottableWithoutReplacement).color;

        rootWithoutReplacement.replaceChildren();

        println(`unassigned after slot removal: ${slottableWithoutReplacement.assignedSlot === null}`);
        println(`style after slot removal: ${getComputedStyle(slottableWithoutReplacement).color}`);
    });
</script>