Truly independent web browser
<!DOCTYPE html>
<meta charset="utf-8">
<script src="../../include.js"></script>
<script src="../../work-test.js"></script>
<style>
/* :has() with an interaction pseudo-class argument, anchored in
non-subject position at an ancestor of the streaming container. Plain
insertions can never change whether interaction pseudo-classes match,
so appends must not restyle the wrapper subtree. */
#wrapper:has(:focus-visible) span {
color: rgb(9, 9, 9);
}
#wrapper:has(:focus) span {
color: rgb(7, 7, 7);
}
span {
color: rgb(1, 1, 1);
}
</style>
<div id="wrapper">
<div id="big"></div>
<div id="stream"></div>
<input id="field">
</div>
<script>
test(() => {
const big = document.getElementById("big");
for (let i = 0; i < 500; ++i) {
const leaf = document.createElement("span");
leaf.textContent = `leaf ${i}`;
big.appendChild(leaf);
}
const stream = document.getElementById("stream");
const work = styleWork(() => {
for (let i = 0; i < 10; ++i) {
const p = document.createElement("p");
p.textContent = `chunk ${i}`;
stream.appendChild(p);
internals.updateStyle();
}
});
const passes = [];
for (const event of work.events) {
if (event.event === "pass")
passes.push({ kind: event.kind, restyled: [] });
else
passes.at(-1).restyled.push(shortStyleName(event.element));
}
println(`appends near interaction :has() restyled per pass: ${passes.map(pass => `${pass.kind} [${pass.restyled.join(", ")}]`).join(", ")}`);
// Focus changes and removal of a focused element must still invalidate
// the :has(:focus) anchor.
const someLeaf = big.firstElementChild;
const field = document.getElementById("field");
field.focus();
println(`focused: ${getComputedStyle(someLeaf).color}`);
field.remove();
println(`focused element removed: ${getComputedStyle(someLeaf).color}`);
});
</script>