Truly independent web browser
<!DOCTYPE html>
<script src="../../include.js"></script>
<style id="rules">
#target::first-line { color: rgb(0, 0, 128); }
#target::view-transition { color: rgb(128, 0, 128); }
</style>
<div id="outer"><div id="target">text<span id="child">child text</span></div></div>
<script>
test(() => {
// A read of any synthetic pseudo-element is answered by the style engine: ::selection while
// no selection makes it observable, and ::first-line and ::view-transition, which no style
// update settles.
const read = (element, pseudo) => {
const style = getComputedStyle(element, pseudo);
println(`${element.id}${pseudo}: color ${style.color}, background-color ${style.backgroundColor}`);
};
internals.updateStyle();
// The rules come after the last style update settled the elements, which leaves the
// unobservable ::selection alone.
rules.sheet.insertRule("#outer::selection { color: rgb(10, 20, 30); background-color: rgb(40, 50, 60); }");
rules.sheet.insertRule("#target::selection { color: rgb(70, 80, 90); }");
internals.updateStyle();
read(target, "::selection");
// A ::selection no rule styles inherits its ancestor's.
read(child, "::selection");
read(target, "::first-line");
read(target, "::view-transition");
read(child, "::first-line");
// No style update keeps those records current, nor the ::marker of an element that is no list
// item, so a read after their rules moved settles them again.
rules.sheet.insertRule("#target::marker { color: rgb(0, 128, 0); }");
read(target, "::marker");
for (const rule of rules.sheet.cssRules)
rule.style.color = "rgb(255, 0, 255)";
read(target, "::selection");
read(target, "::first-line");
read(target, "::view-transition");
read(target, "::marker");
});
</script>