Truly independent web browser
<!DOCTYPE html>
<script src="../../include.js"></script>
<style>
.first { color: red; }
.second { color: red; }
.changed { color: blue; }
.pseudo-first::before { content: "same"; }
.pseudo-second::before { content: "same"; }
#state-target:state(active) { background-color: green; }
#state-target:not(:state(active)) { background-color: green; }
</style>
<div id="target" class="first">target</div>
<div id="pseudo" class="pseudo-first">pseudo target</div>
<state-target id="state-target">state target</state-target>
<script>
customElements.define("state-target", class extends HTMLElement {
constructor() {
super();
this.internals = this.attachInternals();
}
});
test(() => {
const stateTarget = document.getElementById("state-target");
internals.updateStyle();
target.className = "second";
internals.updateStyle();
println(`unchanged color: ${getComputedStyle(target).color}`);
target.className = "changed";
internals.updateStyle();
println(`changed color: ${getComputedStyle(target).color}`);
pseudo.className = "pseudo-second";
internals.updateStyle();
println(`pseudo content: ${getComputedStyle(pseudo, "::before").content}`);
stateTarget.internals.states.add("active");
internals.updateStyle();
println(`state background: ${getComputedStyle(stateTarget).backgroundColor}`);
});
</script>