chrome: fit the stacked title to its whole text in Chromium too
In Chromium the stacked bar's title field cut its last letter off
("Onboardin", "Brightwater Lab"). fit() set the field to its scroll width
at zero width plus its borders and a 2px caret, on the belief that the
scroll width holds both paddings in Chromium and WebKit alike. It does in
WebKit, whose scroll and client widths are an input's padding box; in
Chromium they are its content box (the inner editor), so the scroll width
is the text alone and the field came out 12.8px short, both paddings.
CSS (the stacked caps) and TitleEdit.Size (the no-script guess, which
errs wide in both engines) were not the cause.
fit() now adds whatever of the field lies outside the box its scroll
width is measured in, offsetWidth less clientWidth: the borders in
WebKit, borders and paddings in Chromium. No getComputedStyle needed.
Measured at 1440px, stacked bar, real estilo CSS and JS (fitted width;
content box vs the title's span width; zero-width scroll/client):
Chromium 158.0.8127.18 before after
Q3 26 (11.2/22.05) 39 (24.2)
Onboarding 92 (77.2/87.81) 105 (90.2)
Brightwater Labs 131 (116.2/127.22) 144 (129.2)
Untitled document 143 (128.2/138.52) 156 (141.2)
WWWWWWWWWW 159 (144.2/154.58) 172 (157.2)
long sentence (385.12) 389 (374.2) 402 (387.2)
四半期の計画書 (106.62) 111 (96.2) 124 (109.2)
Résumé — draft (117.69) 122 (107.2) 135 (120.2)
zero width: scroll = text (127 for Brightwater Labs), client 0, offset 15
WebKit 27.2: unchanged, every title (Q3 40, Onboarding 106,
Brightwater Labs 145, Untitled document 157, WWWWWWWWWW 173, long
403, CJK 127, Résumé 136); zero width: scroll = text + paddings
(141 for Brightwater Labs), client 13, offset 15.
Tests:
- chrome.test.mjs: the fake field now models both engines' boxes, and
every fit test runs as Chromium too. The old fit() passes WebKit's
model and fails Chromium's (144px for 156px), as it did in the browsers.
- chrome/title_browser_test.go + titlefit.browser.mjs (make
test-browser, the theme/googleimport convention): the real stacked bar
in Chromium and WebKit at 1440px and 390px, nine titles; a fitted
field must have no overflow (scrollWidth <= clientWidth) and a content
box at least the title's span width, and a control (the field 12.8px
narrower) must be seen as cut off. On the old fit() it fails every
Chromium case; WebKit passes either way.
make test green; make test-browser green (Playwright 1.65.0).
Human
Prompt
Fix the stacked bar's title field being fitted too narrow in Chromium (Onboarding shows as Onboardin); measure in Chromium and WebKit, keep WebKit unchanged, add a test that would have caught it.
From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.
Summary
fit() adds offsetWidth-clientWidth (the field's frame outside the box its scroll width is measured in) instead of only the borders; Chromium measures an input's scroll width in its content box, so titles lost their last letter (12.8px short). WebKit unchanged. Node fake models both engines; new make test-browser check measures the real bar in Chromium and WebKit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+340
−54
Makefile+4 −1chrome/chrome.js+20 −12chrome/chrome.test.mjs+63 −41chrome/title_browser_test.go+174 −0chrome/titlefit.browser.mjs+79 −0
CI passed — run details
diff --git a/Makefile b/Makefile| index c0f40e5..9a2d2ba 100644 |
| --- a/Makefile |
| +++ b/Makefile |
| @@ -74,7 +74,10 @@ test-go: |
| # for the package's directory if it is not resolvable from theme/; |
| # ESTILO_BROWSERS, default chromium,webkit). Today that is theme's |
| # no-flash check for the chrome text, by pixels |
| -# (theme/fonts_browser_test.go). It runs the whole suite with the tag. |
| +# (theme/fonts_browser_test.go), the stacked bar's title field fitted to |
| +# its whole title (chrome/title_browser_test.go) and the Google import |
| +# chooser (googleimport/browser_test.go). It runs the whole suite with |
| +# the tag. |
| # An engine that will not launch fails it; it never skips to a pass. |
| test-browser: |
| CGO_ENABLED=0 go test -tags browser -count=1 ./... |
diff --git a/chrome/chrome.js b/chrome/chrome.js| index 9b39c8c..f3891fd 100644 |
| --- a/chrome/chrome.js |
| +++ b/chrome/chrome.js |
| @@ -90,22 +90,30 @@ |
| // The stacked bar's title field is as wide as its title (Paul: "It |
| // should grow according to the title, not start out full-width"). The |
| - // field measures itself: at zero width its scroll width is its own text |
| - // as it draws it with both its paddings (Chromium and WebKit alike), so |
| - // only the borders go on top, and 2px for the caret at the end of the |
| - // text. field-sizing: content, a canvas and a mirror span in the same |
| - // font all came out short in WebKit; this did not. CSS caps the width |
| - // at the room the field has (max-inline-size, which from 800px allows |
| - // for the field's pulled-back start margin), so a longer title still |
| - // scrolls inside the field. Nothing after the title on its row moves |
| - // when it changes: the stack takes the room. |
| + // field measures itself, at zero width, where its scroll width is its |
| + // own text as it draws it. The engines measure that in different boxes: |
| + // WebKit's scroll and client widths are the padding box, so its scroll |
| + // width holds both paddings; Chromium's are the content box (its inner |
| + // editor), so its scroll width is the text alone and its client width |
| + // 0. Measured on Chromium 158 and WebKit 27.2, "Brightwater Labs": |
| + // scroll width 127 and 141, client width 0 and 13. Adding only the |
| + // borders, as this once did, cut the last letter off in Chromium (the |
| + // field 12.8px short: both paddings). So whatever of the field lies |
| + // outside the box the scroll width is measured in goes on top, |
| + // offsetWidth less clientWidth: the borders in WebKit, the borders and |
| + // paddings in Chromium. Then 2px for the caret at the end of the text. |
| + // field-sizing: content, a canvas and a mirror span in the same font |
| + // all came out short in WebKit; this did not. CSS caps the width at the |
| + // room the field has (max-inline-size, which from 800px allows for the |
| + // field's pulled-back start margin), so a longer title still scrolls |
| + // inside the field. Nothing after the title on its row moves when it |
| + // changes: the stack takes the room. make test-browser holds it in |
| + // both engines (title_browser_test.go). |
| const FIT = '[estilo-bar-title-input][size]' |
| const CARET = 2 |
| const fit = (input) => { |
| - const cs = getComputedStyle(input) |
| - const px = (v) => parseFloat(v) || 0 |
| input.style.inlineSize = '0px' |
| - const w = input.scrollWidth + px(cs.borderInlineStartWidth) + px(cs.borderInlineEndWidth) |
| + const w = input.scrollWidth + input.offsetWidth - input.clientWidth |
| input.style.inlineSize = Math.ceil(w + CARET) + 'px' |
| } |
| const fitAll = () => { Array.prototype.forEach.call(document.querySelectorAll(FIT), fit) } |
diff --git a/chrome/chrome.test.mjs b/chrome/chrome.test.mjs| index 983c76d..e44aff1 100644 |
| --- a/chrome/chrome.test.mjs |
| +++ b/chrome/chrome.test.mjs |
| @@ -1,7 +1,9 @@ |
| // chrome.js behaviour, run under Node against a minimal DOM: just enough |
| // elements, attribute selectors and event dispatch for the script's own |
| -// selectors. estilo has no browser harness; the browser proof is in the |
| -// adopting apps (Sheets' tools/drive/menu-actions.mjs, Docs' menu tests). |
| +// selectors. Most of the browser proof is in the adopting apps (Sheets' |
| +// tools/drive/menu-actions.mjs, Docs' menu tests); the stacked title's |
| +// fit is also measured in Chromium and WebKit by make test-browser |
| +// (title_browser_test.go). |
| import assert from "node:assert/strict"; |
| import fs from "node:fs"; |
| import test from "node:test"; |
| @@ -146,57 +148,77 @@ test("Escape is heard before a menu that stops propagation", () => { |
| }); |
| // The stacked bar's title field. Its text draws 140px wide with 6px of |
| -// padding each side and 1px borders. As a field does in Chromium and |
| -// WebKit (measured), its scroll width at zero width is the text and both |
| -// its paddings (152), and at any other width at least that width, so a |
| -// measure that skips the zeroing reads the old width back instead. |
| -function titleField(attrs = { size: "17" }) { |
| +// padding each side and 1px borders; with no inline size set it is 400px |
| +// (its size attribute's guess). The engines measure a field's scroll and |
| +// client widths in different boxes (measured, Chromium 158 and WebKit |
| +// 27.2): WebKit's are its padding box, so at zero width its scroll width |
| +// is the text and both paddings (152) and its client width the paddings |
| +// (12); Chromium's are its content box, so at zero width its scroll width |
| +// is the text alone (140) and its client width 0. At any width the scroll |
| +// width is at least the client width, so a measure that skips the zeroing |
| +// reads the old width back. The fitted field must give the text its 140px |
| +// and the caret 2px in both: 156px. Measuring only WebKit's box, as this |
| +// fake once did, let a fit that added only the borders through, and in |
| +// Chromium that cut the title's last letter off. |
| +const PAD = 6, BORDER = 1; |
| +function titleField(attrs = { size: "17" }, engine = "webkit") { |
| const input = new El("input", { "estilo-bar-title-input": "", value: "Untitled document", ...attrs }); |
| input.text = 140; |
| input.style = { inlineSize: "" }; |
| - Object.defineProperty(input, "scrollWidth", { |
| - get() { |
| - const w = parseFloat(this.style.inlineSize); |
| - return Number.isNaN(w) || w > 0 ? Math.max(400, this.text + 12) : this.text + 12; |
| - }, |
| + const box = () => { |
| + const w = parseFloat(input.style.inlineSize); |
| + return Math.max(Number.isNaN(w) ? 400 : w, 2 * (PAD + BORDER)); // border-box: never under its own frame |
| + }; |
| + const inner = engine === "chromium" ? 2 * (PAD + BORDER) : 2 * BORDER; // what lies outside the measured box |
| + const drawn = engine === "chromium" ? 0 : 2 * PAD; // the paddings, when the measured box holds them |
| + Object.defineProperties(input, { |
| + offsetWidth: { get: () => box() }, |
| + clientWidth: { get: () => box() - inner }, |
| + scrollWidth: { get: () => Math.max(box() - inner, input.text + drawn) }, |
| }); |
| return input; |
| } |
| -const fieldStyle = () => ({ paddingInlineEnd: "6px", borderInlineStartWidth: "1px", borderInlineEndWidth: "1px" }); |
| +const fieldStyle = () => ({ paddingInlineStart: PAD + "px", paddingInlineEnd: PAD + "px", borderInlineStartWidth: BORDER + "px", borderInlineEndWidth: BORDER + "px" }); |
| +// The room the field gives its text: its content box. |
| +const room = (input) => parseFloat(input.style.inlineSize) - 2 * (PAD + BORDER); |
| -test("a stacked title field is fitted to its text when the script runs", () => { |
| - const fitted = titleField(); |
| - const plain = titleField({}); |
| - load(new El("", {}, [fitted, plain]), { getComputedStyle: fieldStyle }); |
| - // 152 at zero width (the end padding already in it), + 2 border + 2 |
| - // for the caret. |
| - assert.equal(fitted.style.inlineSize, "156px"); |
| - assert.equal(plain.style.inlineSize, "", "a one-row bar's title (no size) is left alone"); |
| -}); |
| +for (const engine of ["webkit", "chromium"]) { |
| + test(`a stacked title field is fitted to its text when the script runs (${engine})`, () => { |
| + const fitted = titleField(undefined, engine); |
| + const plain = titleField({}, engine); |
| + load(new El("", {}, [fitted, plain]), { getComputedStyle: fieldStyle }); |
| + // The text's 140, the frame's 14, and 2 for the caret. |
| + assert.equal(fitted.style.inlineSize, "156px"); |
| + assert.ok(room(fitted) >= fitted.text, "the whole title has room"); |
| + assert.equal(plain.style.inlineSize, "", "a one-row bar's title (no size) is left alone"); |
| + }); |
| +} |
| test("the title is fitted again as it is typed, on resize, at load and when fonts settle", async () => { |
| - const input = titleField(); |
| - let settle; |
| - const fonts = { ready: new Promise((r) => { settle = r; }) }; |
| - const dispatch = load(new El("", {}, [input]), { getComputedStyle: fieldStyle, fonts }); |
| - input.text = 200; |
| - dispatch("input", input); |
| - assert.equal(input.style.inlineSize, "216px", "input"); |
| - input.text = 100; |
| - dispatch.window("resize"); |
| - assert.equal(input.style.inlineSize, "116px", "resize"); |
| - input.text = 120; |
| - dispatch.window("load"); |
| - assert.equal(input.style.inlineSize, "136px", "load"); |
| - input.text = 130; |
| - settle(); |
| - await fonts.ready; |
| - await null; |
| - assert.equal(input.style.inlineSize, "146px", "document.fonts.ready"); |
| + for (const engine of ["webkit", "chromium"]) { |
| + const input = titleField(undefined, engine); |
| + let settle; |
| + const fonts = { ready: new Promise((r) => { settle = r; }) }; |
| + const dispatch = load(new El("", {}, [input]), { getComputedStyle: fieldStyle, fonts }); |
| + input.text = 200; |
| + dispatch("input", input); |
| + assert.equal(input.style.inlineSize, "216px", engine + " input"); |
| + input.text = 100; |
| + dispatch.window("resize"); |
| + assert.equal(input.style.inlineSize, "116px", engine + " resize"); |
| + input.text = 120; |
| + dispatch.window("load"); |
| + assert.equal(input.style.inlineSize, "136px", engine + " load"); |
| + input.text = 130; |
| + settle(); |
| + await fonts.ready; |
| + await null; |
| + assert.equal(input.style.inlineSize, "146px", engine + " document.fonts.ready"); |
| + } |
| }); |
| test("Escape restores the title and fits the field to it again", () => { |
| - const input = titleField(); |
| + const input = titleField(undefined, "chromium"); |
| const dispatch = load(new El("", {}, [input]), { getComputedStyle: fieldStyle }); |
| input.defaultValue = "Untitled document"; |
| input.value = "Something much longer"; |
diff --git a/chrome/title_browser_test.go b/chrome/title_browser_test.go| new file mode 100644 |
| index 0000000..211a0d2 |
| --- /dev/null |
| +++ b/chrome/title_browser_test.go |
| @@ -0,0 +1,174 @@ |
| +//go:build browser |
| + |
| +// The stacked bar's title field, fitted by chrome.js, in real engines. |
| +// Not part of `make test`: it needs Node 22+ and Playwright with its |
| +// browsers (ESTILO_PLAYWRIGHT names the playwright package directory |
| +// when it is not resolvable from here; ESTILO_BROWSERS picks engines, |
| +// default "chromium,webkit"). Run it with `make test-browser`. An engine |
| +// that will not launch fails the test; it never skips to a pass. |
| +// |
| +// 2026-11-14: in Chromium the fitted field cut the title's last letter |
| +// off ("Onboardin", "Brightwater Lab"), 12.8px short, both paddings, |
| +// because Chromium measures an input's scroll width in its content box |
| +// and WebKit in its padding box, and the node test's fake field was |
| +// WebKit's. This is the check that would have caught it. |
| +package chrome |
| + |
| +import ( |
| + "bytes" |
| + "encoding/json" |
| + "fmt" |
| + "net/http" |
| + "net/http/httptest" |
| + "os" |
| + "os/exec" |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/oficina/estilo.git/base" |
| + "amadan.net/oficina/estilo.git/menu" |
| + "amadan.net/oficina/estilo.git/theme" |
| + "github.com/carlosframework/rastrillo/ui" |
| +) |
| + |
| +// The page: the stacked bar as an app draws it, with the suite's |
| +// stylesheets in their fixed order and chrome.js. ?title= is the title. |
| +const titlePage = `<!doctype html> |
| +<html lang="en"> |
| +<head> |
| +<meta charset="utf-8"> |
| +<meta name="viewport" content="width=device-width, initial-scale=1"> |
| +<link rel="stylesheet" href="/tokens.css"> |
| +<link rel="stylesheet" href="/theme.css"> |
| +<link rel="stylesheet" href="/base.css"> |
| +<link rel="stylesheet" href="/menu.css"> |
| +<link rel="stylesheet" href="/chrome.css"> |
| +<script defer src="/chrome.js"></script> |
| +</head> |
| +<body> |
| +<div estilo-shell> |
| +%s |
| +<main id="main"></main> |
| +</div> |
| +</body> |
| +</html> |
| +` |
| + |
| +type titleFit struct { |
| + Engine string `json:"engine"` |
| + Version string `json:"version"` |
| + Error string `json:"error"` |
| + Fields []struct { |
| + Title string `json:"title"` |
| + Viewport int `json:"viewport"` |
| + Inline string `json:"inline"` // style.inlineSize, as chrome.js set it |
| + Width float64 `json:"width"` // the field's border box |
| + Content float64 `json:"content"` // its content box: the room the text has |
| + Text float64 `json:"text"` // the title in the field's font, as a span draws it |
| + Scroll int `json:"scroll"` // scrollWidth |
| + Client int `json:"client"` // clientWidth |
| + Capped bool `json:"capped"` // the bar's room, not the title, set the width |
| + Narrowed bool `json:"narrowed"` // the control: the same field 12.8px (both paddings) narrower |
| + Zero struct { |
| + Scroll, Client, Offset int |
| + } `json:"zero"` // what chrome.js reads, at zero width |
| + } `json:"fields"` |
| +} |
| + |
| +func TestStackedTitleFitsItsTitle(t *testing.T) { |
| + if _, err := exec.LookPath("node"); err != nil { |
| + t.Fatal("node is required (Node 22+)") |
| + } |
| + view := parse(t) |
| + mux := http.NewServeMux() |
| + mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) { |
| + b := stacked() |
| + b.ContextEdit.Value = r.URL.Query().Get("title") |
| + var bar bytes.Buffer |
| + if err := view.ExecuteTemplate(&bar, "estilo-bar", b); err != nil { |
| + t.Error(err) |
| + } |
| + w.Header().Set("Content-Type", "text/html; charset=utf-8") |
| + w.Header().Set("Content-Security-Policy", "default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:") |
| + fmt.Fprintf(w, titlePage, bar.String()) |
| + }) |
| + assets := map[string][]byte{"/tokens.css": ui.TokensCSS(), "/theme.css": theme.CSS(), "/base.css": base.CSS(), "/menu.css": menu.CSS(), "/chrome.css": CSS(), "/chrome.js": JS()} |
| + for path, body := range assets { |
| + mux.HandleFunc("GET "+path, func(w http.ResponseWriter, r *http.Request) { |
| + ct := "text/css; charset=utf-8" |
| + if strings.HasSuffix(path, ".js") { |
| + ct = "text/javascript; charset=utf-8" |
| + } |
| + w.Header().Set("Content-Type", ct) |
| + _, _ = w.Write(body) |
| + }) |
| + } |
| + srv := httptest.NewServer(mux) |
| + t.Cleanup(srv.Close) |
| + |
| + engines := strings.Split(os.Getenv("ESTILO_BROWSERS"), ",") |
| + if engines[0] == "" { |
| + engines = []string{"chromium", "webkit"} |
| + } |
| + job, _ := json.Marshal(map[string]any{ |
| + "origin": srv.URL, |
| + "engines": engines, |
| + "viewports": []int{1440, 390}, |
| + // Short, the two titles the bug was found on, a sentence, wide |
| + // and narrow Latin, CJK, and Latin with accents and a dash. |
| + "titles": []string{"Q3", "Onboarding", "Brightwater Labs", "Untitled document", "WWWWWWWWWW", "illiterate fill", "A considerably longer document title for the quarter", "四半期の計画書", "Résumé — draft"}, |
| + }) |
| + cmd := exec.Command("node", "titlefit.browser.mjs", string(job)) |
| + cmd.Stderr = os.Stderr |
| + raw, err := cmd.Output() |
| + if err != nil { |
| + t.Fatalf("node titlefit.browser.mjs: %v", err) |
| + } |
| + var results []titleFit |
| + if err := json.Unmarshal(raw, &results); err != nil { |
| + t.Fatalf("driver output: %v\n%s", err, raw) |
| + } |
| + if len(results) != len(engines) { |
| + t.Fatalf("%d engines asked for, %d reported", len(engines), len(results)) |
| + } |
| + for _, r := range results { |
| + if r.Error != "" { |
| + t.Errorf("%s did not launch: %s", r.Engine, r.Error) |
| + continue |
| + } |
| + fitted := 0 |
| + for _, f := range r.Fields { |
| + where := fmt.Sprintf("%s %s, %dpx, %q", r.Engine, r.Version, f.Viewport, f.Title) |
| + t.Logf("%s: %s; content %.2f for text %.2f; scroll %d, client %d; at zero width scroll %d, client %d, offset %d; capped %v", where, f.Inline, f.Content, f.Text, f.Scroll, f.Client, f.Zero.Scroll, f.Zero.Client, f.Zero.Offset, f.Capped) |
| + if f.Inline == "" { |
| + t.Errorf("%s: chrome.js did not fit the field", where) |
| + continue |
| + } |
| + // The detector must see a field that is short by exactly what |
| + // the bug cost, or a pass means nothing. |
| + if !f.Narrowed { |
| + t.Errorf("%s: the same field 12.8px narrower was not seen as cut off; the check is blind", where) |
| + } |
| + if f.Capped { |
| + continue // a title longer than the room scrolls inside the field, by design |
| + } |
| + fitted++ |
| + // The engine's own verdict: nothing to scroll to, so nothing cut off. |
| + if f.Scroll > f.Client { |
| + t.Errorf("%s: the title overflows its field (scroll width %d, client width %d): its end is cut off", where, f.Scroll, f.Client) |
| + } |
| + // And the text's own measure fits the room the field gives it. |
| + if f.Content+0.01 < f.Text { |
| + t.Errorf("%s: the field's content box is %.2fpx for a title %.2fpx wide: its end is cut off", where, f.Content, f.Text) |
| + } |
| + // And as wide as its title, not the bar's room: a caret and |
| + // the rounding over the text, never a field's worth. |
| + if f.Content > f.Text+24 { |
| + t.Errorf("%s: the field's content box is %.2fpx for a title %.2fpx wide: not fitted to it", where, f.Content, f.Text) |
| + } |
| + } |
| + if fitted < len(r.Fields)/2 { |
| + t.Errorf("%s: only %d of %d fields were fitted to their title rather than capped", r.Engine, fitted, len(r.Fields)) |
| + } |
| + } |
| +} |
diff --git a/chrome/titlefit.browser.mjs b/chrome/titlefit.browser.mjs| new file mode 100644 |
| index 0000000..3021cf1 |
| --- /dev/null |
| +++ b/chrome/titlefit.browser.mjs |
| @@ -0,0 +1,79 @@ |
| +// titlefit.browser.mjs: open the stacked bar with each title, in each |
| +// engine and viewport, and measure the title field chrome.js fitted. |
| +// Driven by title_browser_test.go (go test -tags browser ./chrome), |
| +// which serves the page and makes every assertion; this file only drives |
| +// the browsers and reports what it measured. |
| +// |
| +// ESTILO_PLAYWRIGHT=<path to the playwright package> \ |
| +// node titlefit.browser.mjs <job JSON> |
| +// |
| +// Job: {origin, engines, viewports, titles}. Output: one entry per |
| +// engine, {engine, version, error, fields: [...]}, as the test reads it. |
| +import { createRequire } from 'node:module' |
| + |
| +const require = createRequire(import.meta.url) |
| +const pw = require(process.env.ESTILO_PLAYWRIGHT || 'playwright') |
| +const job = JSON.parse(process.argv[2]) |
| + |
| +// measure runs in the page, once chrome.js has fitted the field and the |
| +// fonts have settled. |
| +function measure() { |
| + const f = document.querySelector('[estilo-bar-title-input][size]') |
| + const cs = getComputedStyle(f) |
| + const px = (v) => parseFloat(v) || 0 |
| + const frame = px(cs.paddingInlineStart) + px(cs.paddingInlineEnd) + px(cs.borderInlineStartWidth) + px(cs.borderInlineEndWidth) |
| + // The title as a span in the field's font draws it. (In WebKit a |
| + // field draws its text a little wider than this; never narrower.) |
| + const span = document.createElement('span') |
| + for (const p of ['font', 'letterSpacing', 'wordSpacing', 'fontKerning', 'fontFeatureSettings', 'fontVariationSettings', 'textTransform']) span.style[p] = cs[p] |
| + span.style.whiteSpace = 'pre' |
| + span.style.position = 'absolute' |
| + span.textContent = f.value |
| + document.body.append(span) |
| + const text = span.getBoundingClientRect().width |
| + span.remove() |
| + const width = f.getBoundingClientRect().width |
| + const inline = f.style.inlineSize |
| + const cut = () => f.scrollWidth > f.clientWidth || f.getBoundingClientRect().width - frame + 0.01 < text |
| + const out = { |
| + inline, width, content: width - frame, text, |
| + scroll: f.scrollWidth, client: f.clientWidth, |
| + // The bar's room set the width: the field is narrower than chrome.js asked. |
| + capped: width + 0.5 < px(inline), |
| + } |
| + // What chrome.js reads, at zero width. |
| + f.style.inlineSize = '0px' |
| + out.zero = { scroll: f.scrollWidth, client: f.clientWidth, offset: f.offsetWidth } |
| + // The control: the field as the bug had it, both paddings short. |
| + f.style.inlineSize = px(inline) - px(cs.paddingInlineStart) - px(cs.paddingInlineEnd) + 'px' |
| + out.narrowed = cut() |
| + f.style.inlineSize = inline |
| + return out |
| +} |
| + |
| +const results = [] |
| +for (const engine of job.engines) { |
| + const result = { engine, version: '', error: '', fields: [] } |
| + results.push(result) |
| + let browser |
| + try { |
| + browser = await pw[engine].launch() |
| + result.version = browser.version() |
| + for (const vw of job.viewports) { |
| + const page = await browser.newPage({ viewport: { width: vw, height: 400 } }) |
| + for (const title of job.titles) { |
| + await page.goto(job.origin + '/?title=' + encodeURIComponent(title), { waitUntil: 'load' }) |
| + await page.evaluate(() => document.fonts.ready) |
| + // chrome.js fits again once fonts settle; let that land. |
| + await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)))) |
| + result.fields.push({ title, viewport: vw, ...(await page.evaluate(measure)) }) |
| + } |
| + await page.close() |
| + } |
| + } catch (e) { |
| + result.error = String(e && e.message || e) |
| + } finally { |
| + if (browser) await browser.close() |
| + } |
| +} |
| +process.stdout.write(JSON.stringify(results)) |