Truly independent web browser
<!DOCTYPE html>
<script src="../../include.js"></script>
<script src="../../work-test.js"></script>
<style>
@property --turn {
syntax: "<angle>";
inherits: true;
initial-value: 0deg;
}
@property --registered {
syntax: "<angle>";
inherits: true;
initial-value: 0deg;
}
@keyframes turn {
from { --turn: 0deg; }
to { --turn: 360deg; }
}
.source {
animation: turn 1s linear infinite paused;
}
#resetting > div {
--turn: 0deg;
}
.reader {
rotate: var(--turn);
}
#declaring {
--registered: 5deg;
}
#declaring-reader, #moving-declaring-reader {
--own: 1px;
}
#moving {
--declared: 1px;
}
</style>
<div id="reading" class="source"><div><div><div class="reader" id="deep-reader"></div></div></div></div>
<div id="resetting" class="source"><div id="reset-child"></div></div>
<div id="host"><div><span class="reader" id="slotted-reader"></span></div></div>
<div id="declaring" class="source"><div class="reader" id="declaring-reader"></div></div>
<div id="moving" class="source"><div class="reader" id="moving-reader"></div><div class="reader" id="moving-declaring-reader"></div></div>
<script>
test(() => {
const shadow = document.getElementById("host").attachShadow({ mode: "open" });
shadow.innerHTML = `
<style>
@keyframes turn {
from { --turn: 0deg; }
to { --turn: 360deg; }
}
slot { animation: turn 1s linear infinite paused; }
</style>
<slot></slot>`;
// Every element below the child that resets the animated property inherits the same value on every step.
const resetChild = document.getElementById("reset-child");
for (let i = 0; i < 50; ++i) {
const div = resetChild.appendChild(document.createElement("div"));
div.appendChild(document.createElement("span")).className = "reader";
}
const step = (animation, currentTime) => styleWork(() => animation.currentTime = currentTime);
const animationOf = id => document.getElementById(id).getAnimations()[0];
internals.updateStyle();
internals.updateStyle();
const slotAnimation = shadow.querySelector("slot").getAnimations()[0];
step(slotAnimation, 250);
println(`reader in an element a slot takes: ${getComputedStyle(document.getElementById("slotted-reader")).rotate}`);
step(animationOf("reading"), 250);
println(`deep reader below non-readers: ${getComputedStyle(document.getElementById("deep-reader")).rotate}`);
step(animationOf("reading"), 500);
println(`deep reader after a step: ${getComputedStyle(document.getElementById("deep-reader")).rotate}`);
const work = step(animationOf("resetting"), 250);
// FIXME: Only the animated element and the child that resets the property should compute again, and
// no element below that child, but the style engine restyles every element below it too.
const belowReset = name => name !== "resetting" && name !== "reset-child";
const restyledBelowReset = work.restyled().map(shortStyleName).filter(belowReset);
const keptBelowReset = work.events.filter(event => event.outcome === "kept").map(event => shortStyleName(event.element)).filter(belowReset);
println(`elements below the reset restyled: [${restyledBelowReset.join(", ")}]`);
println(`elements below the reset kept: [${keptBelowReset.join(", ")}]`);
println(`reader below the reset: ${getComputedStyle(resetChild.querySelector(".reader")).rotate}`);
// An element declaring a registered custom property resolves its environment anew on every computation, which
// moves what it hands down once more; a reader declaring its own still takes the animated value.
const declaringReader = document.getElementById("declaring-reader");
animationOf("declaring").currentTime = 250;
println(`reader declaring its own below a registered declaration: ${getComputedStyle(declaringReader).rotate}`);
animationOf("declaring").currentTime = 500;
println(`that reader after a step: ${getComputedStyle(declaringReader).rotate}`);
// A change to the element's own declarations in the same update moves what it hands down once more.
const moving = document.getElementById("moving");
const rotateOf = id => getComputedStyle(document.getElementById(id)).rotate;
animationOf("moving").currentTime = 250;
moving.style.setProperty("--declared", "2px");
println(`readers when the element's declarations move too: ${rotateOf("moving-reader")}, ${rotateOf("moving-declaring-reader")}`);
animationOf("moving").currentTime = 500;
moving.style.setProperty("--declared", "3px");
println(`those readers after a step: ${rotateOf("moving-reader")}, ${rotateOf("moving-declaring-reader")}`);
});
</script>