Truly independent web browser
<!DOCTYPE html>
<script src="../include.js"></script>
<style>
#grid {
display: grid;
width: 50px;
height: 50px;
grid-template: 50px / 50px;
}
#item {
width: 100px;
height: 100px;
}
</style>
<div id="grid"><div id="item"></div></div>
<script>
test(() => {
const grid = document.getElementById("grid");
const item = document.getElementById("item");
function setAlignment(value, inherited) {
grid.style.justifyItems = inherited ? value : "normal";
grid.style.alignItems = inherited ? value : "normal";
item.style.justifySelf = inherited ? "auto" : value;
item.style.alignSelf = inherited ? "auto" : value;
}
function offset() {
const gridRect = grid.getBoundingClientRect();
const itemRect = item.getBoundingClientRect();
return JSON.stringify([itemRect.left - gridRect.left, itemRect.top - gridRect.top]);
}
for (const writingMode of ["horizontal-tb", "vertical-rl", "vertical-lr"]) {
grid.style.writingMode = writingMode;
for (const direction of ["ltr", "rtl"]) {
grid.style.direction = direction;
setAlignment("start", false);
const start = offset();
for (const alignment of ["end", "center"]) {
for (const inherited of [false, true]) {
const label = `${writingMode} ${direction} ${inherited ? "inherited" : "explicit"} ${alignment}`;
setAlignment(`safe ${alignment}`, inherited);
println(`${label} oversized safe uses start: ${offset() === start}`);
setAlignment(`unsafe ${alignment}`, inherited);
println(`${label} oversized unsafe keeps alignment: ${offset() !== start}`);
item.style.width = "20px";
item.style.height = "20px";
setAlignment(alignment, false);
const fitting = offset();
setAlignment(`safe ${alignment}`, inherited);
println(`${label} fitting safe keeps alignment: ${offset() === fitting}`);
item.style.width = "100px";
item.style.height = "100px";
}
}
}
}
});
</script>