Truly independent web browser
<!DOCTYPE html>
<script src="../include.js"></script>
<style>
@font-face {
font-family: Ahem;
src: url("../../../Ref/data/fonts/Ahem.ttf");
}
body {
margin: 0;
}
</style>
<svg width="300" height="100" style="font: 40px Ahem">
<a id="link" href="#target"><text id="text" x="10" y="50">XÉp</text></a>
</svg>
<svg id="hidden-svg" width="300" height="100" style="font: 40px Ahem">
<text x="10" y="50">X<tspan visibility="hidden">XXX</tspan></text>
</svg>
<svg id="on-path-svg" width="300" height="100" style="font: 40px Ahem">
<path id="path" d="M 100 80 H 300" />
<text><textPath href="#path"><tspan id="on-path">XX</tspan></textPath></text>
</svg>
<p><a id="html-link" href="#target">HTML link</a></p>
<script>
asyncTest(async done => {
await document.fonts.ready;
// Ahem's X fills its whole cell, but É and p leave parts of their cells blank: above the É's accent and below
// the p's descender. Those blank parts of the cells still hit the text.
const text = document.getElementById("text");
const cells = text.getBoundingClientRect();
const cell = 40;
const hit = (x, y) => document.elementFromPoint(x, y)?.localName;
println(`middle of the X: ${hit(cells.left + cell / 2, cells.top + cell / 2)}`);
println(`blank top of the p's cell: ${hit(cells.left + cell * 2.75, cells.top + 2)}`);
println(`between two cells: ${hit(cells.left + cell, cells.top + cell / 2)}`);
println(`above the cells: ${hit(cells.left + cell / 2, cells.top - 5)}`);
println(`past the last cell: ${hit(cells.left + cell * 3 + 5, cells.top + cell / 2)}`);
// An element takes hits in the cells of its own characters, not in those of a hidden element inside it.
const hiddenBox = document.getElementById("hidden-svg").getBoundingClientRect();
println(`over the text: ${hit(hiddenBox.left + 30, hiddenBox.top + 30)}`);
println(`over a hidden tspan in the text: ${hit(hiddenBox.left + 100, hiddenBox.top + 30)}`);
// A <tspan> on a path takes hits where its glyphs are drawn, not where it would be off the path.
const pathBox = document.getElementById("on-path-svg").getBoundingClientRect();
println(`on a glyph of a tspan on a path: ${hit(pathBox.left + 120, pathBox.top + 70)}`);
println(`where the tspan would be off the path: ${hit(pathBox.left + 20, pathBox.top + 2)}`);
// The link rules of the HTML rendering section are for HTML elements only.
const svgLink = getComputedStyle(document.getElementById("link"));
const htmlLink = getComputedStyle(document.getElementById("html-link"));
println(`SVG link: text-decoration-line ${svgLink.textDecorationLine}, cursor ${svgLink.cursor}`);
println(`HTML link: text-decoration-line ${htmlLink.textDecorationLine}, cursor ${htmlLink.cursor}`);
done();
});
</script>