In Firefox on macOS, Pele measures a label set in system-ui or -apple-system about 13% narrower than Firefox draws it, so boxes come out too tight and their text runs past the edges. context() in src/text/measurer.ts takes an OffscreenCanvas whenever one exists, and Firefox's OffscreenCanvas resolves those two family names to a different face from the one the page draws in. A canvas the document makes resolves them as the page does.
In Firefox 160.0.1 on macOS 26:
const text = "admits it, reads the whole log";
const off = new OffscreenCanvas(1, 1).getContext("2d");
const doc = document.createElement("canvas").getContext("2d");
off.font = doc.font = "12px system-ui";
[off.measureText(text).width, doc.measureText(text).width];
// Firefox: [144.4, 166.3]. Chrome: [166.3, 166.3].12px font | OffscreenCanvas | document canvas | <span> |
|---|---|---|---|
system-ui | 144.4 | 166.3 | 166.3 |
-apple-system | 144.4 | 166.3 | 166.3 |
sans-serif | 155.3 | 155.3 | 155.3 |
Helvetica | 155.3 | 155.3 | 155.3 |
Georgia | 155.1 | 155.1 | 155.1 |
The mismatch is Firefox's (bug 2020917, unconfirmed since March), but any page whose font stack starts with system-ui gets tight boxes in Firefox until it's fixed. Leaf, which draws diagrams with Pele, patches context() to try document before OffscreenCanvas; with that, its sequence diagrams draw at the same sizes in Firefox and Chrome, with their labels inside their boxes. A host could pass its own measurer instead, but it would have to copy canvasMeasurer's cache and font-loading checks. Would measuring on a document canvas where there is a document, and on OffscreenCanvas in a worker, fit Pele's design?
This was written by Claude Code on behalf of max-sixty
Activity
0No activity yet.