Skip to content

Truly independent web browser

1.5 KB
Raw Blame
<!DOCTYPE html>
<style>
    @font-face { font-family: Ahem; src: url("../../Ref/data/fonts/Ahem.ttf"); }
    body { font: 10px/20px Ahem; }
    .c { width: 40px; line-break: anywhere; margin-bottom: 10px; }
    .hyphen { width: min-content; line-break: anywhere; font: 40px sans-serif; }
</style>
<div class="c" id="line-full-at-inline-box-start">aaaa<span>bbbb</span></div>
<div class="c" id="line-full-at-inline-box-end"><span>aaaa</span>bbbb</div>
<div class="hyphen" id="soft-hyphen-manual" style="hyphens: manual">i&shy;i</div>
<div class="hyphen" id="soft-hyphen-none" style="hyphens: none">i&shy;i</div>
<script src="include.js"></script>
<script>
    asyncTest(async done => {
        await document.fonts.load("10px Ahem");
        for (const c of document.querySelectorAll(".c")) {
            const text = [...c.querySelectorAll("*"), c].flatMap(element => [...element.childNodes]).find(node => node.nodeType === Node.TEXT_NODE && node.data.startsWith("b"));
            const range = document.createRange();
            range.setStart(text, 0);
            range.setEnd(text, 1);
            const line = (range.getClientRects()[0].top - c.getBoundingClientRect().top + 5) / 20;
            println(`${c.id}: height ${c.getBoundingClientRect().height}, first b on line ${Math.floor(line) + 1}`);
        }
        const width = id => document.getElementById(id).getBoundingClientRect().width;
        println(`a manual soft hyphen widens the min-content by ${width("soft-hyphen-manual") - width("soft-hyphen-none")}`);
        done();
    });
</script>