Truly independent web browser
<!DOCTYPE html>
<script src="../../include.js"></script>
<style>
.item { margin: attr(data-margin type(<length>)); }
.colored { background: attr(data-color type(<color>), rgb(0, 128, 0)); }
</style>
<div class="item" id="item" data-margin="5px"></div>
<div class="colored" id="colored" data-color="qqffuutt"></div>
<script>
// A shorthand written with attr() leaves its longhands pending the shorthand's substitution,
// which reads the element's attributes, and follows an attribute change.
test(() => {
internals.updateStyle();
for (const element of [item, colored]) {
const clone = element.cloneNode();
clone.removeAttribute("id");
document.body.append(clone);
}
internals.updateStyle();
println(`margin: ${getComputedStyle(item).marginLeft}`);
println(`invalid color falls back: ${getComputedStyle(colored).backgroundColor}`);
item.dataset.margin = "7px";
colored.dataset.color = "rgb(0, 0, 255)";
internals.updateStyle();
println(`margin: ${getComputedStyle(item).marginLeft}`);
println(`color: ${getComputedStyle(colored).backgroundColor}`);
});
</script>